summary refs log tree commit diff
path: root/crypto/src/asn1
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2020-04-05 21:16:59 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2020-04-05 21:16:59 +0700
commit184077ebeabe315ec4dc13e2670868422f7b9594 (patch)
tree2178074db98529109b9d91e5e42e8c555bd904e8 /crypto/src/asn1
parentAdd OIW dsaWithSHA1 OID to 'noParams' (diff)
downloadBouncyCastle.NET-ed25519-184077ebeabe315ec4dc13e2670868422f7b9594.tar.xz
Add OtherName support and refactoring
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r--crypto/src/asn1/x509/OtherName.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/crypto/src/asn1/x509/OtherName.cs b/crypto/src/asn1/x509/OtherName.cs
new file mode 100644
index 000000000..3e6a61499
--- /dev/null
+++ b/crypto/src/asn1/x509/OtherName.cs
@@ -0,0 +1,71 @@
+using System;
+
+namespace Org.BouncyCastle.Asn1.X509
+{
+    /**
+     * The OtherName object.
+     * <pre>
+     * OtherName ::= SEQUENCE {
+     *      type-id    OBJECT IDENTIFIER,
+     *      value      [0] EXPLICIT ANY DEFINED BY type-id }
+     * </pre>
+     */
+    public class OtherName
+        : Asn1Encodable
+    {
+        private readonly DerObjectIdentifier typeID;
+        private readonly Asn1Encodable value;
+
+        /**
+         * OtherName factory method.
+         * @param obj the object used to construct an instance of <code>
+         * OtherName</code>. It must be an instance of <code>OtherName
+         * </code> or <code>ASN1Sequence</code>.
+         * @return the instance of <code>OtherName</code> built from the
+         * supplied object.
+         * @throws java.lang.IllegalArgumentException if the object passed
+         * to the factory is not an instance of <code>OtherName</code> or something that
+         * can be converted into an appropriate <code>ASN1Sequence</code>.
+         */
+        public static OtherName GetInstance(object obj)
+        {
+            if (obj is OtherName)
+                return (OtherName)obj;
+            if (obj == null)
+                return null;
+            return new OtherName(Asn1Sequence.GetInstance(obj));
+        }
+
+        /**
+         * Base constructor.
+         * @param typeID the type of the other name.
+         * @param value the ANY object that represents the value.
+         */
+        public OtherName(DerObjectIdentifier typeID, Asn1Encodable value)
+        {
+            this.typeID = typeID;
+            this.value  = value;
+        }
+
+        private OtherName(Asn1Sequence seq)
+        {
+            this.typeID = DerObjectIdentifier.GetInstance(seq[0]);
+            this.value = DerTaggedObject.GetInstance(seq[1]).GetObject(); // explicitly tagged
+        }
+
+        public virtual DerObjectIdentifier TypeID
+        {
+            get { return typeID; }
+        }
+
+        public Asn1Encodable Value
+        {
+            get { return value; }
+        }
+
+        public override Asn1Object ToAsn1Object()
+        {
+            return new DerSequence(typeID, new DerTaggedObject(true, 0, value));
+        }
+    }
+}