1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.pkix.internal.extension; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.util.Enumeration; |
24 |
|
|
25 |
|
import org.bouncycastle.asn1.ASN1Encodable; |
26 |
|
import org.bouncycastle.asn1.ASN1Encoding; |
27 |
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
28 |
|
import org.bouncycastle.asn1.x509.Extension; |
29 |
|
import org.bouncycastle.asn1.x509.Extensions; |
30 |
|
import org.bouncycastle.asn1.x509.ExtensionsGenerator; |
31 |
|
import org.xwiki.crypto.pkix.X509ExtensionBuilder; |
32 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509Extensions; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 74.3% |
Uncovered Elements: 9 (35) |
Complexity: 10 |
Complexity Density: 0.45 |
|
40 |
|
public abstract class AbstractBcX509ExtensionBuilder implements X509ExtensionBuilder |
41 |
|
{ |
42 |
|
private final ExtensionsGenerator extensions = new ExtensionsGenerator(); |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
44 |
0 |
@Override... |
45 |
|
public X509ExtensionBuilder addExtension(String oid, boolean critical, byte[] value) throws IOException |
46 |
|
{ |
47 |
0 |
this.extensions.addExtension(new ASN1ObjectIdentifier(oid), critical, value); |
48 |
0 |
return this; |
49 |
|
} |
50 |
|
|
|
|
| 83.3% |
Uncovered Elements: 3 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
51 |
12 |
@Override... |
52 |
|
public X509ExtensionBuilder addExtensions(X509Extensions extensionSet) throws IOException |
53 |
|
{ |
54 |
12 |
if (extensionSet == null) { |
55 |
4 |
return this; |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
8 |
if (extensionSet instanceof BcX509Extensions) { |
60 |
8 |
Extensions exts = ((BcX509Extensions) extensionSet).getExtensions(); |
61 |
8 |
@SuppressWarnings("unchecked") |
62 |
|
Enumeration<ASN1ObjectIdentifier> oids = exts.oids(); |
63 |
22 |
while (oids.hasMoreElements()) { |
64 |
14 |
ASN1ObjectIdentifier oid = oids.nextElement(); |
65 |
14 |
Extension ext = exts.getExtension(oid); |
66 |
14 |
this.extensions.addExtension(ext.getExtnId(), ext.isCritical(), ext.getParsedValue()); |
67 |
|
} |
68 |
|
} else { |
69 |
|
|
70 |
0 |
for (String oid : extensionSet.getExtensionOID()) { |
71 |
0 |
this.extensions.addExtension(new ASN1ObjectIdentifier(oid), extensionSet.isCritical(oid), |
72 |
|
extensionSet.getExtensionValue(oid)); |
73 |
|
} |
74 |
|
} |
75 |
8 |
return this; |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
@param |
83 |
|
@param |
84 |
|
@return |
85 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
86 |
26 |
public X509ExtensionBuilder addExtension(ASN1ObjectIdentifier oid, boolean critical, ASN1Encodable value)... |
87 |
|
{ |
88 |
26 |
try { |
89 |
26 |
this.extensions.addExtension(oid, critical, value.toASN1Primitive().getEncoded(ASN1Encoding.DER)); |
90 |
|
} catch (IOException e) { |
91 |
|
|
92 |
0 |
throw new IllegalArgumentException("Invalid extension value, it could not be properly DER encoded."); |
93 |
|
} |
94 |
26 |
return this; |
95 |
|
} |
96 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
97 |
14 |
@Override... |
98 |
|
public X509Extensions build() |
99 |
|
{ |
100 |
14 |
if (this.extensions.isEmpty()) { |
101 |
0 |
return null; |
102 |
|
} |
103 |
14 |
return new BcX509Extensions(this.extensions.generate()); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
7 |
@Override... |
107 |
|
public boolean isEmpty() |
108 |
|
{ |
109 |
7 |
return this.extensions.isEmpty(); |
110 |
|
} |
111 |
|
} |