summary refs log tree commit diff
path: root/crypto/src/asn1/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 16:55:26 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-06-04 16:55:26 +0700
commit3eb93b423abeefbdc03f0ecc38751d76428ba23e (patch)
treef364f857c54f65eb59462560b1f282b896eecf8b /crypto/src/asn1/cms
parentPort LinkedCertificate from bc-java (diff)
downloadBouncyCastle.NET-ed25519-3eb93b423abeefbdc03f0ecc38751d76428ba23e.tar.xz
Refactoring
Diffstat (limited to 'crypto/src/asn1/cms')
-rw-r--r--crypto/src/asn1/cms/AuthEnvelopedData.cs27
-rw-r--r--crypto/src/asn1/cms/AuthenticatedData.cs28
-rw-r--r--crypto/src/asn1/cms/EnvelopedData.cs14
-rw-r--r--crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs11
-rw-r--r--crypto/src/asn1/cms/OriginatorInfo.cs13
-rw-r--r--crypto/src/asn1/cms/PasswordRecipientInfo.cs8
-rw-r--r--crypto/src/asn1/cms/SCVPReqRes.cs8
-rw-r--r--crypto/src/asn1/cms/SignerInfo.cs17
-rw-r--r--crypto/src/asn1/cms/ecc/MQVuserKeyingMaterial.cs7
9 files changed, 24 insertions, 109 deletions
diff --git a/crypto/src/asn1/cms/AuthEnvelopedData.cs b/crypto/src/asn1/cms/AuthEnvelopedData.cs
index c30ec6bbd..6277e4b87 100644
--- a/crypto/src/asn1/cms/AuthEnvelopedData.cs
+++ b/crypto/src/asn1/cms/AuthEnvelopedData.cs
@@ -175,31 +175,20 @@ namespace Org.BouncyCastle.Asn1.Cms
 	    public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(version);
-
-			if (originatorInfo != null)
-			{
-				v.Add(new DerTaggedObject(false, 0, originatorInfo));
-			}
-
+            v.AddOptionalTagged(false, 0, originatorInfo);
 			v.Add(recipientInfos, authEncryptedContentInfo);
 
 			// "authAttrs optionally contains the authenticated attributes."
-			if (authAttrs != null)
-			{
-				// "AuthAttributes MUST be DER encoded, even if the rest of the
-				// AuthEnvelopedData structure is BER encoded."
-				v.Add(new DerTaggedObject(false, 1, authAttrs));
-			}
+            // "AuthAttributes MUST be DER encoded, even if the rest of the
+            // AuthEnvelopedData structure is BER encoded."
+            v.AddOptionalTagged(false, 1, authAttrs);
 
-			v.Add(mac);
+            v.Add(mac);
 
-			// "unauthAttrs optionally contains the unauthenticated attributes."
-			if (unauthAttrs != null)
-			{
-				v.Add(new DerTaggedObject(false, 2, unauthAttrs));
-			}
+            // "unauthAttrs optionally contains the unauthenticated attributes."
+            v.AddOptionalTagged(false, 2, unauthAttrs);
 
-			return new BerSequence(v);
+            return new BerSequence(v);
 		}
 	}
 }
diff --git a/crypto/src/asn1/cms/AuthenticatedData.cs b/crypto/src/asn1/cms/AuthenticatedData.cs
index 6f13a6f30..eb9f82031 100644
--- a/crypto/src/asn1/cms/AuthenticatedData.cs
+++ b/crypto/src/asn1/cms/AuthenticatedData.cs
@@ -196,33 +196,13 @@ namespace Org.BouncyCastle.Asn1.Cms
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(version);
-
-			if (originatorInfo != null)
-			{
-				v.Add(new DerTaggedObject(false, 0, originatorInfo));
-			}
-
+            v.AddOptionalTagged(false, 0, originatorInfo);
 			v.Add(recipientInfos, macAlgorithm);
-
-			if (digestAlgorithm != null)
-			{
-				v.Add(new DerTaggedObject(false, 1, digestAlgorithm));
-			}
-
+            v.AddOptionalTagged(false, 1, digestAlgorithm);
 			v.Add(encapsulatedContentInfo);
-
-			if (authAttrs != null)
-			{
-				v.Add(new DerTaggedObject(false, 2, authAttrs));
-			}
-
+            v.AddOptionalTagged(false, 2, authAttrs);
 			v.Add(mac);
-
-			if (unauthAttrs != null)
-			{
-				v.Add(new DerTaggedObject(false, 3, unauthAttrs));
-			}
-
+            v.AddOptionalTagged(false, 3, unauthAttrs);
 			return new BerSequence(v);
 		}
 
diff --git a/crypto/src/asn1/cms/EnvelopedData.cs b/crypto/src/asn1/cms/EnvelopedData.cs
index 09f291a93..41dae548f 100644
--- a/crypto/src/asn1/cms/EnvelopedData.cs
+++ b/crypto/src/asn1/cms/EnvelopedData.cs
@@ -137,19 +137,9 @@ namespace Org.BouncyCastle.Asn1.Cms
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(version);
-
-            if (originatorInfo != null)
-            {
-                v.Add(new DerTaggedObject(false, 0, originatorInfo));
-            }
-
+            v.AddOptionalTagged(false, 0, originatorInfo);
             v.Add(recipientInfos, encryptedContentInfo);
-
-            if (unprotectedAttrs != null)
-            {
-                v.Add(new DerTaggedObject(false, 1, unprotectedAttrs));
-            }
-
+            v.AddOptionalTagged(false, 1, unprotectedAttrs);
             return new BerSequence(v);
         }
 
diff --git a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
index 62a38925b..52eb7d4d3 100644
--- a/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
+++ b/crypto/src/asn1/cms/KeyAgreeRecipientInfo.cs
@@ -125,16 +125,9 @@ namespace Org.BouncyCastle.Asn1.Cms
          */
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(
-				version, new DerTaggedObject(true, 0, originator));
-
-			if (ukm != null)
-            {
-                v.Add(new DerTaggedObject(true, 1, ukm));
-            }
-
+            Asn1EncodableVector v = new Asn1EncodableVector(version, new DerTaggedObject(true, 0, originator));
+            v.AddOptionalTagged(true, 1, ukm);
 			v.Add(keyEncryptionAlgorithm, recipientEncryptedKeys);
-
 			return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cms/OriginatorInfo.cs b/crypto/src/asn1/cms/OriginatorInfo.cs
index 33b049efa..23acc2d9f 100644
--- a/crypto/src/asn1/cms/OriginatorInfo.cs
+++ b/crypto/src/asn1/cms/OriginatorInfo.cs
@@ -104,17 +104,8 @@ namespace Org.BouncyCastle.Asn1.Cms
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
-
-			if (certs != null)
-            {
-                v.Add(new DerTaggedObject(false, 0, certs));
-            }
-
-			if (crls != null)
-            {
-                v.Add(new DerTaggedObject(false, 1, crls));
-            }
-
+            v.AddOptionalTagged(false, 0, certs);
+            v.AddOptionalTagged(false, 1, crls);
 			return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cms/PasswordRecipientInfo.cs b/crypto/src/asn1/cms/PasswordRecipientInfo.cs
index 7f275fde7..596dd9537 100644
--- a/crypto/src/asn1/cms/PasswordRecipientInfo.cs
+++ b/crypto/src/asn1/cms/PasswordRecipientInfo.cs
@@ -119,14 +119,8 @@ namespace Org.BouncyCastle.Asn1.Cms
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(version);
-
-			if (keyDerivationAlgorithm != null)
-            {
-                v.Add(new DerTaggedObject(false, 0, keyDerivationAlgorithm));
-            }
-
+            v.AddOptionalTagged(false, 0, keyDerivationAlgorithm);
 			v.Add(keyEncryptionAlgorithm, encryptedKey);
-
 			return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cms/SCVPReqRes.cs b/crypto/src/asn1/cms/SCVPReqRes.cs
index 486979a29..a6ebf7302 100644
--- a/crypto/src/asn1/cms/SCVPReqRes.cs
+++ b/crypto/src/asn1/cms/SCVPReqRes.cs
@@ -63,14 +63,8 @@ namespace Org.BouncyCastle.Asn1.Cms
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector();
-
-            if (request != null)
-            {
-                v.Add(new DerTaggedObject(true, 0, request));
-            }
-
+            v.AddOptionalTagged(true, 0, request);
             v.Add(response);
-
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cms/SignerInfo.cs b/crypto/src/asn1/cms/SignerInfo.cs
index b6bd319b0..44d4dcfb2 100644
--- a/crypto/src/asn1/cms/SignerInfo.cs
+++ b/crypto/src/asn1/cms/SignerInfo.cs
@@ -164,21 +164,10 @@ namespace Org.BouncyCastle.Asn1.Cms
          */
         public override Asn1Object ToAsn1Object()
         {
-            Asn1EncodableVector v = new Asn1EncodableVector(
-                version, sid, digAlgorithm);
-
-            if (authenticatedAttributes != null)
-            {
-                v.Add(new DerTaggedObject(false, 0, authenticatedAttributes));
-            }
-
+            Asn1EncodableVector v = new Asn1EncodableVector(version, sid, digAlgorithm);
+            v.AddOptionalTagged(false, 0, authenticatedAttributes);
             v.Add(digEncryptionAlgorithm, encryptedDigest);
-
-            if (unauthenticatedAttributes != null)
-            {
-                v.Add(new DerTaggedObject(false, 1, unauthenticatedAttributes));
-            }
-
+            v.AddOptionalTagged(false, 1, unauthenticatedAttributes);
             return new DerSequence(v);
         }
     }
diff --git a/crypto/src/asn1/cms/ecc/MQVuserKeyingMaterial.cs b/crypto/src/asn1/cms/ecc/MQVuserKeyingMaterial.cs
index dc4ac1a4a..3a4761e78 100644
--- a/crypto/src/asn1/cms/ecc/MQVuserKeyingMaterial.cs
+++ b/crypto/src/asn1/cms/ecc/MQVuserKeyingMaterial.cs
@@ -93,12 +93,7 @@ namespace Org.BouncyCastle.Asn1.Cms.Ecc
 		public override Asn1Object ToAsn1Object()
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(ephemeralPublicKey);
-
-			if (addedukm != null)
-			{
-				v.Add(new DerTaggedObject(true, 0, addedukm));
-			}
-
+            v.AddOptionalTagged(true, 0, addedukm);
 			return new DerSequence(v);
 		}
 	}