summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/cmp/CAKeyUpdAnnContent.cs7
-rw-r--r--crypto/src/asn1/cmp/CertConfirmContent.cs14
-rw-r--r--crypto/src/asn1/cmp/CertOrEncCert.cs9
-rw-r--r--crypto/src/asn1/cmp/CertRepMessage.cs14
-rw-r--r--crypto/src/asn1/cmp/CertReqTemplateContent.cs5
-rw-r--r--crypto/src/asn1/cmp/CertResponse.cs23
-rw-r--r--crypto/src/asn1/cmp/CertStatus.cs18
-rw-r--r--crypto/src/asn1/cmp/CertifiedKeyPair.cs5
-rw-r--r--crypto/src/asn1/cmp/Challenge.cs11
-rw-r--r--crypto/src/asn1/cmp/CrlAnnContent.cs12
-rw-r--r--crypto/src/asn1/cmp/CrlSource.cs16
-rw-r--r--crypto/src/asn1/cmp/CrlStatus.cs2
-rw-r--r--crypto/src/asn1/cmp/DhbmParameter.cs7
-rw-r--r--crypto/src/asn1/cmp/ErrorMsgContent.cs15
-rw-r--r--crypto/src/asn1/cmp/GenMsgContent.cs13
-rw-r--r--crypto/src/asn1/cmp/GenRepContent.cs13
-rw-r--r--crypto/src/asn1/cmp/InfoTypeAndValue.cs2
-rw-r--r--crypto/src/asn1/cmp/KeyRecRepContent.cs17
-rw-r--r--crypto/src/asn1/cmp/NestedMessageContent.cs4
-rw-r--r--crypto/src/asn1/cmp/OobCertHash.cs12
-rw-r--r--crypto/src/asn1/cmp/PKIBody.cs5
-rw-r--r--crypto/src/asn1/cmp/PKIConfirmContent.cs7
-rw-r--r--crypto/src/asn1/cmp/PKIFreeText.cs12
-rw-r--r--crypto/src/asn1/cmp/PKIHeader.cs9
-rw-r--r--crypto/src/asn1/cmp/PKIHeaderBuilder.cs3
-rw-r--r--crypto/src/asn1/cmp/PKIMessage.cs68
-rw-r--r--crypto/src/asn1/cmp/PKIMessages.cs12
-rw-r--r--crypto/src/asn1/cmp/PKIStatus.cs14
-rw-r--r--crypto/src/asn1/cmp/PKIStatusInfo.cs52
-rw-r--r--crypto/src/asn1/cmp/PbmParameter.cs11
-rw-r--r--crypto/src/asn1/cmp/PollRepContent.cs2
-rw-r--r--crypto/src/asn1/cmp/PollReqContent.cs7
-rw-r--r--crypto/src/asn1/cmp/PopoDecKeyChallContent.cs12
-rw-r--r--crypto/src/asn1/cmp/PopoDecKeyRespContent.cs12
-rw-r--r--crypto/src/asn1/cmp/ProtectedPart.cs7
-rw-r--r--crypto/src/asn1/cmp/RevAnnContent.cs7
-rw-r--r--crypto/src/asn1/cmp/RevDetails.cs5
-rw-r--r--crypto/src/asn1/cmp/RevRepContent.cs20
-rw-r--r--crypto/src/asn1/cmp/RevRepContentBuilder.cs2
-rw-r--r--crypto/src/asn1/cmp/RevReqContent.cs12
-rw-r--r--crypto/src/asn1/cmp/RootCaKeyUpdateContent.cs10
41 files changed, 200 insertions, 308 deletions
diff --git a/crypto/src/asn1/cmp/CAKeyUpdAnnContent.cs b/crypto/src/asn1/cmp/CAKeyUpdAnnContent.cs
index d39c57bc9..4460c8265 100644
--- a/crypto/src/asn1/cmp/CAKeyUpdAnnContent.cs
+++ b/crypto/src/asn1/cmp/CAKeyUpdAnnContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CAKeyUpdAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CAKeyUpdAnnContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CmpCertificate m_oldWithNew;
@@ -44,9 +44,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return new DerSequence(m_oldWithNew, m_newWithOld, m_newWithNew);
-		}
+		public override Asn1Object ToAsn1Object() => new DerSequence(m_oldWithNew, m_newWithOld, m_newWithNew);
 	}
 }
diff --git a/crypto/src/asn1/cmp/CertConfirmContent.cs b/crypto/src/asn1/cmp/CertConfirmContent.cs
index e11826d6b..61b7451b4 100644
--- a/crypto/src/asn1/cmp/CertConfirmContent.cs
+++ b/crypto/src/asn1/cmp/CertConfirmContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertConfirmContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertConfirmContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -24,20 +24,14 @@ namespace Org.BouncyCastle.Asn1.Cmp
             m_content = seq;
         }
 
-        public virtual CertStatus[] ToCertStatusArray()
-		{
-			return m_content.MapElements(CertStatus.GetInstance);
-		}
+        public virtual CertStatus[] ToCertStatusArray() => m_content.MapElements(CertStatus.GetInstance);
 
-		/**
+        /**
 		 * <pre>
 		 * CertConfirmContent ::= SEQUENCE OF CertStatus
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+        public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/CertOrEncCert.cs b/crypto/src/asn1/cmp/CertOrEncCert.cs
index d248de1aa..94df00006 100644
--- a/crypto/src/asn1/cmp/CertOrEncCert.cs
+++ b/crypto/src/asn1/cmp/CertOrEncCert.cs
@@ -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.GetExplicitBaseObject());
 			}
-			else if (taggedObject.TagNo == 1)
+			else if (taggedObject.HasContextTag(1))
 			{
                 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 {
diff --git a/crypto/src/asn1/cmp/CertRepMessage.cs b/crypto/src/asn1/cmp/CertRepMessage.cs
index 882816b86..9c260eadb 100644
--- a/crypto/src/asn1/cmp/CertRepMessage.cs
+++ b/crypto/src/asn1/cmp/CertRepMessage.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertRepMessage GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertRepMessage(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_caPubs;
@@ -39,7 +39,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			if (response == null)
 				throw new ArgumentNullException(nameof(response));
 
-			if (caPubs != null)
+			if (caPubs != null && caPubs.Length > 0)
 			{
 				m_caPubs = new DerSequence(caPubs);
 			}
@@ -47,15 +47,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			m_response = new DerSequence(response);
 		}
 
-		public virtual CmpCertificate[] GetCAPubs()
-		{
-			return m_caPubs == null ? null : m_caPubs.MapElements(CmpCertificate.GetInstance);
-		}
+		public virtual CmpCertificate[] GetCAPubs() => m_caPubs?.MapElements(CmpCertificate.GetInstance);
 
-		public virtual CertResponse[] GetResponse()
-		{
-            return m_response.MapElements(CertResponse.GetInstance);
-		}
+		public virtual CertResponse[] GetResponse() => m_response.MapElements(CertResponse.GetInstance);
 
 		/**
 		 * <pre>
diff --git a/crypto/src/asn1/cmp/CertReqTemplateContent.cs b/crypto/src/asn1/cmp/CertReqTemplateContent.cs
index c08a9a293..ae35bc5e8 100644
--- a/crypto/src/asn1/cmp/CertReqTemplateContent.cs
+++ b/crypto/src/asn1/cmp/CertReqTemplateContent.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertReqTemplateContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertReqTemplateContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CertTemplate m_certTemplate;
@@ -62,7 +62,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(m_certTemplate);
+            Asn1EncodableVector v = new Asn1EncodableVector(2);
+            v.Add(m_certTemplate);
             v.AddOptional(m_keySpec);
             return new DerSequence(v);
         }
diff --git a/crypto/src/asn1/cmp/CertResponse.cs b/crypto/src/asn1/cmp/CertResponse.cs
index e70d6d388..ce3355270 100644
--- a/crypto/src/asn1/cmp/CertResponse.cs
+++ b/crypto/src/asn1/cmp/CertResponse.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertResponse GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertResponse(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly DerInteger m_certReqId;
@@ -34,9 +34,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 				if (seq.Count == 3)
 				{
 					Asn1Encodable o = seq[2];
-					if (o is Asn1OctetString)
+					if (o is Asn1OctetString octetString)
 					{
-						m_rspInfo = Asn1OctetString.GetInstance(o);
+						m_rspInfo = octetString;
 					}
 					else
 					{
@@ -59,15 +59,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
         public CertResponse(DerInteger certReqId, PkiStatusInfo status, CertifiedKeyPair certifiedKeyPair,
             Asn1OctetString rspInfo)
         {
-            if (certReqId == null)
-				throw new ArgumentNullException(nameof(certReqId));
-
-			if (status == null)
-				throw new ArgumentNullException(nameof(status));
-
-			m_certReqId = certReqId;
-			m_status = status;
-			m_certifiedKeyPair = certifiedKeyPair;
+			m_certReqId = certReqId ?? throw new ArgumentNullException(nameof(certReqId));
+			m_status = status ?? throw new ArgumentNullException(nameof(status));
+            m_certifiedKeyPair = certifiedKeyPair;
 			m_rspInfo = rspInfo;
 		}
 
@@ -77,6 +71,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 		public virtual CertifiedKeyPair CertifiedKeyPair => m_certifiedKeyPair;
 
+		public virtual Asn1OctetString RspInfo => m_rspInfo;
+
 		/**
 		 * <pre>
 		 * CertResponse ::= SEQUENCE {
@@ -95,7 +91,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_certReqId, m_status);
+			Asn1EncodableVector v = new Asn1EncodableVector(4);
+			v.Add(m_certReqId, m_status);
 			v.AddOptional(m_certifiedKeyPair, m_rspInfo);
 			return new DerSequence(v);
 		}
diff --git a/crypto/src/asn1/cmp/CertStatus.cs b/crypto/src/asn1/cmp/CertStatus.cs
index 37f0c29e8..b64a0fe84 100644
--- a/crypto/src/asn1/cmp/CertStatus.cs
+++ b/crypto/src/asn1/cmp/CertStatus.cs
@@ -19,7 +19,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertStatus(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1OctetString m_certHash;
@@ -43,8 +43,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 					}
 					if (p is Asn1TaggedObject dto)
 					{
-						if (dto.TagNo != 0)
-							throw new ArgumentException("unknown tag " + dto.TagNo);
+						if (!dto.HasContextTag(0))
+							throw new ArgumentException("unknown tag " + Asn1Utilities.GetTagText(dto));
 
 						m_hashAlg = AlgorithmIdentifier.GetInstance(dto, true);
 					}
@@ -56,14 +56,17 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		{
 			m_certHash = new DerOctetString(certHash);
 			m_certReqID = new DerInteger(certReqID);
-		}
+            m_statusInfo = null;
+            m_hashAlg = null;
+        }
 
-		public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo)
+        public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo)
 		{
             m_certHash = new DerOctetString(certHash);
             m_certReqID = new DerInteger(certReqID);
             m_statusInfo = statusInfo;
-		}
+            m_hashAlg = null;
+        }
 
         public CertStatus(byte[] certHash, BigInteger certReqID, PkiStatusInfo statusInfo, AlgorithmIdentifier hashAlg)
         {
@@ -97,7 +100,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
          */
         public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_certHash, m_certReqID);
+			Asn1EncodableVector v = new Asn1EncodableVector(4);
+			v.Add(m_certHash, m_certReqID);
 			v.AddOptional(m_statusInfo);
 			v.AddOptionalTagged(true, 0, m_hashAlg);
 			return new DerSequence(v);
diff --git a/crypto/src/asn1/cmp/CertifiedKeyPair.cs b/crypto/src/asn1/cmp/CertifiedKeyPair.cs
index 73828fda4..9c7fd8175 100644
--- a/crypto/src/asn1/cmp/CertifiedKeyPair.cs
+++ b/crypto/src/asn1/cmp/CertifiedKeyPair.cs
@@ -18,7 +18,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CertifiedKeyPair GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CertifiedKeyPair(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CertOrEncCert m_certOrEncCert;
@@ -94,7 +94,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_certOrEncCert);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
+			v.Add(m_certOrEncCert);
             v.AddOptionalTagged(true, 0, m_privateKey);
             v.AddOptionalTagged(true, 1, m_publicationInfo);
 			return new DerSequence(v);
diff --git a/crypto/src/asn1/cmp/Challenge.cs b/crypto/src/asn1/cmp/Challenge.cs
index b86c3d800..4e30dcb55 100644
--- a/crypto/src/asn1/cmp/Challenge.cs
+++ b/crypto/src/asn1/cmp/Challenge.cs
@@ -44,7 +44,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static Challenge GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new Challenge(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly AlgorithmIdentifier m_owf;
@@ -111,7 +111,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
         public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(2);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
 			v.AddOptional(m_owf);
 			v.Add(m_witness, m_challenge);
 			return new DerSequence(v);
@@ -134,7 +134,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
             public static Rand GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
             {
-                return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+                return new Rand(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
             }
 
             private readonly DerInteger m_intVal;
@@ -159,10 +159,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 			public virtual GeneralName Sender => m_sender;
 
-			public override Asn1Object ToAsn1Object()
-			{
-                return new DerSequence(m_intVal, m_sender);
-            }
+			public override Asn1Object ToAsn1Object() => new DerSequence(m_intVal, m_sender);
         }
 	}
 }
diff --git a/crypto/src/asn1/cmp/CrlAnnContent.cs b/crypto/src/asn1/cmp/CrlAnnContent.cs
index ac8fc0458..fb566c17f 100644
--- a/crypto/src/asn1/cmp/CrlAnnContent.cs
+++ b/crypto/src/asn1/cmp/CrlAnnContent.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CrlAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CrlAnnContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -31,10 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
             m_content = new DerSequence(crl);
         }
 
-        public virtual CertificateList[] ToCertificateListArray()
-		{
-			return m_content.MapElements(CertificateList.GetInstance);
-		}
+        public virtual CertificateList[] ToCertificateListArray() => m_content.MapElements(CertificateList.GetInstance);
 
 		/**
 		 * <pre>
@@ -42,9 +39,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+		public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/CrlSource.cs b/crypto/src/asn1/cmp/CrlSource.cs
index 6203b17c7..61fc96b32 100644
--- a/crypto/src/asn1/cmp/CrlSource.cs
+++ b/crypto/src/asn1/cmp/CrlSource.cs
@@ -36,18 +36,20 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         private CrlSource(Asn1TaggedObject taggedObject)
         {
-            switch (taggedObject.TagNo)
+            if (taggedObject.HasContextTag(0))
             {
-            case 0:
                 m_dpn = DistributionPointName.GetInstance(taggedObject, true);
                 m_issuer = null;
-                break;
-            case 1:
+            }
+            else if (taggedObject.HasContextTag(1))
+            {
                 m_dpn = null;
                 m_issuer = GeneralNames.GetInstance(taggedObject, true);
-                break;
-            default:
-                throw new ArgumentException("unknown tag: " + Asn1Utilities.GetTagText(taggedObject));
+            }
+            else
+            {
+                throw new ArgumentException("unknown tag " + Asn1Utilities.GetTagText(taggedObject),
+                    nameof(taggedObject));
             }
         }
 
diff --git a/crypto/src/asn1/cmp/CrlStatus.cs b/crypto/src/asn1/cmp/CrlStatus.cs
index 6cd01c945..f5cf091f4 100644
--- a/crypto/src/asn1/cmp/CrlStatus.cs
+++ b/crypto/src/asn1/cmp/CrlStatus.cs
@@ -23,7 +23,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static CrlStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new CrlStatus(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CrlSource m_source;
diff --git a/crypto/src/asn1/cmp/DhbmParameter.cs b/crypto/src/asn1/cmp/DhbmParameter.cs
index 12b8d91d3..1b44b732e 100644
--- a/crypto/src/asn1/cmp/DhbmParameter.cs
+++ b/crypto/src/asn1/cmp/DhbmParameter.cs
@@ -26,7 +26,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static DhbmParameter GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new DhbmParameter(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly AlgorithmIdentifier m_owf;
@@ -51,9 +51,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public virtual AlgorithmIdentifier Mac => m_mac;
 
-        public override Asn1Object ToAsn1Object()
-        {
-            return new DerSequence(m_owf, m_mac);
-        }
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_owf, m_mac);
     }
 }
diff --git a/crypto/src/asn1/cmp/ErrorMsgContent.cs b/crypto/src/asn1/cmp/ErrorMsgContent.cs
index 0937d85d4..44646313e 100644
--- a/crypto/src/asn1/cmp/ErrorMsgContent.cs
+++ b/crypto/src/asn1/cmp/ErrorMsgContent.cs
@@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static ErrorMsgContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new ErrorMsgContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly PkiStatusInfo m_pkiStatusInfo;
@@ -57,15 +57,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		{
 		}
 
-		public ErrorMsgContent(
-			PkiStatusInfo	pkiStatusInfo,
-			DerInteger		errorCode,
-			PkiFreeText		errorDetails)
+		public ErrorMsgContent(PkiStatusInfo pkiStatusInfo, DerInteger errorCode, PkiFreeText errorDetails)
 		{
-			if (pkiStatusInfo == null)
-				throw new ArgumentNullException(nameof(pkiStatusInfo));
-
-			m_pkiStatusInfo = pkiStatusInfo;
+			m_pkiStatusInfo = pkiStatusInfo ?? throw new ArgumentNullException(nameof(pkiStatusInfo));
 			m_errorCode = errorCode;
 			m_errorDetails = errorDetails;
 		}
@@ -90,7 +84,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_pkiStatusInfo);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
+			v.Add(m_pkiStatusInfo);
 			v.AddOptional(m_errorCode, m_errorDetails);
 			return new DerSequence(v);
 		}
diff --git a/crypto/src/asn1/cmp/GenMsgContent.cs b/crypto/src/asn1/cmp/GenMsgContent.cs
index 11c0c8b3b..378f8e5d6 100644
--- a/crypto/src/asn1/cmp/GenMsgContent.cs
+++ b/crypto/src/asn1/cmp/GenMsgContent.cs
@@ -17,7 +17,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static GenMsgContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new GenMsgContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -37,10 +37,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			m_content = new DerSequence(itvs);
 		}
 
-		public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray()
-		{
-			return m_content.MapElements(InfoTypeAndValue.GetInstance);
-		}
+		public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray() =>
+            m_content.MapElements(InfoTypeAndValue.GetInstance);
 
 		/**
 		 * <pre>
@@ -48,9 +46,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+		public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/GenRepContent.cs b/crypto/src/asn1/cmp/GenRepContent.cs
index 1de37e094..f155e691e 100644
--- a/crypto/src/asn1/cmp/GenRepContent.cs
+++ b/crypto/src/asn1/cmp/GenRepContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static GenRepContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new GenRepContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -34,10 +34,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			m_content = new DerSequence(itvs);
 		}
 
-		public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray()
-		{
-            return m_content.MapElements(InfoTypeAndValue.GetInstance);
-		}
+		public virtual InfoTypeAndValue[] ToInfoTypeAndValueArray() =>
+			m_content.MapElements(InfoTypeAndValue.GetInstance);
 
 		/**
 		 * <pre>
@@ -45,9 +43,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+		public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/InfoTypeAndValue.cs b/crypto/src/asn1/cmp/InfoTypeAndValue.cs
index ca6dc1fe5..03e055f10 100644
--- a/crypto/src/asn1/cmp/InfoTypeAndValue.cs
+++ b/crypto/src/asn1/cmp/InfoTypeAndValue.cs
@@ -61,7 +61,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static InfoTypeAndValue GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new InfoTypeAndValue(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly DerObjectIdentifier m_infoType;
diff --git a/crypto/src/asn1/cmp/KeyRecRepContent.cs b/crypto/src/asn1/cmp/KeyRecRepContent.cs
index 8121988d2..e465346eb 100644
--- a/crypto/src/asn1/cmp/KeyRecRepContent.cs
+++ b/crypto/src/asn1/cmp/KeyRecRepContent.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static KeyRecRepContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new KeyRecRepContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly PkiStatusInfo m_status;
@@ -44,7 +44,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 					m_keyPairHist = Asn1Sequence.GetInstance(tObj.GetExplicitBaseObject());
 					break;
 				default:
-					throw new ArgumentException("unknown tag number: " + tObj.TagNo, "seq");
+					throw new ArgumentException("unknown tag number: " + tObj.TagNo);
 				}
 			}
 		}
@@ -53,15 +53,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 		public virtual CmpCertificate NewSigCert => m_newSigCert;
 
-		public virtual CmpCertificate[] GetCACerts()
-		{
-			return m_caCerts?.MapElements(CmpCertificate.GetInstance);
-		}
+		public virtual CmpCertificate[] GetCACerts() => m_caCerts?.MapElements(CmpCertificate.GetInstance);
 
-		public virtual CertifiedKeyPair[] GetKeyPairHist()
-		{
-			return m_keyPairHist?.MapElements(CertifiedKeyPair.GetInstance);
-		}
+		public virtual CertifiedKeyPair[] GetKeyPairHist() => m_keyPairHist?.MapElements(CertifiedKeyPair.GetInstance);
 
 		/**
 		 * <pre>
@@ -78,7 +72,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_status);
+			Asn1EncodableVector v = new Asn1EncodableVector(4);
+			v.Add(m_status);
             v.AddOptionalTagged(true, 0, m_newSigCert);
             v.AddOptionalTagged(true, 1, m_caCerts);
             v.AddOptionalTagged(true, 2, m_keyPairHist);
diff --git a/crypto/src/asn1/cmp/NestedMessageContent.cs b/crypto/src/asn1/cmp/NestedMessageContent.cs
index fc73fac1b..35daffabe 100644
--- a/crypto/src/asn1/cmp/NestedMessageContent.cs
+++ b/crypto/src/asn1/cmp/NestedMessageContent.cs
@@ -23,7 +23,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static new NestedMessageContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+#pragma warning disable CS0618 // Type or member is obsolete
+            return new NestedMessageContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+#pragma warning restore CS0618 // Type or member is obsolete
         }
 
         public NestedMessageContent(PkiMessage msg)
diff --git a/crypto/src/asn1/cmp/OobCertHash.cs b/crypto/src/asn1/cmp/OobCertHash.cs
index 95cbe0cf2..1e6224612 100644
--- a/crypto/src/asn1/cmp/OobCertHash.cs
+++ b/crypto/src/asn1/cmp/OobCertHash.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static OobCertHash GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new OobCertHash(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly AlgorithmIdentifier m_hashAlg;
@@ -48,15 +48,19 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			{
 				Asn1TaggedObject tObj = (Asn1TaggedObject)seq[i];
 
-				if (tObj.TagNo == 0)
+				if (tObj.HasContextTag(0))
 				{
 					m_hashAlg = AlgorithmIdentifier.GetInstance(tObj, true);
 				}
-				else
+				else if (tObj.HasContextTag(1))
 				{
 					m_certId = CertId.GetInstance(tObj, true);
 				}
-			}
+				else
+				{
+                    throw new ArgumentException("unknown tag " + Asn1Utilities.GetTagText(tObj));
+                }
+            }
 		}
 
 		public virtual CertId CertID => m_certId;
diff --git a/crypto/src/asn1/cmp/PKIBody.cs b/crypto/src/asn1/cmp/PKIBody.cs
index 467a78c8d..19a1a03a1 100644
--- a/crypto/src/asn1/cmp/PKIBody.cs
+++ b/crypto/src/asn1/cmp/PKIBody.cs
@@ -202,9 +202,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
          * </pre>
          * @return a basic ASN.1 object representation.
          */
-        public override Asn1Object ToAsn1Object()
-        {
-            return new DerTaggedObject(true, m_tagNo, m_body);
-        }
+        public override Asn1Object ToAsn1Object() => new DerTaggedObject(true, m_tagNo, m_body);
     }
 }
diff --git a/crypto/src/asn1/cmp/PKIConfirmContent.cs b/crypto/src/asn1/cmp/PKIConfirmContent.cs
index 34a66f3f7..6cc5b6ae6 100644
--- a/crypto/src/asn1/cmp/PKIConfirmContent.cs
+++ b/crypto/src/asn1/cmp/PKIConfirmContent.cs
@@ -19,7 +19,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiConfirmContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Null.GetInstance(taggedObject, declaredExplicit));
+            return new PkiConfirmContent(Asn1Null.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Null m_val;
@@ -40,9 +40,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_val;
-		}
+		public override Asn1Object ToAsn1Object() => m_val;
 	}
 }
diff --git a/crypto/src/asn1/cmp/PKIFreeText.cs b/crypto/src/asn1/cmp/PKIFreeText.cs
index f4d7e0967..a567852e4 100644
--- a/crypto/src/asn1/cmp/PKIFreeText.cs
+++ b/crypto/src/asn1/cmp/PKIFreeText.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiFreeText GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PkiFreeText(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_strings;
@@ -65,19 +65,13 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * @param index index of the string of interest
 		 * @return the string at index.
 		 */
-		public DerUtf8String this[int index]
-		{
-			get { return (DerUtf8String)m_strings[index]; }
-		}
+		public DerUtf8String this[int index] => (DerUtf8String)m_strings[index];
 
 		/**
 		 * <pre>
 		 * PkiFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
 		 * </pre>
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_strings;
-		}
+		public override Asn1Object ToAsn1Object() => m_strings;
 	}
 }
diff --git a/crypto/src/asn1/cmp/PKIHeader.cs b/crypto/src/asn1/cmp/PKIHeader.cs
index 6914ae613..c000c8b98 100644
--- a/crypto/src/asn1/cmp/PKIHeader.cs
+++ b/crypto/src/asn1/cmp/PKIHeader.cs
@@ -1,7 +1,6 @@
 using System;
 
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
@@ -27,7 +26,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiHeader GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PkiHeader(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly DerInteger pvno;
@@ -52,8 +51,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
             for (int pos = 3; pos < seq.Count; ++pos)
             {
                 Asn1TaggedObject tObj = Asn1TaggedObject.GetInstance(seq[pos]);
-                if (Asn1Tags.ContextSpecific != tObj.TagClass)
-                    continue;
+                if (!tObj.HasContextTag())
+                    throw new ArgumentException("unknown tag: " + Asn1Utilities.GetTagText(tObj));
 
                 switch (tObj.TagNo)
                 {
@@ -85,7 +84,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
                     generalInfo = Asn1Sequence.GetInstance(tObj, true);
                     break;
                 default:
-                    throw new ArgumentException("unknown tag number: " + tObj.TagNo, nameof(seq));
+                    throw new ArgumentException("unknown tag number: " + tObj.TagNo);
                 }
             }
         }
diff --git a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
index 6c7a2db63..914c8a8fa 100644
--- a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
+++ b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
@@ -176,7 +176,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public virtual PkiHeader Build()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(pvno, sender, recipient);
+			Asn1EncodableVector v = new Asn1EncodableVector(12);
+			v.Add(pvno, sender, recipient);
             v.AddOptionalTagged(true, 0, messageTime);
             v.AddOptionalTagged(true, 1, protectionAlg);
 			v.AddOptionalTagged(true, 2, senderKID);
diff --git a/crypto/src/asn1/cmp/PKIMessage.cs b/crypto/src/asn1/cmp/PKIMessage.cs
index 2265dd9b2..e835b6f16 100644
--- a/crypto/src/asn1/cmp/PKIMessage.cs
+++ b/crypto/src/asn1/cmp/PKIMessage.cs
@@ -16,18 +16,18 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiMessage GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PkiMessage(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
-        private readonly PkiHeader header;
-        private readonly PkiBody body;
-        private readonly DerBitString protection;
-        private readonly Asn1Sequence extraCerts;
+        private readonly PkiHeader m_header;
+        private readonly PkiBody m_body;
+        private readonly DerBitString m_protection;
+        private readonly Asn1Sequence m_extraCerts;
 
         private PkiMessage(Asn1Sequence seq)
         {
-            header = PkiHeader.GetInstance(seq[0]);
-            body = PkiBody.GetInstance(seq[1]);
+            m_header = PkiHeader.GetInstance(seq[0]);
+            m_body = PkiBody.GetInstance(seq[1]);
 
             for (int pos = 2; pos < seq.Count; ++pos)
             {
@@ -35,11 +35,11 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
                 if (tObj.HasContextTag(0))
                 {
-                    protection = DerBitString.GetInstance(tObj, true);
+                    m_protection = DerBitString.GetInstance(tObj, true);
                 }
                 else if (tObj.HasContextTag(1))
                 {
-                    extraCerts = Asn1Sequence.GetInstance(tObj, true);
+                    m_extraCerts = Asn1Sequence.GetInstance(tObj, true);
                 }
             }
         }
@@ -52,55 +52,34 @@ namespace Org.BouncyCastle.Asn1.Cmp
          * @param protection message protection (may be null)
          * @param extraCerts extra certificates (may be null)
          */
-        public PkiMessage(
-            PkiHeader header,
-            PkiBody body,
-            DerBitString protection,
-            CmpCertificate[] extraCerts)
+        public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection, CmpCertificate[] extraCerts)
         {
-            this.header = header;
-            this.body = body;
-            this.protection = protection;
+            m_header = header;
+            m_body = body;
+            m_protection = protection;
             if (extraCerts != null)
             {
-                this.extraCerts = new DerSequence(extraCerts);
+                m_extraCerts = new DerSequence(extraCerts);
             }
         }
 
-        public PkiMessage(
-            PkiHeader header,
-            PkiBody body,
-            DerBitString protection)
+        public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection)
             : this(header, body, protection, null)
         {
         }
 
-        public PkiMessage(
-            PkiHeader header,
-            PkiBody body)
+        public PkiMessage(PkiHeader header, PkiBody body)
             : this(header, body, null, null)
         {
         }
 
-        public virtual PkiHeader Header
-        {
-            get { return header; }
-        }
+        public virtual PkiHeader Header => m_header;
 
-        public virtual PkiBody Body
-        {
-            get { return body; }
-        }
+        public virtual PkiBody Body => m_body;
 
-        public virtual DerBitString Protection
-        {
-            get { return protection; }
-        }
+        public virtual DerBitString Protection => m_protection;
 
-        public virtual CmpCertificate[] GetExtraCerts()
-        {
-            return extraCerts?.MapElements(CmpCertificate.GetInstance);
-        }
+        public virtual CmpCertificate[] GetExtraCerts() => m_extraCerts?.MapElements(CmpCertificate.GetInstance);
 
         /**
          * <pre>
@@ -116,9 +95,10 @@ namespace Org.BouncyCastle.Asn1.Cmp
          */
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(header, body);
-            v.AddOptionalTagged(true, 0, protection);
-            v.AddOptionalTagged(true, 1, extraCerts);
+            Asn1EncodableVector v = new Asn1EncodableVector(4);
+            v.Add(m_header, m_body);
+            v.AddOptionalTagged(true, 0, m_protection);
+            v.AddOptionalTagged(true, 1, m_extraCerts);
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cmp/PKIMessages.cs b/crypto/src/asn1/cmp/PKIMessages.cs
index ea7550b9a..1396b615c 100644
--- a/crypto/src/asn1/cmp/PKIMessages.cs
+++ b/crypto/src/asn1/cmp/PKIMessages.cs
@@ -18,7 +18,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiMessages GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PkiMessages(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private Asn1Sequence m_content;
@@ -38,10 +38,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
             m_content = new DerSequence(msgs);
         }
 
-        public virtual PkiMessage[] ToPkiMessageArray()
-        {
-            return m_content.MapElements(PkiMessage.GetInstance);
-        }
+        public virtual PkiMessage[] ToPkiMessageArray() => m_content.MapElements(PkiMessage.GetInstance);
 
         /**
          * <pre>
@@ -49,9 +46,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
          * </pre>
          * @return a basic ASN.1 object representation.
          */
-        public override Asn1Object ToAsn1Object()
-        {
-            return m_content;
-        }
+        public override Asn1Object ToAsn1Object() => m_content;
     }
 }
diff --git a/crypto/src/asn1/cmp/PKIStatus.cs b/crypto/src/asn1/cmp/PKIStatus.cs
index 72b0c7403..0a7e9e958 100644
--- a/crypto/src/asn1/cmp/PKIStatus.cs
+++ b/crypto/src/asn1/cmp/PKIStatus.cs
@@ -41,7 +41,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
             return GetInstance(DerInteger.GetInstance(taggedObject, declaredExplicit));
         }
 
-        private readonly DerInteger status;
+        private readonly DerInteger m_status;
 
 		private PkiStatusEncodable(PkiStatus status)
 			: this(new DerInteger((int)status))
@@ -50,17 +50,11 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
 		private PkiStatusEncodable(DerInteger status)
 		{
-			this.status = status;
+			m_status = status;
 		}
 
-		public virtual BigInteger Value
-		{
-			get { return status.Value; }
-		}
+		public virtual BigInteger Value => m_status.Value;
 
-		public override Asn1Object ToAsn1Object()
-		{
-			return status;
-		}
+		public override Asn1Object ToAsn1Object() => m_status;
 	}
 }
diff --git a/crypto/src/asn1/cmp/PKIStatusInfo.cs b/crypto/src/asn1/cmp/PKIStatusInfo.cs
index 17473efc8..fbd180c6d 100644
--- a/crypto/src/asn1/cmp/PKIStatusInfo.cs
+++ b/crypto/src/asn1/cmp/PKIStatusInfo.cs
@@ -20,63 +20,68 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PkiStatusInfo GetInstance(Asn1TaggedObject obj, bool isExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
+#pragma warning disable CS0618 // Type or member is obsolete
+            return new PkiStatusInfo(Asn1Sequence.GetInstance(obj, isExplicit));
+#pragma warning restore CS0618 // Type or member is obsolete
         }
 
-		private readonly DerInteger status;
-		private readonly PkiFreeText statusString;
-		private readonly DerBitString failInfo;
+        private readonly DerInteger m_status;
+		private readonly PkiFreeText m_statusString;
+		private readonly DerBitString m_failInfo;
 
         [Obsolete("Use 'GetInstance' instead")]
         public PkiStatusInfo(Asn1Sequence seq)
 		{
-			this.status = DerInteger.GetInstance(seq[0]);
+			m_status = DerInteger.GetInstance(seq[0]);
 
-			this.statusString = null;
-			this.failInfo = null;
+			m_statusString = null;
+			m_failInfo = null;
 
 			if (seq.Count > 2)
 			{
-				this.statusString = PkiFreeText.GetInstance(seq[1]);
-				this.failInfo = DerBitString.GetInstance(seq[2]);
+				m_statusString = PkiFreeText.GetInstance(seq[1]);
+				m_failInfo = DerBitString.GetInstance(seq[2]);
 			}
 			else if (seq.Count > 1)
 			{
 				object obj = seq[1];
 				if (obj is DerBitString)
 				{
-					this.failInfo = DerBitString.GetInstance(obj);
+					m_failInfo = DerBitString.GetInstance(obj);
 				}
 				else
 				{
-					this.statusString = PkiFreeText.GetInstance(obj);
+					m_statusString = PkiFreeText.GetInstance(obj);
 				}
 			}
 		}
 
 		public PkiStatusInfo(int status)
 		{
-			this.status = new DerInteger(status);
+			m_status = new DerInteger(status);
+			m_statusString = null;
+			m_failInfo = null;
 		}
 
 		public PkiStatusInfo(int status, PkiFreeText statusString)
 		{
-			this.status = new DerInteger(status);
-			this.statusString = statusString;
-		}
+			m_status = new DerInteger(status);
+			m_statusString = statusString;
+            m_failInfo = null;
+        }
 
         public PkiStatusInfo(int status, PkiFreeText statusString, PkiFailureInfo failInfo)
         {
-            this.status = new DerInteger(status);
-			this.statusString = statusString;
-			this.failInfo = failInfo;
+            m_status = new DerInteger(status);
+			m_statusString = statusString;
+			m_failInfo = failInfo;
 		}
 
-		public BigInteger Status => status.Value;
+		public BigInteger Status => m_status.Value;
 
-		public PkiFreeText StatusString => statusString;
+		public PkiFreeText StatusString => m_statusString;
 
-		public DerBitString FailInfo => failInfo;
+		public DerBitString FailInfo => m_failInfo;
 
 		/**
 		 * <pre>
@@ -111,8 +116,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(status);
-            v.AddOptional(statusString, failInfo);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
+			v.Add(m_status);
+            v.AddOptional(m_statusString, m_failInfo);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/PbmParameter.cs b/crypto/src/asn1/cmp/PbmParameter.cs
index ae3fb5f8e..aeb91d7d0 100644
--- a/crypto/src/asn1/cmp/PbmParameter.cs
+++ b/crypto/src/asn1/cmp/PbmParameter.cs
@@ -1,6 +1,4 @@
-using System;
-
-using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.Asn1.X509;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
@@ -35,7 +33,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PbmParameter GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PbmParameter(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1OctetString m_salt;
@@ -93,9 +91,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
          * </pre>
          * @return a basic ASN.1 object representation.
          */
-        public override Asn1Object ToAsn1Object()
-        {
-            return new DerSequence(m_salt, m_owf, m_iterationCount, m_mac);
-        }
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_salt, m_owf, m_iterationCount, m_mac);
     }
 }
diff --git a/crypto/src/asn1/cmp/PollRepContent.cs b/crypto/src/asn1/cmp/PollRepContent.cs
index e8af7b7e9..e81ce3278 100644
--- a/crypto/src/asn1/cmp/PollRepContent.cs
+++ b/crypto/src/asn1/cmp/PollRepContent.cs
@@ -20,7 +20,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PollRepContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PollRepContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly DerInteger[] m_certReqID;
diff --git a/crypto/src/asn1/cmp/PollReqContent.cs b/crypto/src/asn1/cmp/PollReqContent.cs
index 31320416e..ab89d26ec 100644
--- a/crypto/src/asn1/cmp/PollReqContent.cs
+++ b/crypto/src/asn1/cmp/PollReqContent.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PollReqContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PollReqContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -85,10 +85,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-        public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+        public override Asn1Object ToAsn1Object() => m_content;
 
 		private static DerSequence[] IntsToSequence(DerInteger[] ids)
 		{
diff --git a/crypto/src/asn1/cmp/PopoDecKeyChallContent.cs b/crypto/src/asn1/cmp/PopoDecKeyChallContent.cs
index 20dadd232..56f88af3d 100644
--- a/crypto/src/asn1/cmp/PopoDecKeyChallContent.cs
+++ b/crypto/src/asn1/cmp/PopoDecKeyChallContent.cs
@@ -16,7 +16,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PopoDecKeyChallContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PopoDecKeyChallContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -26,10 +26,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 	        m_content = seq;
 	    }
 
-	    public virtual Challenge[] ToChallengeArray()
-	    {
-			return m_content.MapElements(Challenge.GetInstance);
-	    }
+	    public virtual Challenge[] ToChallengeArray() => m_content.MapElements(Challenge.GetInstance);
 
 	    /**
 	     * <pre>
@@ -37,9 +34,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 	     * </pre>
 	     * @return a basic ASN.1 object representation.
 	     */
-	    public override Asn1Object ToAsn1Object()
-	    {
-	        return m_content;
-	    }
+	    public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/PopoDecKeyRespContent.cs b/crypto/src/asn1/cmp/PopoDecKeyRespContent.cs
index 8344e4ae9..a77cc15cd 100644
--- a/crypto/src/asn1/cmp/PopoDecKeyRespContent.cs
+++ b/crypto/src/asn1/cmp/PopoDecKeyRespContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static PopoDecKeyRespContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new PopoDecKeyRespContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -24,10 +24,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			m_content = seq;
 		}
 
-		public virtual DerInteger[] ToIntegerArray()
-		{
-			return m_content.MapElements(DerInteger.GetInstance);
-		}
+		public virtual DerInteger[] ToIntegerArray() => m_content.MapElements(DerInteger.GetInstance);
 
 		/**
 		 * <pre>
@@ -35,9 +32,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+		public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/ProtectedPart.cs b/crypto/src/asn1/cmp/ProtectedPart.cs
index 863a85e17..e6b6311df 100644
--- a/crypto/src/asn1/cmp/ProtectedPart.cs
+++ b/crypto/src/asn1/cmp/ProtectedPart.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static ProtectedPart GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new ProtectedPart(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly PkiHeader m_header;
@@ -45,9 +45,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return new DerSequence(m_header, m_body);
-		}
+		public override Asn1Object ToAsn1Object() => new DerSequence(m_header, m_body);
 	}
 }
diff --git a/crypto/src/asn1/cmp/RevAnnContent.cs b/crypto/src/asn1/cmp/RevAnnContent.cs
index 1d3957759..5ac731fb8 100644
--- a/crypto/src/asn1/cmp/RevAnnContent.cs
+++ b/crypto/src/asn1/cmp/RevAnnContent.cs
@@ -3,7 +3,7 @@ using Org.BouncyCastle.Asn1.X509;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
-	public class RevAnnContent
+    public class RevAnnContent
 		: Asn1Encodable
 	{
         public static RevAnnContent GetInstance(object obj)
@@ -17,7 +17,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static RevAnnContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new RevAnnContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly PkiStatusEncodable m_status;
@@ -80,7 +80,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_status, m_certID, m_willBeRevokedAt, m_badSinceDate);
+			Asn1EncodableVector v = new Asn1EncodableVector(5);
+			v.Add(m_status, m_certID, m_willBeRevokedAt, m_badSinceDate);
 			v.AddOptional(m_crlDetails);
 			return new DerSequence(v);
 		}
diff --git a/crypto/src/asn1/cmp/RevDetails.cs b/crypto/src/asn1/cmp/RevDetails.cs
index 79b30044a..718a9ef71 100644
--- a/crypto/src/asn1/cmp/RevDetails.cs
+++ b/crypto/src/asn1/cmp/RevDetails.cs
@@ -29,7 +29,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static RevDetails GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new RevDetails(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CertTemplate m_certDetails;
@@ -75,7 +75,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		*/
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_certDetails);
+            Asn1EncodableVector v = new Asn1EncodableVector(2);
+            v.Add(m_certDetails);
 			v.AddOptional(m_crlEntryDetails);
 			return new DerSequence(v);
 		}
diff --git a/crypto/src/asn1/cmp/RevRepContent.cs b/crypto/src/asn1/cmp/RevRepContent.cs
index 762df12cd..ae1d0baed 100644
--- a/crypto/src/asn1/cmp/RevRepContent.cs
+++ b/crypto/src/asn1/cmp/RevRepContent.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static RevRepContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new RevRepContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_status;
@@ -57,20 +57,11 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			}
 		}
 
-		public virtual PkiStatusInfo[] GetStatus()
-		{
-			return m_status.MapElements(PkiStatusInfo.GetInstance);
-		}
+		public virtual PkiStatusInfo[] GetStatus() => m_status.MapElements(PkiStatusInfo.GetInstance);
 
-		public virtual CertId[] GetRevCerts()
-		{
-			return m_revCerts?.MapElements(CertId.GetInstance);
-		}
+		public virtual CertId[] GetRevCerts() => m_revCerts?.MapElements(CertId.GetInstance);
 
-		public virtual CertificateList[] GetCrls()
-		{
-			return m_crls?.MapElements(CertificateList.GetInstance);
-		}
+		public virtual CertificateList[] GetCrls() => m_crls?.MapElements(CertificateList.GetInstance);
 
 		/**
 		 * <pre>
@@ -88,7 +79,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(m_status);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
+			v.Add(m_status);
             v.AddOptionalTagged(true, 0, m_revCerts);
             v.AddOptionalTagged(true, 1, m_crls);
 			return new DerSequence(v);
diff --git a/crypto/src/asn1/cmp/RevRepContentBuilder.cs b/crypto/src/asn1/cmp/RevRepContentBuilder.cs
index 4ff85483e..2aa127dd3 100644
--- a/crypto/src/asn1/cmp/RevRepContentBuilder.cs
+++ b/crypto/src/asn1/cmp/RevRepContentBuilder.cs
@@ -5,7 +5,7 @@ using Org.BouncyCastle.Asn1.X509;
 
 namespace Org.BouncyCastle.Asn1.Cmp
 {
-	public class RevRepContentBuilder
+    public class RevRepContentBuilder
 	{
 		private readonly Asn1EncodableVector m_status = new Asn1EncodableVector();
 		private readonly Asn1EncodableVector m_revCerts = new Asn1EncodableVector();
diff --git a/crypto/src/asn1/cmp/RevReqContent.cs b/crypto/src/asn1/cmp/RevReqContent.cs
index eea65869e..125fd8bdc 100644
--- a/crypto/src/asn1/cmp/RevReqContent.cs
+++ b/crypto/src/asn1/cmp/RevReqContent.cs
@@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static RevReqContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new RevReqContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly Asn1Sequence m_content;
@@ -34,10 +34,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			m_content = new DerSequence(revDetailsArray);
 		}
 
-		public virtual RevDetails[] ToRevDetailsArray()
-		{
-			return m_content.MapElements(RevDetails.GetInstance);
-		}
+		public virtual RevDetails[] ToRevDetailsArray() => m_content.MapElements(RevDetails.GetInstance);
 
 		/**
 		 * <pre>
@@ -45,9 +42,6 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		 * </pre>
 		 * @return a basic ASN.1 object representation.
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return m_content;
-		}
+		public override Asn1Object ToAsn1Object() => m_content;
 	}
 }
diff --git a/crypto/src/asn1/cmp/RootCaKeyUpdateContent.cs b/crypto/src/asn1/cmp/RootCaKeyUpdateContent.cs
index 64da80d6c..f00090f23 100644
--- a/crypto/src/asn1/cmp/RootCaKeyUpdateContent.cs
+++ b/crypto/src/asn1/cmp/RootCaKeyUpdateContent.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public static RootCaKeyUpdateContent GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
         {
-            return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+            return new RootCaKeyUpdateContent(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
         private readonly CmpCertificate m_newWithNew;
@@ -40,10 +40,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public RootCaKeyUpdateContent(CmpCertificate newWithNew, CmpCertificate newWithOld, CmpCertificate oldWithNew)
         {
-            if (newWithNew == null)
-                throw new ArgumentNullException(nameof(newWithNew));
-
-            m_newWithNew = newWithNew;
+            m_newWithNew = newWithNew ?? throw new ArgumentNullException(nameof(newWithNew));
             m_newWithOld = newWithOld;
             m_oldWithNew = oldWithNew;
         }
@@ -84,7 +81,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(m_newWithNew);
+            Asn1EncodableVector v = new Asn1EncodableVector(3);
+            v.Add(m_newWithNew);
             v.AddOptionalTagged(true, 0, m_newWithOld);
             v.AddOptionalTagged(true, 1, m_oldWithNew);
             return new DerSequence(v);