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.params.x509certificate.extension; |
21 |
|
|
22 |
|
import java.net.InetAddress; |
23 |
|
import java.net.UnknownHostException; |
24 |
|
import java.util.Arrays; |
25 |
|
|
26 |
|
import org.bouncycastle.asn1.DEROctetString; |
27 |
|
import org.bouncycastle.asn1.x509.GeneralName; |
28 |
|
import org.xwiki.crypto.pkix.internal.extension.BcGeneralName; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 85.1% |
Uncovered Elements: 7 (47) |
Complexity: 17 |
Complexity Density: 0.59 |
|
36 |
|
public class X509IpAddress implements X509StringGeneralName, BcGeneralName |
37 |
|
{ |
38 |
|
private final byte[] ipAddress; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@param |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
45 |
5 |
public X509IpAddress(String ipAddress)... |
46 |
|
{ |
47 |
5 |
GeneralName name = new GeneralName(GeneralName.iPAddress, ipAddress); |
48 |
5 |
this.ipAddress = DEROctetString.getInstance(name.getName()).getOctets(); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
2 |
public X509IpAddress(InetAddress ipAddress)... |
57 |
|
{ |
58 |
2 |
this.ipAddress = ipAddress.getAddress(); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
@param |
66 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
67 |
2 |
public X509IpAddress(InetAddress ipAddress, InetAddress ipMask)... |
68 |
|
{ |
69 |
2 |
byte[] ip = ipAddress.getAddress(); |
70 |
2 |
byte[] mask = ipMask.getAddress(); |
71 |
|
|
72 |
2 |
if (ip.length != mask.length) { |
73 |
0 |
throw new IllegalArgumentException("Incompatible ip address (" + ip.length |
74 |
|
+ ") and ip mask (" + mask.length + ")"); |
75 |
|
} |
76 |
2 |
this.ipAddress = new byte[ip.length + mask.length]; |
77 |
2 |
System.arraycopy(ip, 0, this.ipAddress, 0, ip.length); |
78 |
2 |
System.arraycopy(mask, 0, this.ipAddress, ip.length, mask.length); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
86 |
9 |
public X509IpAddress(GeneralName name)... |
87 |
|
{ |
88 |
9 |
if (name.getTagNo() != GeneralName.iPAddress) { |
89 |
0 |
throw new IllegalArgumentException("Incompatible general name: " + name.getTagNo()); |
90 |
|
} |
91 |
9 |
this.ipAddress = DEROctetString.getInstance(name.getName()).getOctets(); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
@return |
96 |
|
@throws |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
98 |
23 |
public InetAddress getIpAddress() throws UnknownHostException... |
99 |
|
{ |
100 |
23 |
byte[] ip = this.ipAddress; |
101 |
|
|
102 |
23 |
if (ip.length == 8 || ip.length == 32) { |
103 |
15 |
ip = new byte[ip.length / 2]; |
104 |
15 |
System.arraycopy(this.ipAddress, 0, ip, 0, ip.length); |
105 |
|
} |
106 |
|
|
107 |
23 |
return InetAddress.getByAddress(ip); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
@return |
112 |
|
@throws |
113 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
114 |
15 |
public InetAddress getIpMask() throws UnknownHostException... |
115 |
|
{ |
116 |
15 |
if (this.ipAddress.length != 8 && this.ipAddress.length != 32) { |
117 |
0 |
return null; |
118 |
|
} |
119 |
|
|
120 |
15 |
byte[] mask = new byte[this.ipAddress.length / 2]; |
121 |
15 |
System.arraycopy(this.ipAddress, mask.length, mask, 0, mask.length); |
122 |
|
|
123 |
15 |
return InetAddress.getByAddress(mask); |
124 |
|
} |
125 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
126 |
23 |
@Override... |
127 |
|
public String getName() |
128 |
|
{ |
129 |
23 |
try { |
130 |
23 |
if (this.ipAddress.length != 8 && this.ipAddress.length != 32) { |
131 |
8 |
return getIpAddress().getHostAddress(); |
132 |
|
} |
133 |
15 |
return getIpAddress().getHostAddress() + "/" + getIpMask().getHostAddress(); |
134 |
|
} catch (UnknownHostException e) { |
135 |
0 |
return Arrays.toString(this.ipAddress); |
136 |
|
} |
137 |
|
} |
138 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
9 |
@Override... |
140 |
|
public GeneralName getGeneralName() |
141 |
|
{ |
142 |
9 |
return new GeneralName(GeneralName.iPAddress, new DEROctetString(this.ipAddress)); |
143 |
|
} |
144 |
|
} |