01: package org.bouncycastle.cms;
02:
03: import org.bouncycastle.util.Arrays;
04:
05: import java.math.BigInteger;
06: import java.security.cert.X509CertSelector;
07:
08: public class RecipientId extends X509CertSelector {
09: byte[] keyIdentifier = null;
10:
11: /**
12: * set a secret key identifier (for use with KEKRecipientInfo)
13: */
14: public void setKeyIdentifier(byte[] keyIdentifier) {
15: this .keyIdentifier = keyIdentifier;
16: }
17:
18: /**
19: * return the secret key identifier
20: */
21: public byte[] getKeyIdentifier() {
22: return keyIdentifier;
23: }
24:
25: public int hashCode() {
26: int code = Arrays.hashCode(keyIdentifier)
27: ^ Arrays.hashCode(this .getSubjectKeyIdentifier());
28:
29: BigInteger serialNumber = this .getSerialNumber();
30: if (serialNumber != null) {
31: code ^= serialNumber.hashCode();
32: }
33:
34: String issuer = this .getIssuerAsString();
35: if (issuer != null) {
36: code ^= issuer.hashCode();
37: }
38:
39: return code;
40: }
41:
42: public boolean equals(Object o) {
43: if (!(o instanceof RecipientId)) {
44: return false;
45: }
46:
47: RecipientId id = (RecipientId) o;
48:
49: return Arrays.areEqual(keyIdentifier, id.keyIdentifier)
50: && Arrays.areEqual(this .getSubjectKeyIdentifier(), id
51: .getSubjectKeyIdentifier())
52: && equalsObj(this .getSerialNumber(), id
53: .getSerialNumber())
54: && equalsObj(this .getIssuerAsString(), id
55: .getIssuerAsString());
56: }
57:
58: private boolean equalsObj(Object a, Object b) {
59: return (a != null) ? a.equals(b) : b == null;
60: }
61: }
|