summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/KemCiphertextInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cmp/KemCiphertextInfo.cs')
-rw-r--r--crypto/src/asn1/cmp/KemCiphertextInfo.cs64
1 files changed, 64 insertions, 0 deletions
diff --git a/crypto/src/asn1/cmp/KemCiphertextInfo.cs b/crypto/src/asn1/cmp/KemCiphertextInfo.cs
new file mode 100644
index 000000000..7a6c3b25e
--- /dev/null
+++ b/crypto/src/asn1/cmp/KemCiphertextInfo.cs
@@ -0,0 +1,64 @@
+using System;
+
+using Org.BouncyCastle.Asn1.X509;
+
+namespace Org.BouncyCastle.Asn1.Cmp
+{
+    /**
+     * <pre>
+     *    KemCiphertextInfo ::= SEQUENCE {
+     *      kem              AlgorithmIdentifier{KEM-ALGORITHM, {...}},
+     *      ct               OCTET STRING
+     *    }
+     * </pre>
+     */
+    public class KemCiphertextInfo
+        : Asn1Encodable
+    {
+        public static KemCiphertextInfo GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is KemCiphertextInfo kemCiphertextInfo)
+                return kemCiphertextInfo;
+            return new KemCiphertextInfo(Asn1Sequence.GetInstance(obj));
+        }
+
+        public static KemCiphertextInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new KemCiphertextInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+
+        private readonly AlgorithmIdentifier m_kem;
+        private readonly Asn1OctetString m_ct;
+
+        private KemCiphertextInfo(Asn1Sequence seq)
+        {
+            if (seq.Count != 2)
+                throw new ArgumentException("sequence size should 2", nameof(seq));
+
+            m_kem = AlgorithmIdentifier.GetInstance(seq[0]);
+            m_ct = Asn1OctetString.GetInstance(seq[1]);
+        }
+
+        public KemCiphertextInfo(AlgorithmIdentifier kem, Asn1OctetString ct)
+        {
+            m_kem = kem;
+            m_ct = ct;
+        }
+
+        public virtual AlgorithmIdentifier Kem => m_kem;
+
+        public virtual Asn1OctetString Ct => m_ct;
+
+        /**
+         * <pre>
+         *    KemCiphertextInfo ::= SEQUENCE {
+         *      kem              AlgorithmIdentifier{KEM-ALGORITHM, {...}},
+         *      ct               OCTET STRING
+         *    }
+         * </pre>
+         *
+         * @return a basic ASN.1 object representation.
+         */
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_kem, m_ct);
+    }
+}