summary refs log tree commit diff
path: root/crypto/src/asn1/cms/OriginatorInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms/OriginatorInfo.cs')
-rw-r--r--crypto/src/asn1/cms/OriginatorInfo.cs65
1 files changed, 19 insertions, 46 deletions
diff --git a/crypto/src/asn1/cms/OriginatorInfo.cs b/crypto/src/asn1/cms/OriginatorInfo.cs
index 48b771bcb..74569cbec 100644
--- a/crypto/src/asn1/cms/OriginatorInfo.cs
+++ b/crypto/src/asn1/cms/OriginatorInfo.cs
@@ -1,7 +1,5 @@
 using System;
 
-using Org.BouncyCastle.Utilities;
-
 namespace Org.BouncyCastle.Asn1.Cms
 {
     public class OriginatorInfo
@@ -25,57 +23,32 @@ namespace Org.BouncyCastle.Asn1.Cms
 #pragma warning restore CS0618 // Type or member is obsolete
         }
 
-        private Asn1Set certs;
-        private Asn1Set crls;
+        private readonly Asn1Set m_certs;
+        private readonly Asn1Set m_crls;
 
-        public OriginatorInfo(
-            Asn1Set certs,
-            Asn1Set crls)
+        public OriginatorInfo(Asn1Set certs, Asn1Set crls)
         {
-            this.certs = certs;
-            this.crls = crls;
+            m_certs = certs;
+            m_crls = crls;
         }
 
         [Obsolete("Use 'GetInstance' instead")]
-        public OriginatorInfo(
-            Asn1Sequence seq)
+        public OriginatorInfo(Asn1Sequence seq)
         {
-            switch (seq.Count)
-            {
-            case 0:     // empty
-                break;
-            case 1:
-                Asn1TaggedObject o = (Asn1TaggedObject) seq[0];
-                switch (o.TagNo)
-                {
-                case 0 :
-                    certs = Asn1Set.GetInstance(o, false);
-                    break;
-                case 1 :
-                    crls = Asn1Set.GetInstance(o, false);
-                    break;
-                default:
-                    throw new ArgumentException("Bad tag in OriginatorInfo: " + o.TagNo);
-                }
-                break;
-            case 2:
-                certs = Asn1Set.GetInstance((Asn1TaggedObject) seq[0], false);
-                crls  = Asn1Set.GetInstance((Asn1TaggedObject) seq[1], false);
-                break;
-            default:
-                throw new ArgumentException("OriginatorInfo too big");
-            }
+            int count = seq.Count, pos = 0;
+            if (count < 0 || count > 2)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
+
+            m_certs = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, Asn1Set.GetInstance);
+            m_crls = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, false, Asn1Set.GetInstance);
+
+            if (pos != count)
+                throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
         }
 
-        public Asn1Set Certificates
-		{
-			get { return certs; }
-		}
+        public Asn1Set Certificates => m_certs;
 
-		public Asn1Set Crls
-		{
-			get { return crls; }
-		}
+        public Asn1Set Crls => m_crls;
 
 		/**
          * Produce an object suitable for an Asn1OutputStream.
@@ -89,8 +62,8 @@ namespace Org.BouncyCastle.Asn1.Cms
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(2);
-            v.AddOptionalTagged(false, 0, certs);
-            v.AddOptionalTagged(false, 1, crls);
+            v.AddOptionalTagged(false, 0, m_certs);
+            v.AddOptionalTagged(false, 1, m_crls);
 			return new DerSequence(v);
         }
     }