diff options
Diffstat (limited to 'crypto/src/cms/RecipientId.cs')
-rw-r--r-- | crypto/src/cms/RecipientId.cs | 56 |
1 files changed, 19 insertions, 37 deletions
diff --git a/crypto/src/cms/RecipientId.cs b/crypto/src/cms/RecipientId.cs index 815f3ff90..c4107b14e 100644 --- a/crypto/src/cms/RecipientId.cs +++ b/crypto/src/cms/RecipientId.cs @@ -1,58 +1,40 @@ using System; -using Org.BouncyCastle.Asn1.X509; -using Org.BouncyCastle.Math; using Org.BouncyCastle.Utilities; using Org.BouncyCastle.X509.Store; namespace Org.BouncyCastle.Cms { + // TODO[api] sealed public class RecipientID - : X509CertStoreSelector + : X509CertStoreSelector, IEquatable<RecipientID> { - private byte[] keyIdentifier; + private byte[] m_keyIdentifier; public byte[] KeyIdentifier { - get { return Arrays.Clone(keyIdentifier); } - set { keyIdentifier = Arrays.Clone(value); } + get { return Arrays.Clone(m_keyIdentifier); } + set { m_keyIdentifier = Arrays.Clone(value); } } - public override int GetHashCode() + public virtual bool Equals(RecipientID other) { - int code = Arrays.GetHashCode(keyIdentifier) - ^ Arrays.GetHashCode(this.SubjectKeyIdentifier); - - BigInteger serialNumber = this.SerialNumber; - if (serialNumber != null) - { - code ^= serialNumber.GetHashCode(); - } - - X509Name issuer = this.Issuer; - if (issuer != null) - { - code ^= issuer.GetHashCode(); - } - - return code; + return other == null ? false + : other == this ? true + : Arrays.AreEqual(m_keyIdentifier, other.m_keyIdentifier) + && MatchesSubjectKeyIdentifier(other) + && MatchesSerialNumber(other) + && MatchesIssuer(other); } - public override bool Equals( - object obj) - { - if (obj == this) - return true; + public override bool Equals(object obj) => Equals(obj as RecipientID); - RecipientID id = obj as RecipientID; - - if (id == null) - return false; - - return Arrays.AreEqual(keyIdentifier, id.keyIdentifier) - && Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier) - && Objects.Equals(SerialNumber, id.SerialNumber) - && IssuersMatch(Issuer, id.Issuer); + public override int GetHashCode() + { + return Arrays.GetHashCode(m_keyIdentifier) + ^ GetHashCodeOfSubjectKeyIdentifier() + ^ Objects.GetHashCode(SerialNumber) + ^ Objects.GetHashCode(Issuer); } } } |