summary refs log tree commit diff
path: root/crypto/src/cms/OriginatorId.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-05-04 13:08:25 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-05-04 13:08:25 +0700
commit525dad93ce6d9444bab33f68fa5a43d8d9b9f94b (patch)
tree2cec4a9619a2f2edf88dc7b3536f106d96544ad7 /crypto/src/cms/OriginatorId.cs
parentWhen there is reference equality, Equals() should return true. (diff)
downloadBouncyCastle.NET-ed25519-525dad93ce6d9444bab33f68fa5a43d8d9b9f94b.tar.xz
Refactoring in CMS cert selectors
Diffstat (limited to 'crypto/src/cms/OriginatorId.cs')
-rw-r--r--crypto/src/cms/OriginatorId.cs51
1 files changed, 16 insertions, 35 deletions
diff --git a/crypto/src/cms/OriginatorId.cs b/crypto/src/cms/OriginatorId.cs
index 6ae64c503..440112736 100644
--- a/crypto/src/cms/OriginatorId.cs
+++ b/crypto/src/cms/OriginatorId.cs
@@ -1,49 +1,30 @@
-using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Math;
+using System;
+
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.X509.Store;
 
 namespace Org.BouncyCastle.Cms
 {
-    /**
-    * a basic index for an originator.
-    */
+    // TODO[api] sealed
     public class OriginatorID
-        : X509CertStoreSelector
+        : X509CertStoreSelector, IEquatable<OriginatorID>
     {
-        public override int GetHashCode()
+        public virtual bool Equals(OriginatorID other)
         {
-            int code = 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
+                :  MatchesSubjectKeyIdentifier(other)
+                && MatchesSerialNumber(other)
+                && MatchesIssuer(other);
         }
 
-        public override bool Equals(
-            object obj)
-        {
-			if (obj == this)
-				return false;
-
-			OriginatorID id = obj as OriginatorID;
-
-			if (id == null)
-				return false;
+        public override bool Equals(object obj) => Equals(obj as OriginatorID);
 
-			return Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier)
-				&& Objects.Equals(SerialNumber, id.SerialNumber)
-				&& IssuersMatch(Issuer, id.Issuer);
+        public override int GetHashCode()
+        {
+            return GetHashCodeOfSubjectKeyIdentifier()
+                ^  Objects.GetHashCode(SerialNumber)
+                ^  Objects.GetHashCode(Issuer);
         }
     }
 }