summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/PKIMessage.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cmp/PKIMessage.cs')
-rw-r--r--crypto/src/asn1/cmp/PKIMessage.cs31
1 files changed, 17 insertions, 14 deletions
diff --git a/crypto/src/asn1/cmp/PKIMessage.cs b/crypto/src/asn1/cmp/PKIMessage.cs
index 9ac54b3da..2265dd9b2 100644
--- a/crypto/src/asn1/cmp/PKIMessage.cs
+++ b/crypto/src/asn1/cmp/PKIMessage.cs
@@ -5,6 +5,20 @@ namespace Org.BouncyCastle.Asn1.Cmp
     public class PkiMessage
         : Asn1Encodable
     {
+        public static PkiMessage GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is PkiMessage pkiMessage)
+                return pkiMessage;
+            return new PkiMessage(Asn1Sequence.GetInstance(obj));
+        }
+
+        public static PkiMessage GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
+
         private readonly PkiHeader header;
         private readonly PkiBody body;
         private readonly DerBitString protection;
@@ -17,30 +31,19 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
             for (int pos = 2; pos < seq.Count; ++pos)
             {
-                Asn1TaggedObject tObj = (Asn1TaggedObject)seq[pos].ToAsn1Object();
+                Asn1TaggedObject tObj = Asn1TaggedObject.GetInstance(seq[pos]);
 
-                if (tObj.TagNo == 0)
+                if (tObj.HasContextTag(0))
                 {
                     protection = DerBitString.GetInstance(tObj, true);
                 }
-                else
+                else if (tObj.HasContextTag(1))
                 {
                     extraCerts = Asn1Sequence.GetInstance(tObj, true);
                 }
             }
         }
 
-        public static PkiMessage GetInstance(object obj)
-        {
-            if (obj is PkiMessage)
-                return (PkiMessage)obj;
-
-            if (obj != null)
-                return new PkiMessage(Asn1Sequence.GetInstance(obj));
-
-            return null;
-        }
-
         /**
          * Creates a new PkiMessage.
          *