summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/CertAnnContent.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cmp/CertAnnContent.cs')
-rw-r--r--crypto/src/asn1/cmp/CertAnnContent.cs54
1 files changed, 17 insertions, 37 deletions
diff --git a/crypto/src/asn1/cmp/CertAnnContent.cs b/crypto/src/asn1/cmp/CertAnnContent.cs
index 30b1fad2f..d41f48e2e 100644
--- a/crypto/src/asn1/cmp/CertAnnContent.cs
+++ b/crypto/src/asn1/cmp/CertAnnContent.cs
@@ -1,8 +1,6 @@
 using System;
-using System.IO;
 
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
@@ -14,56 +12,38 @@ namespace Org.BouncyCastle.Asn1.Cmp
     {
         public static new CertAnnContent GetInstance(object obj)
         {
-            // TODO[cmp]
             if (obj == null)
                 return null;
-
-            if (obj is CertAnnContent content)
-                return content;
-
+            if (obj is CertAnnContent certAnnContent)
+                return certAnnContent;
             if (obj is CmpCertificate cmpCertificate)
-                return GetInstance(cmpCertificate.GetEncoded());
-
-            if (obj is byte[] bs)
-            {
-                try
-                {
-                    obj = Asn1Object.FromByteArray(bs);
-                }
-                catch (IOException)
-                {
-                    throw new ArgumentException("Invalid encoding in CertAnnContent");
-                }
-            }
-
-            if (obj is Asn1Sequence)
-                return new CertAnnContent(X509CertificateStructure.GetInstance(obj));
-
-            // TODO[cmp]
+                return new CertAnnContent(cmpCertificate);
             if (obj is Asn1TaggedObject taggedObject)
-                return new CertAnnContent(taggedObject.TagNo, taggedObject.GetObject());
-
-            throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), nameof(obj));
+                return new CertAnnContent(taggedObject);
+            return new CertAnnContent(X509CertificateStructure.GetInstance(obj));
         }
 
         public static new CertAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            // TODO[cmp]
-            if (taggedObject == null)
-                return null;
-
-            if (!declaredExplicit)
-                throw new ArgumentException("tag must be explicit");
-
-            // TODO[cmp]
-            return GetInstance(taggedObject.GetObject());
+            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
         }
 
+        [Obsolete("Use 'GetInstance' from tagged object instead")]
         public CertAnnContent(int type, Asn1Object otherCert)
             : base(type, otherCert)
         {
         }
 
+        internal CertAnnContent(Asn1TaggedObject taggedObject)
+            : base(taggedObject)
+        {
+        }
+
+        internal CertAnnContent(CmpCertificate other)
+            : base(other)
+        {
+        }
+
         public CertAnnContent(X509CertificateStructure x509v3PKCert)
             : base(x509v3PKCert)
         {