summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/BerSequence.cs33
-rw-r--r--crypto/src/asn1/DLSequence.cs29
-rw-r--r--crypto/src/asn1/DerSequence.cs29
-rw-r--r--crypto/src/asn1/cmp/PKIHeaderBuilder.cs11
-rw-r--r--crypto/src/asn1/cmp/PKIMessage.cs2
-rw-r--r--crypto/src/asn1/esf/CertificateValues.cs3
-rw-r--r--crypto/src/asn1/esf/CompleteCertificateRefs.cs3
-rw-r--r--crypto/src/asn1/esf/CompleteRevocationRefs.cs3
-rw-r--r--crypto/src/asn1/esf/CrlListID.cs3
-rw-r--r--crypto/src/asn1/esf/OcspListID.cs3
-rw-r--r--crypto/src/asn1/esf/OtherSigningCertificate.cs9
-rw-r--r--crypto/src/asn1/esf/RevocationValues.cs12
-rw-r--r--crypto/src/asn1/esf/SignaturePolicyId.cs6
-rw-r--r--crypto/src/asn1/ess/SigningCertificateV2.cs2
-rw-r--r--crypto/src/asn1/isismtt/x509/ProfessionInfo.cs2
-rw-r--r--crypto/src/asn1/tsp/ArchiveTimeStampChain.cs2
-rw-r--r--crypto/src/asn1/tsp/ArchiveTimeStampSequence.cs2
17 files changed, 89 insertions, 65 deletions
diff --git a/crypto/src/asn1/BerSequence.cs b/crypto/src/asn1/BerSequence.cs
index 93c92ab91..94499819a 100644
--- a/crypto/src/asn1/BerSequence.cs
+++ b/crypto/src/asn1/BerSequence.cs
@@ -19,13 +19,24 @@ namespace Org.BouncyCastle.Asn1
             case 1:
                 return FromSequence(sequences[0]);
             default:
-                return FromElements(ConcatenateElements(sequences));
+                return WithElements(ConcatenateElements(sequences));
             }
         }
 
-        internal static new BerSequence FromElements(Asn1Encodable[] elements)
+        public static new BerSequence FromElements(Asn1Encodable[] elements)
         {
-            return elements.Length < 1 ? Empty : new BerSequence(elements, clone: false);
+            if (elements == null)
+                throw new ArgumentNullException(nameof(elements));
+
+            return elements.Length < 1 ? Empty : new BerSequence(elements);
+        }
+
+        public static new BerSequence FromElementsOptional(Asn1Encodable[] elements)
+        {
+            if (elements == null)
+                return null;
+
+            return elements.Length < 1 ? Empty : new BerSequence(elements);
         }
 
         public static new BerSequence FromSequence(Asn1Sequence sequence)
@@ -33,7 +44,7 @@ namespace Org.BouncyCastle.Asn1
             if (sequence is BerSequence berSequence)
                 return berSequence;
 
-            return FromElements(sequence.m_elements);
+            return WithElements(sequence.m_elements);
         }
 
 		public static new BerSequence FromVector(Asn1EncodableVector elementVector)
@@ -41,10 +52,20 @@ namespace Org.BouncyCastle.Asn1
             return elementVector.Count < 1 ? Empty : new BerSequence(elementVector);
 		}
 
-		/**
+        public static new BerSequence Map(Asn1Sequence sequence, Func<Asn1Encodable, Asn1Encodable> func)
+        {
+            return sequence.Count < 1 ? Empty : new BerSequence(sequence.MapElements(func), clone: false);
+        }
+
+        internal static new BerSequence WithElements(Asn1Encodable[] elements)
+        {
+            return elements.Length < 1 ? Empty : new BerSequence(elements, clone: false);
+        }
+
+        /**
 		 * create an empty sequence
 		 */
-		public BerSequence()
+        public BerSequence()
             : base()
 		{
 		}
diff --git a/crypto/src/asn1/DLSequence.cs b/crypto/src/asn1/DLSequence.cs
index 05b634f57..0c2431db1 100644
--- a/crypto/src/asn1/DLSequence.cs
+++ b/crypto/src/asn1/DLSequence.cs
@@ -19,13 +19,24 @@ namespace Org.BouncyCastle.Asn1
             case 1:
                 return FromSequence(sequences[0]);
             default:
-                return FromElements(ConcatenateElements(sequences));
+                return WithElements(ConcatenateElements(sequences));
             }
         }
 
-        internal static new DLSequence FromElements(Asn1Encodable[] elements)
+        public static new DLSequence FromElements(Asn1Encodable[] elements)
         {
-            return elements.Length < 1 ? Empty : new DLSequence(elements, clone: false);
+            if (elements == null)
+                throw new ArgumentNullException(nameof(elements));
+
+            return elements.Length < 1 ? Empty : new DLSequence(elements);
+        }
+
+        public static new DLSequence FromElementsOptional(Asn1Encodable[] elements)
+        {
+            if (elements == null)
+                return null;
+
+            return elements.Length < 1 ? Empty : new DLSequence(elements);
         }
 
         public static new DLSequence FromSequence(Asn1Sequence sequence)
@@ -33,7 +44,7 @@ namespace Org.BouncyCastle.Asn1
             if (sequence is DLSequence dlSequence)
                 return dlSequence;
 
-            return FromElements(sequence.m_elements);
+            return WithElements(sequence.m_elements);
         }
 
         public static new DLSequence FromVector(Asn1EncodableVector elementVector)
@@ -41,6 +52,16 @@ namespace Org.BouncyCastle.Asn1
             return elementVector.Count < 1 ? Empty : new DLSequence(elementVector);
         }
 
+        public static new DLSequence Map(Asn1Sequence sequence, Func<Asn1Encodable, Asn1Encodable> func)
+        {
+            return sequence.Count < 1 ? Empty : new DLSequence(sequence.MapElements(func), clone: false);
+        }
+
+        internal static new DLSequence WithElements(Asn1Encodable[] elements)
+        {
+            return elements.Length < 1 ? Empty : new DLSequence(elements, clone: false);
+        }
+
         /**
 		 * create an empty sequence
 		 */
diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs
index 4a4aee434..a6ecb3ffa 100644
--- a/crypto/src/asn1/DerSequence.cs
+++ b/crypto/src/asn1/DerSequence.cs
@@ -19,13 +19,24 @@ namespace Org.BouncyCastle.Asn1
             case 1:
                 return FromSequence(sequences[0]);
             default:
-                return FromElements(ConcatenateElements(sequences));
+                return WithElements(ConcatenateElements(sequences));
             }
         }
 
-        internal static DerSequence FromElements(Asn1Encodable[] elements)
+        public static DerSequence FromElements(Asn1Encodable[] elements)
         {
-            return elements.Length < 1 ? Empty : new DerSequence(elements, clone: false);
+            if (elements == null)
+                throw new ArgumentNullException(nameof(elements));
+
+            return elements.Length < 1 ? Empty : new DerSequence(elements);
+        }
+
+        public static DerSequence FromElementsOptional(Asn1Encodable[] elements)
+        {
+            if (elements == null)
+                return null;
+
+            return elements.Length < 1 ? Empty : new DerSequence(elements);
         }
 
         public static DerSequence FromSequence(Asn1Sequence sequence)
@@ -33,7 +44,7 @@ namespace Org.BouncyCastle.Asn1
             if (sequence is DerSequence derSequence)
                 return derSequence;
 
-            return FromElements(sequence.m_elements);
+            return WithElements(sequence.m_elements);
         }
 
 		public static DerSequence FromVector(Asn1EncodableVector elementVector)
@@ -41,6 +52,16 @@ namespace Org.BouncyCastle.Asn1
             return elementVector.Count < 1 ? Empty : new DerSequence(elementVector);
 		}
 
+        public static DerSequence Map(Asn1Sequence sequence, Func<Asn1Encodable, Asn1Encodable> func)
+        {
+            return sequence.Count < 1 ? Empty : new DerSequence(sequence.MapElements(func), clone: false);
+        }
+
+        internal static DerSequence WithElements(Asn1Encodable[] elements)
+        {
+            return elements.Length < 1 ? Empty : new DerSequence(elements, clone: false);
+        }
+
         /**
 		 * create an empty sequence
 		 */
diff --git a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
index 3426c8f0e..29f37f7d9 100644
--- a/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
+++ b/crypto/src/asn1/cmp/PKIHeaderBuilder.cs
@@ -120,15 +120,10 @@ namespace Org.BouncyCastle.Asn1.Cmp
 			return this;
 		}
 
-		private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue generalInfo)
-		{
-			return new DerSequence(generalInfo);
-		}
+		private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue generalInfo) => new DerSequence(generalInfo);
 
-		private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue[] generalInfos)
-		{
-			return generalInfos == null ? null : DerSequence.FromElements(generalInfos);
-		}
+		private static Asn1Sequence MakeGeneralInfoSeq(InfoTypeAndValue[] generalInfos) =>
+			DerSequence.FromElementsOptional(generalInfos);
 
 		/**
 		 * <pre>
diff --git a/crypto/src/asn1/cmp/PKIMessage.cs b/crypto/src/asn1/cmp/PKIMessage.cs
index 7008a9e1c..a408fead5 100644
--- a/crypto/src/asn1/cmp/PKIMessage.cs
+++ b/crypto/src/asn1/cmp/PKIMessage.cs
@@ -52,7 +52,7 @@ namespace Org.BouncyCastle.Asn1.Cmp
             m_header = header ?? throw new ArgumentNullException(nameof(header));
             m_body = body ?? throw new ArgumentNullException(nameof(body));
             m_protection = protection;
-            m_extraCerts = extraCerts == null ? null : DerSequence.FromElements(extraCerts);
+            m_extraCerts = DerSequence.FromElementsOptional(extraCerts);
         }
 
         public PkiMessage(PkiHeader header, PkiBody body, DerBitString protection)
diff --git a/crypto/src/asn1/esf/CertificateValues.cs b/crypto/src/asn1/esf/CertificateValues.cs
index 384094511..2c0a4b444 100644
--- a/crypto/src/asn1/esf/CertificateValues.cs
+++ b/crypto/src/asn1/esf/CertificateValues.cs
@@ -38,9 +38,6 @@ namespace Org.BouncyCastle.Asn1.Esf
 
         public CertificateValues(params X509CertificateStructure[] certificates)
 		{
-			if (certificates == null)
-				throw new ArgumentNullException(nameof(certificates));
-
 			m_certificates = DerSequence.FromElements(certificates);
 		}
 
diff --git a/crypto/src/asn1/esf/CompleteCertificateRefs.cs b/crypto/src/asn1/esf/CompleteCertificateRefs.cs
index 4e8f122ca..637571ea3 100644
--- a/crypto/src/asn1/esf/CompleteCertificateRefs.cs
+++ b/crypto/src/asn1/esf/CompleteCertificateRefs.cs
@@ -36,9 +36,6 @@ namespace Org.BouncyCastle.Asn1.Esf
 
 		public CompleteCertificateRefs(params OtherCertID[] otherCertIDs)
 		{
-			if (otherCertIDs == null)
-				throw new ArgumentNullException(nameof(otherCertIDs));
-
 			m_otherCertIDs = DerSequence.FromElements(otherCertIDs);
 		}
 
diff --git a/crypto/src/asn1/esf/CompleteRevocationRefs.cs b/crypto/src/asn1/esf/CompleteRevocationRefs.cs
index 82ac6beab..aa3b7cc10 100644
--- a/crypto/src/asn1/esf/CompleteRevocationRefs.cs
+++ b/crypto/src/asn1/esf/CompleteRevocationRefs.cs
@@ -36,9 +36,6 @@ namespace Org.BouncyCastle.Asn1.Esf
 
 		public CompleteRevocationRefs(params CrlOcspRef[] crlOcspRefs)
 		{
-			if (crlOcspRefs == null)
-				throw new ArgumentNullException(nameof(crlOcspRefs));
-
 			m_crlOcspRefs = DerSequence.FromElements(crlOcspRefs);
 		}
 
diff --git a/crypto/src/asn1/esf/CrlListID.cs b/crypto/src/asn1/esf/CrlListID.cs
index f9ca95e24..6d05c3971 100644
--- a/crypto/src/asn1/esf/CrlListID.cs
+++ b/crypto/src/asn1/esf/CrlListID.cs
@@ -44,9 +44,6 @@ namespace Org.BouncyCastle.Asn1.Esf
 
 		public CrlListID(params CrlValidatedID[] crls)
 		{
-			if (crls == null)
-				throw new ArgumentNullException(nameof(crls));
-
 			m_crls = DerSequence.FromElements(crls);
 		}
 
diff --git a/crypto/src/asn1/esf/OcspListID.cs b/crypto/src/asn1/esf/OcspListID.cs
index a821e6b17..5784fffe0 100644
--- a/crypto/src/asn1/esf/OcspListID.cs
+++ b/crypto/src/asn1/esf/OcspListID.cs
@@ -43,9 +43,6 @@ namespace Org.BouncyCastle.Asn1.Esf
 
         public OcspListID(params OcspResponsesID[] ocspResponses)
 		{
-			if (ocspResponses == null)
-				throw new ArgumentNullException(nameof(ocspResponses));
-
 			m_ocspResponses = DerSequence.FromElements(ocspResponses);
 		}
 
diff --git a/crypto/src/asn1/esf/OtherSigningCertificate.cs b/crypto/src/asn1/esf/OtherSigningCertificate.cs
index 78fda76d1..f9333eb6c 100644
--- a/crypto/src/asn1/esf/OtherSigningCertificate.cs
+++ b/crypto/src/asn1/esf/OtherSigningCertificate.cs
@@ -54,15 +54,8 @@ namespace Org.BouncyCastle.Asn1.Esf
 
 		public OtherSigningCertificate(OtherCertID[] certs, params PolicyInformation[] policies)
 		{
-			if (certs == null)
-                throw new ArgumentNullException(nameof(certs));
-
             m_certs = DerSequence.FromElements(certs);
-
-			if (policies != null)
-			{
-				m_policies = DerSequence.FromElements(policies);
-			}
+            m_policies = DerSequence.FromElementsOptional(policies);
 		}
 
 		public OtherSigningCertificate(IEnumerable<OtherCertID> certs)
diff --git a/crypto/src/asn1/esf/RevocationValues.cs b/crypto/src/asn1/esf/RevocationValues.cs
index 2d9175275..78cc1af0d 100644
--- a/crypto/src/asn1/esf/RevocationValues.cs
+++ b/crypto/src/asn1/esf/RevocationValues.cs
@@ -59,16 +59,8 @@ namespace Org.BouncyCastle.Asn1.Esf
 
         public RevocationValues(CertificateList[] crlVals, BasicOcspResponse[] ocspVals, OtherRevVals otherRevVals)
 		{
-			if (crlVals != null)
-			{
-				m_crlVals = DerSequence.FromElements(crlVals);
-			}
-
-			if (ocspVals != null)
-			{
-				m_ocspVals = DerSequence.FromElements(ocspVals);
-			}
-
+            m_crlVals = DerSequence.FromElementsOptional(crlVals);
+            m_ocspVals = DerSequence.FromElementsOptional(ocspVals);
 			m_otherRevVals = otherRevVals;
 		}
 
diff --git a/crypto/src/asn1/esf/SignaturePolicyId.cs b/crypto/src/asn1/esf/SignaturePolicyId.cs
index 18ea1634a..8d1adc891 100644
--- a/crypto/src/asn1/esf/SignaturePolicyId.cs
+++ b/crypto/src/asn1/esf/SignaturePolicyId.cs
@@ -62,11 +62,7 @@ namespace Org.BouncyCastle.Asn1.Esf
 		{
 			m_sigPolicyIdentifier = sigPolicyIdentifier ?? throw new ArgumentNullException(nameof(sigPolicyIdentifier));
             m_sigPolicyHash = sigPolicyHash ?? throw new ArgumentNullException(nameof(sigPolicyHash));
-
-            if (sigPolicyQualifiers != null)
-			{
-				m_sigPolicyQualifiers = DerSequence.FromElements(sigPolicyQualifiers);
-			}
+            m_sigPolicyQualifiers = DerSequence.FromElementsOptional(sigPolicyQualifiers);
 		}
 
 		public SignaturePolicyId(DerObjectIdentifier sigPolicyIdentifier, OtherHashAlgAndValue sigPolicyHash,
diff --git a/crypto/src/asn1/ess/SigningCertificateV2.cs b/crypto/src/asn1/ess/SigningCertificateV2.cs
index c53a7c990..e2f873ed2 100644
--- a/crypto/src/asn1/ess/SigningCertificateV2.cs
+++ b/crypto/src/asn1/ess/SigningCertificateV2.cs
@@ -50,7 +50,7 @@ namespace Org.BouncyCastle.Asn1.Ess
         public SigningCertificateV2(EssCertIDv2[] certs, PolicyInformation[] policies)
         {
             m_certs = new DerSequence(certs);
-            m_policies = policies == null ? null : DerSequence.FromElements(policies);
+            m_policies = DerSequence.FromElementsOptional(policies);
         }
 
         public EssCertIDv2[] GetCerts() => m_certs.MapElements(EssCertIDv2.GetInstance);
diff --git a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
index c504b5d49..48daf1fdd 100644
--- a/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
+++ b/crypto/src/asn1/isismtt/x509/ProfessionInfo.cs
@@ -209,7 +209,7 @@ namespace Org.BouncyCastle.Asn1.IsisMtt.X509
         {
             m_namingAuthority = namingAuthority;
 			m_professionItems = DerSequence.FromElements(professionItems);
-			m_professionOids = professionOids == null ? null : DerSequence.FromElements(professionOids);
+			m_professionOids = DerSequence.FromElementsOptional(professionOids);
 			m_registrationNumber = registrationNumber == null ? null : new DerPrintableString(registrationNumber, true);
 			m_addProfessionInfo = addProfessionInfo;
 		}
diff --git a/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs b/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
index 91aa6426e..9ea2c83a1 100644
--- a/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
+++ b/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
@@ -39,7 +39,7 @@ namespace Org.BouncyCastle.Asn1.Tsp
 
         private ArchiveTimeStampChain(Asn1Sequence seq)
         {
-            m_archiveTimeStamps = DerSequence.FromElements(seq.MapElements(ArchiveTimeStamp.GetInstance));
+            m_archiveTimeStamps = DerSequence.Map(seq, ArchiveTimeStamp.GetInstance);
         }
 
         public ArchiveTimeStampChain(ArchiveTimeStamp archiveTimeStamp)
diff --git a/crypto/src/asn1/tsp/ArchiveTimeStampSequence.cs b/crypto/src/asn1/tsp/ArchiveTimeStampSequence.cs
index 3ddeed4dd..300768359 100644
--- a/crypto/src/asn1/tsp/ArchiveTimeStampSequence.cs
+++ b/crypto/src/asn1/tsp/ArchiveTimeStampSequence.cs
@@ -39,7 +39,7 @@ namespace Org.BouncyCastle.Asn1.Tsp
 
         private ArchiveTimeStampSequence(Asn1Sequence seq)
         {
-            m_archiveTimeStampChains = DerSequence.FromElements(seq.MapElements(ArchiveTimeStampChain.GetInstance));
+            m_archiveTimeStampChains = DerSequence.Map(seq, ArchiveTimeStampChain.GetInstance);
         }
 
         public ArchiveTimeStampSequence(ArchiveTimeStampChain archiveTimeStampChain)