1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.spongycastle.cms;
import java.math.BigInteger;
import org.spongycastle.asn1.x500.X500Name;
import org.spongycastle.util.Arrays;
import org.spongycastle.util.Selector;
/**
* a basic index for an originator.
*/
class OriginatorId
implements Selector
{
private byte[] subjectKeyId;
private X500Name issuer;
private BigInteger serialNumber;
/**
* Construct a signer ID with the value of a public key's subjectKeyId.
*
* @param subjectKeyId a subjectKeyId
*/
public OriginatorId(byte[] subjectKeyId)
{
setSubjectKeyID(subjectKeyId);
}
private void setSubjectKeyID(byte[] subjectKeyId)
{
this.subjectKeyId = subjectKeyId;
}
/**
* Construct a signer ID based on the issuer and serial number of the signer's associated
* certificate.
*
* @param issuer the issuer of the signer's associated certificate.
* @param serialNumber the serial number of the signer's associated certificate.
*/
public OriginatorId(X500Name issuer, BigInteger serialNumber)
{
setIssuerAndSerial(issuer, serialNumber);
}
private void setIssuerAndSerial(X500Name issuer, BigInteger serialNumber)
{
this.issuer = issuer;
this.serialNumber = serialNumber;
}
/**
* Construct a signer ID based on the issuer and serial number of the signer's associated
* certificate.
*
* @param issuer the issuer of the signer's associated certificate.
* @param serialNumber the serial number of the signer's associated certificate.
* @param subjectKeyId the subject key identifier to use to match the signers associated certificate.
*/
public OriginatorId(X500Name issuer, BigInteger serialNumber, byte[] subjectKeyId)
{
setIssuerAndSerial(issuer, serialNumber);
setSubjectKeyID(subjectKeyId);
}
public X500Name getIssuer()
{
return issuer;
}
public Object clone()
{
return new OriginatorId(this.issuer, this.serialNumber, this.subjectKeyId);
}
public int hashCode()
{
int code = Arrays.hashCode(subjectKeyId);
if (this.serialNumber != null)
{
code ^= this.serialNumber.hashCode();
}
if (this.issuer != null)
{
code ^= this.issuer.hashCode();
}
return code;
}
public boolean equals(
Object o)
{
if (!(o instanceof OriginatorId))
{
return false;
}
OriginatorId id = (OriginatorId)o;
return Arrays.areEqual(subjectKeyId, id.subjectKeyId)
&& equalsObj(this.serialNumber, id.serialNumber)
&& equalsObj(this.issuer, id.issuer);
}
private boolean equalsObj(Object a, Object b)
{
return (a != null) ? a.equals(b) : b == null;
}
public boolean match(Object obj)
{
return false;
}
}
|