1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.internal.asymmetric; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
|
24 |
|
import org.bouncycastle.asn1.ASN1Integer; |
25 |
|
import org.bouncycastle.asn1.DERNull; |
26 |
|
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; |
27 |
|
import org.bouncycastle.asn1.pkcs.RSAPublicKey; |
28 |
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier; |
29 |
|
import org.bouncycastle.asn1.x509.DSAParameter; |
30 |
|
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; |
31 |
|
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers; |
32 |
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter; |
33 |
|
import org.bouncycastle.crypto.params.DSAParameters; |
34 |
|
import org.bouncycastle.crypto.params.DSAPublicKeyParameters; |
35 |
|
import org.bouncycastle.crypto.params.RSAKeyParameters; |
36 |
|
import org.bouncycastle.crypto.util.SubjectPublicKeyInfoFactory; |
37 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 78.6% |
Uncovered Elements: 6 (28) |
Complexity: 8 |
Complexity Density: 0.47 |
|
45 |
|
public class BcPublicKeyParameters extends AbstractBcAsymmetricKeyParameters implements PublicKeyParameters |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@param |
51 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
52 |
63 |
public BcPublicKeyParameters(AsymmetricKeyParameter parameters)... |
53 |
|
{ |
54 |
63 |
super(parameters); |
55 |
63 |
if (isPrivate()) { |
56 |
0 |
throw new IllegalArgumentException("Private key assigned to a public key: " |
57 |
|
+ parameters.getClass().getName()); |
58 |
|
} |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
@return |
63 |
|
@throws |
64 |
|
|
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
65 |
23 |
public SubjectPublicKeyInfo getSubjectPublicKeyInfo() throws IOException... |
66 |
|
{ |
67 |
23 |
if (this.parameters instanceof RSAKeyParameters) { |
68 |
14 |
RSAKeyParameters params = (RSAKeyParameters) this.parameters; |
69 |
|
|
70 |
14 |
return new SubjectPublicKeyInfo( |
71 |
|
new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), |
72 |
|
new RSAPublicKey(params.getModulus(), params.getExponent())); |
73 |
9 |
} else if (this.parameters instanceof DSAPublicKeyParameters) { |
74 |
9 |
DSAPublicKeyParameters params = (DSAPublicKeyParameters) this.parameters; |
75 |
9 |
DSAParameters dsaParams = params.getParameters(); |
76 |
9 |
DSAParameter algParams = null; |
77 |
|
|
78 |
9 |
if (dsaParams != null) { |
79 |
9 |
algParams = new DSAParameter(dsaParams.getP(), dsaParams.getQ(), dsaParams.getG()); |
80 |
|
} |
81 |
|
|
82 |
9 |
return new SubjectPublicKeyInfo( |
83 |
|
new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa, algParams), |
84 |
|
new ASN1Integer(params.getY())); |
85 |
|
} else { |
86 |
|
|
87 |
0 |
return SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(this.parameters); |
88 |
|
} |
89 |
|
} |
90 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
91 |
2 |
@Override... |
92 |
|
public byte[] getEncoded() |
93 |
|
{ |
94 |
2 |
try { |
95 |
2 |
return getSubjectPublicKeyInfo().getEncoded(); |
96 |
|
} catch (IOException e) { |
97 |
0 |
return null; |
98 |
|
} |
99 |
|
} |
100 |
|
} |