summary refs log tree commit diff
path: root/crypto/src/asn1/bc/LinkedCertificate.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 13:53:00 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 13:53:00 +0700
commit6c7a86e0b73074b2a42ea129acc831ace01d41a5 (patch)
treec0bb41783442ef197d0f10bcb56f6e015fc687ec /crypto/src/asn1/bc/LinkedCertificate.cs
parentName constraint validation updates from bc-java (diff)
downloadBouncyCastle.NET-ed25519-6c7a86e0b73074b2a42ea129acc831ace01d41a5.tar.xz
Port LinkedCertificate from bc-java
Diffstat (limited to 'crypto/src/asn1/bc/LinkedCertificate.cs')
-rw-r--r--crypto/src/asn1/bc/LinkedCertificate.cs100
1 files changed, 100 insertions, 0 deletions
diff --git a/crypto/src/asn1/bc/LinkedCertificate.cs b/crypto/src/asn1/bc/LinkedCertificate.cs
new file mode 100644
index 000000000..c8d05d8f5
--- /dev/null
+++ b/crypto/src/asn1/bc/LinkedCertificate.cs
@@ -0,0 +1,100 @@
+using System;
+
+using Org.BouncyCastle.Asn1.X509;
+
+namespace Org.BouncyCastle.Asn1.BC
+{
+    /**
+     * Extension to tie an alternate certificate to the containing certificate.
+     * <pre>
+     *     LinkedCertificate := SEQUENCE {
+     *         digest        DigestInfo,                   -- digest of PQC certificate
+     *         certLocation  GeneralName,                  -- location of PQC certificate
+     *         certIssuer    [0] Name OPTIONAL,            -- issuer of PQC cert (if different from current certificate)
+     *         cACerts       [1] GeneralNames OPTIONAL,    -- CA certificates for PQC cert (one of more locations)
+     * }
+     * </pre>
+     */
+    public class LinkedCertificate
+        : Asn1Encodable
+    {
+        private readonly DigestInfo mDigest;
+        private readonly GeneralName mCertLocation;
+
+        private X509Name mCertIssuer;
+        private GeneralNames mCACerts;
+
+        public LinkedCertificate(DigestInfo digest, GeneralName certLocation)
+            : this(digest, certLocation, null, null)
+        {
+        }
+
+        public LinkedCertificate(DigestInfo digest, GeneralName certLocation, X509Name certIssuer, GeneralNames caCerts)
+        {
+            this.mDigest = digest;
+            this.mCertLocation = certLocation;
+            this.mCertIssuer = certIssuer;
+            this.mCACerts = caCerts;
+        }
+
+        private LinkedCertificate(Asn1Sequence seq)
+        {
+            this.mDigest = DigestInfo.GetInstance(seq[0]);
+            this.mCertLocation = GeneralName.GetInstance(seq[1]);
+
+            for (int i = 2; i < seq.Count; ++i)
+            {
+                Asn1TaggedObject tagged =  Asn1TaggedObject.GetInstance(seq[i]);
+
+                switch (tagged.TagNo)
+                {
+                case 0:
+                    this.mCertIssuer = X509Name.GetInstance(tagged, false);
+                    break;
+                case 1:
+                    this.mCACerts = GeneralNames.GetInstance(tagged, false);
+                    break;
+                default:
+                    throw new ArgumentException("unknown tag in tagged field");
+                }
+            }
+        }
+
+        public static LinkedCertificate GetInstance(object obj)
+        {
+            if (obj is LinkedCertificate)
+                return (LinkedCertificate)obj;
+            if (obj != null)
+                return new LinkedCertificate(Asn1Sequence.GetInstance(obj));
+            return null;
+        }
+
+        public virtual DigestInfo Digest
+        {
+            get { return mDigest; }
+        }
+
+        public virtual GeneralName CertLocation
+        {
+            get { return mCertLocation; }
+        }
+
+        public virtual X509Name CertIssuer
+        {
+            get { return mCertIssuer; }
+        }
+
+        public virtual GeneralNames CACerts
+        {
+            get { return mCACerts; }
+        }
+
+        public override Asn1Object ToAsn1Object()
+        {
+            Asn1EncodableVector v = new Asn1EncodableVector(mDigest, mCertLocation);
+            v.AddOptionalTagged(false, 0, mCertIssuer);
+            v.AddOptionalTagged(false, 1, mCACerts);
+            return new DerSequence(v);
+        }
+    }
+}