summary refs log tree commit diff
path: root/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-07-01 19:23:46 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-07-01 19:23:46 +0700
commit4e97fa1cbee0072938c5ea33ca51f4e3964f2998 (patch)
tree0aad9c9bc277429ee733c8383672cb7c6aed329a /crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
parentRefactoring in Asn1.Smime (diff)
downloadBouncyCastle.NET-ed25519-4e97fa1cbee0072938c5ea33ca51f4e3964f2998.tar.xz
Refactoring in Asn1.Tsp
Diffstat (limited to 'crypto/src/asn1/tsp/ArchiveTimeStampChain.cs')
-rw-r--r--crypto/src/asn1/tsp/ArchiveTimeStampChain.cs31
1 files changed, 14 insertions, 17 deletions
diff --git a/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs b/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
index 6d274cf58..91aa6426e 100644
--- a/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
+++ b/crypto/src/asn1/tsp/ArchiveTimeStampChain.cs
@@ -29,33 +29,27 @@ namespace Org.BouncyCastle.Asn1.Tsp
             return new ArchiveTimeStampChain(Asn1Sequence.GetInstance(obj));
         }
 
-        public static ArchiveTimeStampChain GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
-        {
-            return new ArchiveTimeStampChain(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
-        }
+        public static ArchiveTimeStampChain GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new ArchiveTimeStampChain(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+
+        public static ArchiveTimeStampChain GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
+            new ArchiveTimeStampChain(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
 
         private readonly Asn1Sequence m_archiveTimeStamps;
 
-        public ArchiveTimeStampChain(ArchiveTimeStamp archiveTimeStamp)
+        private ArchiveTimeStampChain(Asn1Sequence seq)
         {
-            m_archiveTimeStamps = new DerSequence(archiveTimeStamp);
+            m_archiveTimeStamps = DerSequence.FromElements(seq.MapElements(ArchiveTimeStamp.GetInstance));
         }
 
-        public ArchiveTimeStampChain(ArchiveTimeStamp[] archiveTimeStamps)
+        public ArchiveTimeStampChain(ArchiveTimeStamp archiveTimeStamp)
         {
-            m_archiveTimeStamps = new DerSequence(archiveTimeStamps);
+            m_archiveTimeStamps = new DerSequence(archiveTimeStamp);
         }
 
-        private ArchiveTimeStampChain(Asn1Sequence sequence)
+        public ArchiveTimeStampChain(ArchiveTimeStamp[] archiveTimeStamps)
         {
-            Asn1EncodableVector vector = new Asn1EncodableVector(sequence.Count);
-
-            foreach (var element in sequence)
-            {
-                vector.Add(ArchiveTimeStamp.GetInstance(element));
-            }
-
-            m_archiveTimeStamps = new DerSequence(vector);
+            m_archiveTimeStamps = DerSequence.FromElements(archiveTimeStamps);
         }
 
         public virtual ArchiveTimeStamp[] GetArchiveTimestamps() =>
@@ -69,6 +63,9 @@ namespace Org.BouncyCastle.Asn1.Tsp
          */
         public virtual ArchiveTimeStampChain Append(ArchiveTimeStamp archiveTimeStamp)
         {
+            if (archiveTimeStamp == null)
+                throw new ArgumentNullException(nameof(archiveTimeStamp));
+
             Asn1EncodableVector v = new Asn1EncodableVector(m_archiveTimeStamps.Count + 1);
 
             foreach (var element in m_archiveTimeStamps)