summary refs log tree commit diff
path: root/crypto/src/asn1/cms/TimeStampAndCRL.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crypto/src/asn1/cms/TimeStampAndCRL.cs48
1 files changed, 28 insertions, 20 deletions
diff --git a/crypto/src/asn1/cms/TimeStampAndCRL.cs b/crypto/src/asn1/cms/TimeStampAndCRL.cs
index c0cd48905..a76ce7680 100644
--- a/crypto/src/asn1/cms/TimeStampAndCRL.cs
+++ b/crypto/src/asn1/cms/TimeStampAndCRL.cs
@@ -1,3 +1,7 @@
+using System;
+
+using Org.BouncyCastle.Asn1.X509;
+
 namespace Org.BouncyCastle.Asn1.Cms
 {
     public class TimeStampAndCrl
@@ -17,33 +21,37 @@ namespace Org.BouncyCastle.Asn1.Cms
             return new TimeStampAndCrl(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
-        private ContentInfo timeStamp;
-		private X509.CertificateList crl;
+        private readonly ContentInfo m_timeStamp;
+		private readonly CertificateList m_crl;
 
 		public TimeStampAndCrl(ContentInfo timeStamp)
+			: this(timeStamp, null)
 		{
-			this.timeStamp = timeStamp;
 		}
 
-		private TimeStampAndCrl(Asn1Sequence seq)
-		{
-			this.timeStamp = ContentInfo.GetInstance(seq[0]);
-			if (seq.Count == 2)
-			{
-				this.crl = X509.CertificateList.GetInstance(seq[1]);
-			}
-		}
+        public TimeStampAndCrl(ContentInfo timeStamp, CertificateList crl)
+        {
+            m_timeStamp = timeStamp ?? throw new ArgumentNullException(nameof(timeStamp));
+            m_crl = crl;
+        }
 
-		public virtual ContentInfo TimeStampToken
+        private TimeStampAndCrl(Asn1Sequence seq)
 		{
-			get { return this.timeStamp; }
-		}
+            int count = seq.Count, pos = 0;
+            if (count < 1 || count > 2)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
 
-		public virtual X509.CertificateList Crl
-		{
-			get { return this.crl; }
+            m_timeStamp = ContentInfo.GetInstance(seq[pos++]);
+            m_crl = Asn1Utilities.ReadOptional(seq, ref pos, CertificateList.GetOptional);
+
+            if (pos != count)
+                throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
 		}
 
+		public virtual ContentInfo TimeStampToken => m_timeStamp;
+
+		public virtual CertificateList Crl => m_crl;
+
 		/**
 		 * <pre>
 		 * TimeStampAndCRL ::= SEQUENCE {
@@ -55,9 +63,9 @@ namespace Org.BouncyCastle.Asn1.Cms
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(timeStamp);
-			v.AddOptional(crl);
-			return new DerSequence(v);
+			return m_crl == null
+				?  new DerSequence(m_timeStamp)
+                :  new DerSequence(m_timeStamp, m_crl);
 		}
 	}
 }