summary refs log tree commit diff
path: root/crypto/src/asn1/cms/TimeStampTokenEvidence.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-06-18 16:12:06 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-06-18 16:12:06 +0700
commit740c25a020c7539c99e82dd4531492c5b6bbd787 (patch)
tree998874b3c9d7b80636919b44de639218c9622f29 /crypto/src/asn1/cms/TimeStampTokenEvidence.cs
parentDerInteger constants for small values (diff)
downloadBouncyCastle.NET-ed25519-740c25a020c7539c99e82dd4531492c5b6bbd787.tar.xz
Refactoring in Asn1.Cms
Diffstat (limited to 'crypto/src/asn1/cms/TimeStampTokenEvidence.cs')
-rw-r--r--crypto/src/asn1/cms/TimeStampTokenEvidence.cs32
1 files changed, 13 insertions, 19 deletions
diff --git a/crypto/src/asn1/cms/TimeStampTokenEvidence.cs b/crypto/src/asn1/cms/TimeStampTokenEvidence.cs
index 6ac1eb11d..f7c5298a7 100644
--- a/crypto/src/asn1/cms/TimeStampTokenEvidence.cs
+++ b/crypto/src/asn1/cms/TimeStampTokenEvidence.cs
@@ -1,3 +1,7 @@
+using System;
+
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Asn1.Cms
 {
     public class TimeStampTokenEvidence
@@ -17,34 +21,27 @@ namespace Org.BouncyCastle.Asn1.Cms
             return new TimeStampTokenEvidence(Asn1Sequence.GetInstance(tagged, isExplicit));
         }
 
-        private TimeStampAndCrl[] timeStampAndCrls;
+        private readonly TimeStampAndCrl[] m_timeStampAndCrls;
 
 		public TimeStampTokenEvidence(TimeStampAndCrl[] timeStampAndCrls)
 		{
-			this.timeStampAndCrls = timeStampAndCrls;
+			if (Arrays.IsNullOrContainsNull(timeStampAndCrls))
+                throw new NullReferenceException("'timeStampAndCrls' cannot be null, or contain null");
+
+            m_timeStampAndCrls = timeStampAndCrls;
 		}
 
 		public TimeStampTokenEvidence(TimeStampAndCrl timeStampAndCrl)
 		{
-			this.timeStampAndCrls = new TimeStampAndCrl[]{ timeStampAndCrl };
+			m_timeStampAndCrls = new []{ timeStampAndCrl ?? throw new ArgumentNullException(nameof(timeStampAndCrl)) };
 		}
 
 		private TimeStampTokenEvidence(Asn1Sequence seq)
 		{
-			this.timeStampAndCrls = new TimeStampAndCrl[seq.Count];
-
-			int count = 0;
-
-			foreach (Asn1Encodable ae in seq)
-			{
-				this.timeStampAndCrls[count++] = TimeStampAndCrl.GetInstance(ae.ToAsn1Object());
-			}
+			m_timeStampAndCrls = seq.MapElements(TimeStampAndCrl.GetInstance);
 		}
 
-        public virtual TimeStampAndCrl[] ToTimeStampAndCrlArray()
-		{
-			return (TimeStampAndCrl[])timeStampAndCrls.Clone();
-		}
+        public virtual TimeStampAndCrl[] ToTimeStampAndCrlArray() => (TimeStampAndCrl[])m_timeStampAndCrls.Clone();
 
 		/**
 		 * <pre>
@@ -53,9 +50,6 @@ namespace Org.BouncyCastle.Asn1.Cms
 		 * </pre>
 		 * @return
 		 */
-		public override Asn1Object ToAsn1Object()
-		{
-			return new DerSequence(timeStampAndCrls);
-		}
+		public override Asn1Object ToAsn1Object() => new DerSequence(m_timeStampAndCrls);
 	}
 }