summary refs log tree commit diff
path: root/crypto/src/asn1/cmp
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cmp')
-rw-r--r--crypto/src/asn1/cmp/CertRepMessage.cs8
-rw-r--r--crypto/src/asn1/cmp/CertifiedKeyPair.cs13
-rw-r--r--crypto/src/asn1/cmp/Challenge.cs3
-rw-r--r--crypto/src/asn1/cmp/InfoTypeAndValue.cs7
-rw-r--r--crypto/src/asn1/cmp/KeyRecRepContent.cs14
-rw-r--r--crypto/src/asn1/cmp/OobCertHash.cs13
-rw-r--r--crypto/src/asn1/cmp/PKIHeader.cs28
-rw-r--r--crypto/src/asn1/cmp/PKIMessage.cs14
-rw-r--r--crypto/src/asn1/cmp/PKIStatusInfo.cs12
-rw-r--r--crypto/src/asn1/cmp/RevRepContent.cs13
10 files changed, 24 insertions, 101 deletions
diff --git a/crypto/src/asn1/cmp/CertRepMessage.cs b/crypto/src/asn1/cmp/CertRepMessage.cs
index 82869784d..d24dd963b 100644
--- a/crypto/src/asn1/cmp/CertRepMessage.cs
+++ b/crypto/src/asn1/cmp/CertRepMessage.cs
@@ -82,14 +82,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
-
-			if (caPubs != null)
-			{
-				v.Add(new DerTaggedObject(true, 1, caPubs));
-			}
-
+            v.AddOptionalTagged(true, 1, caPubs);
 			v.Add(response);
-
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/CertifiedKeyPair.cs b/crypto/src/asn1/cmp/CertifiedKeyPair.cs
index c06f00019..0b1c5d44d 100644
--- a/crypto/src/asn1/cmp/CertifiedKeyPair.cs
+++ b/crypto/src/asn1/cmp/CertifiedKeyPair.cs
@@ -98,17 +98,8 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(certOrEncCert);
-
-			if (privateKey != null)
-			{
-				v.Add(new DerTaggedObject(true, 0, privateKey));
-			}
-
-			if (publicationInfo != null)
-			{
-				v.Add(new DerTaggedObject(true, 1, publicationInfo));
-			}
-
+            v.AddOptionalTagged(true, 0, privateKey);
+            v.AddOptionalTagged(true, 1, publicationInfo);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/Challenge.cs b/crypto/src/asn1/cmp/Challenge.cs
index 5c78c2a2b..016c082e2 100644
--- a/crypto/src/asn1/cmp/Challenge.cs
+++ b/crypto/src/asn1/cmp/Challenge.cs
@@ -72,8 +72,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
 			v.AddOptional(owf);
-			v.Add(witness);
-			v.Add(challenge);
+			v.Add(witness, challenge);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/InfoTypeAndValue.cs b/crypto/src/asn1/cmp/InfoTypeAndValue.cs
index 0ce6f73ba..305d6e5e7 100644
--- a/crypto/src/asn1/cmp/InfoTypeAndValue.cs
+++ b/crypto/src/asn1/cmp/InfoTypeAndValue.cs
@@ -111,12 +111,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(infoType);
-
-            if (infoValue != null)
-            {
-                v.Add(infoValue);
-            }
-
+            v.AddOptional(infoValue);
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cmp/KeyRecRepContent.cs b/crypto/src/asn1/cmp/KeyRecRepContent.cs
index 00c4612b9..e35c0e351 100644
--- a/crypto/src/asn1/cmp/KeyRecRepContent.cs
+++ b/crypto/src/asn1/cmp/KeyRecRepContent.cs
@@ -100,18 +100,10 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(status);
-			AddOptional(v, 0, newSigCert);
-			AddOptional(v, 1, caCerts);
-			AddOptional(v, 2, keyPairHist);
+            v.AddOptionalTagged(true, 0, newSigCert);
+            v.AddOptionalTagged(true, 1, caCerts);
+            v.AddOptionalTagged(true, 2, keyPairHist);
 			return new DerSequence(v);
 		}
-
-		private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
-		{
-			if (obj != null)
-			{
-				v.Add(new DerTaggedObject(true, tagNo, obj));
-			}
-		}
 	}
 }
diff --git a/crypto/src/asn1/cmp/OobCertHash.cs b/crypto/src/asn1/cmp/OobCertHash.cs
index cd8192b40..434939c0e 100644
--- a/crypto/src/asn1/cmp/OobCertHash.cs
+++ b/crypto/src/asn1/cmp/OobCertHash.cs
@@ -70,19 +70,10 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector();
-			AddOptional(v, 0, hashAlg);
-			AddOptional(v, 1, certId);
+            v.AddOptionalTagged(true, 0, hashAlg);
+            v.AddOptionalTagged(true, 1, certId);
 			v.Add(hashVal);
 			return new DerSequence(v);
 		}
-
-		private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
-		{
-			if (obj != null)
-			{
-				v.Add(new DerTaggedObject(true, tagNo, obj));
-			}
-		}
 	}
 }
-
diff --git a/crypto/src/asn1/cmp/PKIHeader.cs b/crypto/src/asn1/cmp/PKIHeader.cs
index 577cb45df..7b6296279 100644
--- a/crypto/src/asn1/cmp/PKIHeader.cs
+++ b/crypto/src/asn1/cmp/PKIHeader.cs
@@ -213,26 +213,16 @@ namespace Org.BouncyCastle.Asn1.Cmp
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(pvno, sender, recipient);
-
-            AddOptional(v, 0, messageTime);
-            AddOptional(v, 1, protectionAlg);
-            AddOptional(v, 2, senderKID);
-            AddOptional(v, 3, recipKID);
-            AddOptional(v, 4, transactionID);
-            AddOptional(v, 5, senderNonce);
-            AddOptional(v, 6, recipNonce);
-            AddOptional(v, 7, freeText);
-            AddOptional(v, 8, generalInfo);
-
+            v.AddOptionalTagged(true, 0, messageTime);
+            v.AddOptionalTagged(true, 1, protectionAlg);
+            v.AddOptionalTagged(true, 2, senderKID);
+            v.AddOptionalTagged(true, 3, recipKID);
+            v.AddOptionalTagged(true, 4, transactionID);
+            v.AddOptionalTagged(true, 5, senderNonce);
+            v.AddOptionalTagged(true, 6, recipNonce);
+            v.AddOptionalTagged(true, 7, freeText);
+            v.AddOptionalTagged(true, 8, generalInfo);
             return new DerSequence(v);
         }
-
-        private static void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
-        {
-            if (obj != null)
-            {
-                v.Add(new DerTaggedObject(true, tagNo, obj));
-            }
-        }
     }
 }
diff --git a/crypto/src/asn1/cmp/PKIMessage.cs b/crypto/src/asn1/cmp/PKIMessage.cs
index 086a2d938..c87bf2126 100644
--- a/crypto/src/asn1/cmp/PKIMessage.cs
+++ b/crypto/src/asn1/cmp/PKIMessage.cs
@@ -122,19 +122,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(header, body);
-
-            AddOptional(v, 0, protection);
-            AddOptional(v, 1, extraCerts);
-
+            v.AddOptionalTagged(true, 0, protection);
+            v.AddOptionalTagged(true, 1, extraCerts);
             return new DerSequence(v);
         }
-
-        private static void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
-        {
-            if (obj != null)
-            {
-                v.Add(new DerTaggedObject(true, tagNo, obj));
-            }
-        }
     }
 }
diff --git a/crypto/src/asn1/cmp/PKIStatusInfo.cs b/crypto/src/asn1/cmp/PKIStatusInfo.cs
index b19bf7459..c9f64bfde 100644
--- a/crypto/src/asn1/cmp/PKIStatusInfo.cs
+++ b/crypto/src/asn1/cmp/PKIStatusInfo.cs
@@ -149,17 +149,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(status);
-
-			if (statusString != null)
-			{
-				v.Add(statusString);
-			}
-
-			if (failInfo!= null)
-			{
-				v.Add(failInfo);
-			}
-
+            v.AddOptional(statusString, failInfo);
 			return new DerSequence(v);
 		}
 	}
diff --git a/crypto/src/asn1/cmp/RevRepContent.cs b/crypto/src/asn1/cmp/RevRepContent.cs
index 8e382a60d..4b3f82b96 100644
--- a/crypto/src/asn1/cmp/RevRepContent.cs
+++ b/crypto/src/asn1/cmp/RevRepContent.cs
@@ -96,18 +96,9 @@ namespace Org.BouncyCastle.Asn1.Cmp
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(status);
-			AddOptional(v, 0, revCerts);
-			AddOptional(v, 1, crls);
+            v.AddOptionalTagged(true, 0, revCerts);
+            v.AddOptionalTagged(true, 1, crls);
 			return new DerSequence(v);
 		}
-
-		private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
-		{
-			if (obj != null)
-			{
-				v.Add(new DerTaggedObject(true, tagNo, obj));
-			}
-		}
 	}
 }
-