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.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.EnumSet; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Set; |
27 |
|
|
28 |
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
29 |
|
import org.bouncycastle.asn1.DERBitString; |
30 |
|
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; |
31 |
|
import org.bouncycastle.asn1.x509.GeneralName; |
32 |
|
import org.bouncycastle.asn1.x509.GeneralNames; |
33 |
|
import org.bouncycastle.asn1.x509.KeyPurposeId; |
34 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.ExtendedKeyUsages; |
35 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.KeyUsage; |
36 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509DirectoryName; |
37 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509DnsName; |
38 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GeneralName; |
39 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GenericName; |
40 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509IpAddress; |
41 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509Rfc822Name; |
42 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509URI; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
|
|
| 83.1% |
Uncovered Elements: 12 (71) |
Complexity: 17 |
Complexity Density: 0.31 |
|
50 |
|
public final class BcExtensionUtils |
51 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
52 |
0 |
private BcExtensionUtils()... |
53 |
|
{ |
54 |
|
|
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
@return |
62 |
|
|
|
|
| 81.5% |
Uncovered Elements: 5 (27) |
Complexity: 7 |
Complexity Density: 0.28 |
|
63 |
1 |
public static List<X509GeneralName> getX509GeneralNames(GeneralNames genNames)... |
64 |
|
{ |
65 |
1 |
if (genNames == null) { |
66 |
0 |
return null; |
67 |
|
} |
68 |
|
|
69 |
1 |
GeneralName[] names = genNames.getNames(); |
70 |
1 |
List<X509GeneralName> x509names = new ArrayList<X509GeneralName>(names.length); |
71 |
|
|
72 |
1 |
for (GeneralName name : names) { |
73 |
15 |
switch (name.getTagNo()) { |
74 |
2 |
case GeneralName.rfc822Name: |
75 |
2 |
x509names.add(new X509Rfc822Name(name)); |
76 |
2 |
break; |
77 |
1 |
case GeneralName.dNSName: |
78 |
1 |
x509names.add(new X509DnsName(name)); |
79 |
1 |
break; |
80 |
1 |
case GeneralName.directoryName: |
81 |
1 |
x509names.add(new X509DirectoryName(name)); |
82 |
1 |
break; |
83 |
2 |
case GeneralName.uniformResourceIdentifier: |
84 |
2 |
x509names.add(new X509URI(name)); |
85 |
2 |
break; |
86 |
9 |
case GeneralName.iPAddress: |
87 |
9 |
x509names.add(new X509IpAddress(name)); |
88 |
9 |
break; |
89 |
0 |
default: |
90 |
0 |
x509names.add(new X509GenericName(name)); |
91 |
0 |
break; |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
1 |
return x509names; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@return |
103 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
104 |
27 |
public static EnumSet<KeyUsage> getSetOfKeyUsage(org.bouncycastle.asn1.x509.KeyUsage keyUsage)... |
105 |
|
{ |
106 |
27 |
if (keyUsage == null) { |
107 |
0 |
return null; |
108 |
|
} |
109 |
|
|
110 |
27 |
Collection<KeyUsage> usages = new ArrayList<KeyUsage>(); |
111 |
|
|
112 |
27 |
for (KeyUsage usage : KeyUsage.values()) { |
113 |
243 |
if ((((DERBitString) keyUsage.toASN1Primitive()).intValue() & usage.value()) > 0) { |
114 |
54 |
usages.add(usage); |
115 |
|
} |
116 |
|
} |
117 |
27 |
return EnumSet.copyOf(usages); |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@param |
124 |
|
@return |
125 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
126 |
4 |
public static ExtendedKeyUsages getExtendedKeyUsages(ExtendedKeyUsage usages)... |
127 |
|
{ |
128 |
4 |
if (usages == null) { |
129 |
0 |
return null; |
130 |
|
} |
131 |
|
|
132 |
4 |
List<String> usageStr = new ArrayList<String>(); |
133 |
|
|
134 |
4 |
for (KeyPurposeId keyPurposeId : usages.getUsages()) { |
135 |
4 |
usageStr.add(keyPurposeId.getId()); |
136 |
|
} |
137 |
|
|
138 |
4 |
return new ExtendedKeyUsages(usageStr); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
@return |
146 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
147 |
2 |
public static GeneralNames getGeneralNames(X509GeneralName[] genNames)... |
148 |
|
{ |
149 |
2 |
GeneralName[] names = new GeneralName[genNames.length]; |
150 |
|
|
151 |
2 |
int i = 0; |
152 |
2 |
for (X509GeneralName name : genNames) { |
153 |
16 |
if (name instanceof BcGeneralName) { |
154 |
16 |
names[i++] = ((BcGeneralName) name).getGeneralName(); |
155 |
|
} else { |
156 |
0 |
throw new IllegalArgumentException("Unexpected general name: " + name.getClass().toString()); |
157 |
|
} |
158 |
|
} |
159 |
|
|
160 |
2 |
return new GeneralNames(names); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
@param |
167 |
|
@return |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
169 |
6 |
public static org.bouncycastle.asn1.x509.KeyUsage getKeyUsage(EnumSet<KeyUsage> usages)... |
170 |
|
{ |
171 |
6 |
int bitmask = 0; |
172 |
6 |
for (KeyUsage usage : usages) { |
173 |
12 |
bitmask |= usage.value(); |
174 |
|
} |
175 |
6 |
return new org.bouncycastle.asn1.x509.KeyUsage(bitmask); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
@return |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
184 |
2 |
public static ExtendedKeyUsage getExtendedKeyUsage(Set<String> usages)... |
185 |
|
{ |
186 |
2 |
KeyPurposeId[] keyUsages = new KeyPurposeId[usages.size()]; |
187 |
2 |
int i = 0; |
188 |
|
|
189 |
2 |
for (String usage : usages) { |
190 |
2 |
keyUsages[i++] = KeyPurposeId.getInstance(new ASN1ObjectIdentifier(usage)); |
191 |
|
} |
192 |
|
|
193 |
2 |
return new ExtendedKeyUsage(keyUsages); |
194 |
|
} |
195 |
|
} |