summary refs log tree commit diff
path: root/crypto/src/pqc/asn1/CmcePublicKey.cs
diff options
context:
space:
mode:
authorroyb <roy.basmacier@primekey.com>2022-02-03 12:51:52 -0500
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-06-23 21:58:04 +0700
commit004de388d03ebfc6734d4a613f5114ceb8f7a570 (patch)
treec796413a7589c47548c15f35ec4b27f4b17fe6a8 /crypto/src/pqc/asn1/CmcePublicKey.cs
parentNew build organization (diff)
downloadBouncyCastle.NET-ed25519-004de388d03ebfc6734d4a613f5114ceb8f7a570.tar.xz
Initial merge of PQC port
Diffstat (limited to 'crypto/src/pqc/asn1/CmcePublicKey.cs')
-rw-r--r--crypto/src/pqc/asn1/CmcePublicKey.cs78
1 files changed, 78 insertions, 0 deletions
diff --git a/crypto/src/pqc/asn1/CmcePublicKey.cs b/crypto/src/pqc/asn1/CmcePublicKey.cs
new file mode 100644
index 000000000..1e417c5df
--- /dev/null
+++ b/crypto/src/pqc/asn1/CmcePublicKey.cs
@@ -0,0 +1,78 @@
+using System;
+using Org.BouncyCastle.Asn1;
+using Org.BouncyCastle.Utilities;
+
+namespace Org.BouncyCastle.Pqc.Asn1
+{
+    public class CmcePublicKey
+        : Asn1Object
+    {
+        private byte[] t;
+
+        public CmcePublicKey(byte[] t)
+        {
+            this.t = t;
+        }
+
+        public CmcePublicKey(Asn1Sequence seq)
+        {
+            t = Arrays.Clone(Asn1OctetString.GetInstance(seq[0]).GetOctets());
+        }
+
+        public byte[] T => Arrays.Clone(t);
+
+        public Asn1Object ToAsn1Primitive()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector();
+            v.Add(new DerOctetString(t));
+            return new DerSequence(v);
+        }
+
+        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);
+        }
+
+        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());
+        }
+
+        protected override int Asn1GetHashCode()
+        {
+            return ToAsn1Primitive().GetHashCode();
+        }
+    }
+}
\ No newline at end of file