summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/pqc/asn1/CmcePrivateKey.cs34
-rw-r--r--crypto/src/pqc/asn1/CmcePublicKey.cs43
2 files changed, 26 insertions, 51 deletions
diff --git a/crypto/src/pqc/asn1/CmcePrivateKey.cs b/crypto/src/pqc/asn1/CmcePrivateKey.cs
index 743b801f5..dba42f6c1 100644
--- a/crypto/src/pqc/asn1/CmcePrivateKey.cs
+++ b/crypto/src/pqc/asn1/CmcePrivateKey.cs
@@ -1,4 +1,5 @@
 using System;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Utilities;
 
@@ -22,6 +23,15 @@ namespace Org.BouncyCastle.Pqc.Asn1
     public class CmcePrivateKey
         : Asn1Object
     {
+        public static CmcePrivateKey GetInstance(Object o)
+        {
+            if (o == null)
+                return null;
+            if (o is CmcePrivateKey cmcePrivateKey)
+                return cmcePrivateKey;
+            return new CmcePrivateKey(Asn1Sequence.GetInstance(o));
+        }
+
         private int version;
         private byte[] delta;
         private byte[] c;
@@ -103,20 +113,6 @@ namespace Org.BouncyCastle.Pqc.Asn1
             return new DerSequence(v);
         }
 
-        public static  CmcePrivateKey GetInstance(Object o)
-        {
-            if (o is CmcePrivateKey)
-            {
-                return (CmcePrivateKey)o;
-            }
-            else if (o != null)
-            {
-                return new CmcePrivateKey(Asn1Sequence.GetInstance(o));
-            }
-
-            return null;
-        }
-        //TODO are these correct tags?
         internal override IAsn1Encoding GetEncoding(int encoding)
         {
             return ToAsn1Primitive().GetEncoding(encoding);
@@ -129,16 +125,12 @@ namespace Org.BouncyCastle.Pqc.Asn1
 
         protected override bool Asn1Equals(Asn1Object asn1Object)
         {
-            CmcePrivateKey other = asn1Object as CmcePrivateKey;
-            if (other == null)
-                return false;
-            
-            return Arrays.AreEqual(this.ToAsn1Primitive().GetEncoded(), other.ToAsn1Primitive().GetEncoded());
+            return ToAsn1Primitive().CallAsn1Equals(asn1Object);
         }
 
         protected override int Asn1GetHashCode()
         {
-            return ToAsn1Object().CallAsn1GetHashCode();
+            return ToAsn1Primitive().CallAsn1GetHashCode();
         }
     }
-}
\ No newline at end of file
+}
diff --git a/crypto/src/pqc/asn1/CmcePublicKey.cs b/crypto/src/pqc/asn1/CmcePublicKey.cs
index 00a2afe19..e811c0d97 100644
--- a/crypto/src/pqc/asn1/CmcePublicKey.cs
+++ b/crypto/src/pqc/asn1/CmcePublicKey.cs
@@ -1,4 +1,5 @@
 using System;
+
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Utilities;
 
@@ -8,6 +9,15 @@ namespace Org.BouncyCastle.Pqc.Asn1
     public class CmcePublicKey
         : Asn1Object
     {
+        public static CmcePublicKey GetInstance(Object o)
+        {
+            if (o == null)
+                return null;
+            if (o is CmcePublicKey cmcePublicKey)
+                return cmcePublicKey;
+            return new CmcePublicKey(Asn1Sequence.GetInstance(o));
+        }
+
         private byte[] t;
 
         public CmcePublicKey(byte[] t)
@@ -27,20 +37,6 @@ namespace Org.BouncyCastle.Pqc.Asn1
             return new DerSequence(new DerOctetString(t));
         }
 
-        public static CmcePublicKey GetInstance(Object o)
-        {
-            if (o is CmcePrivateKey)
-            {
-                return (CmcePublicKey) o;
-            }
-            else if (o != null)
-            {
-                return new CmcePublicKey(Asn1Sequence.GetInstance(o));
-            }
-
-            return null;
-        }
-
         internal override IAsn1Encoding GetEncoding(int encoding)
         {
             return ToAsn1Primitive().GetEncoding(encoding);
@@ -49,29 +45,16 @@ namespace Org.BouncyCastle.Pqc.Asn1
         internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo)
         {
             return ToAsn1Primitive().GetEncodingImplicit(encoding, tagClass, tagNo);
-
         }
 
         protected override bool Asn1Equals(Asn1Object asn1Object)
         {
-            if (this.Equals(asn1Object))
-            {
-                return true;
-            }
-
-            if (!(asn1Object is Asn1Encodable))
-            {
-                return false;
-            }
-
-            Asn1Encodable other = (Asn1Encodable) asn1Object;
-
-            return ToAsn1Primitive().Equals(other.ToAsn1Object());
+            return ToAsn1Primitive().CallAsn1Equals(asn1Object);
         }
 
         protected override int Asn1GetHashCode()
         {
-            return ToAsn1Primitive().GetHashCode();
+            return ToAsn1Primitive().CallAsn1GetHashCode();
         }
     }
-}
\ No newline at end of file
+}