summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/CertOrEncCert.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cmp/CertOrEncCert.cs')
-rw-r--r--crypto/src/asn1/cmp/CertOrEncCert.cs15
1 files changed, 9 insertions, 6 deletions
diff --git a/crypto/src/asn1/cmp/CertOrEncCert.cs b/crypto/src/asn1/cmp/CertOrEncCert.cs
index 1423503d2..94df00006 100644
--- a/crypto/src/asn1/cmp/CertOrEncCert.cs
+++ b/crypto/src/asn1/cmp/CertOrEncCert.cs
@@ -13,7 +13,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 				return null;
             if (obj is CertOrEncCert certOrEncCert)
                 return certOrEncCert;
-            return new CertOrEncCert(Asn1TaggedObject.GetInstance(obj));
+            return new CertOrEncCert(Asn1TaggedObject.GetInstance(obj, Asn1Tags.ContextSpecific));
         }
 
         public static CertOrEncCert GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
@@ -26,17 +26,18 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 		private CertOrEncCert(Asn1TaggedObject taggedObject)
 		{
-			if (taggedObject.TagNo == 0)
+			if (taggedObject.HasContextTag(0))
 			{
-				m_certificate = CmpCertificate.GetInstance(taggedObject.GetObject());
+				m_certificate = CmpCertificate.GetInstance(taggedObject.GetExplicitBaseObject());
 			}
-			else if (taggedObject.TagNo == 1)
+			else if (taggedObject.HasContextTag(1))
 			{
-                m_encryptedCert = EncryptedKey.GetInstance(taggedObject.GetObject());
+                m_encryptedCert = EncryptedKey.GetInstance(taggedObject.GetExplicitBaseObject());
 			}
 			else
 			{
-				throw new ArgumentException("unknown tag: " + taggedObject.TagNo, nameof(taggedObject));
+				throw new ArgumentException("unknown tag: " + Asn1Utilities.GetTagText(taggedObject),
+					nameof(taggedObject));
             }
         }
 
@@ -60,6 +61,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 		public virtual EncryptedKey EncryptedCert => m_encryptedCert;
 
+		public virtual bool HasEncryptedCertificate => m_encryptedCert != null;
+
         /**
 		 * <pre>
 		 * CertOrEncCert ::= CHOICE {