summary refs log tree commit diff
path: root/crypto/src/asn1/crmf/PopoSigningKey.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/crmf/PopoSigningKey.cs')
-rw-r--r--crypto/src/asn1/crmf/PopoSigningKey.cs90
1 files changed, 35 insertions, 55 deletions
diff --git a/crypto/src/asn1/crmf/PopoSigningKey.cs b/crypto/src/asn1/crmf/PopoSigningKey.cs
index 93e14e30d..2d30e1a67 100644
--- a/crypto/src/asn1/crmf/PopoSigningKey.cs
+++ b/crypto/src/asn1/crmf/PopoSigningKey.cs
@@ -1,49 +1,41 @@
-using System;
-
-using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
+using Org.BouncyCastle.Asn1.X509;
 
 namespace Org.BouncyCastle.Asn1.Crmf
 {
     public class PopoSigningKey
         : Asn1Encodable
     {
-        private readonly PopoSigningKeyInput poposkInput;
-        private readonly AlgorithmIdentifier algorithmIdentifier;
-        private readonly DerBitString signature;
-
-        private PopoSigningKey(Asn1Sequence seq)
+        public static PopoSigningKey GetInstance(object obj)
         {
-            int index = 0;
-
-            if (seq[index] is Asn1TaggedObject)
-            {
-                Asn1TaggedObject tagObj
-                    = (Asn1TaggedObject) seq[index++];
-                if (tagObj.TagNo != 0)
-                {
-                    throw new ArgumentException( "Unknown PopoSigningKeyInput tag: " + tagObj.TagNo, "seq");
-                }
-                poposkInput = PopoSigningKeyInput.GetInstance(tagObj.GetObject());
-            }
-            algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
-            signature = DerBitString.GetInstance(seq[index]);
+            if (obj == null)
+                return null;
+            if (obj is PopoSigningKey popoSigningKey)
+                return popoSigningKey;
+            return new PopoSigningKey(Asn1Sequence.GetInstance(obj));
         }
 
-        public static PopoSigningKey GetInstance(object obj)
+        public static PopoSigningKey GetInstance(Asn1TaggedObject obj, bool isExplicit)
         {
-            if (obj is PopoSigningKey)
-                return (PopoSigningKey)obj;
-
-            if (obj is Asn1Sequence)
-                return new PopoSigningKey((Asn1Sequence)obj);
-
-            throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
+            return new PopoSigningKey(Asn1Sequence.GetInstance(obj, isExplicit));
         }
 
-        public static PopoSigningKey GetInstance(Asn1TaggedObject obj, bool isExplicit)
+        private readonly PopoSigningKeyInput m_poposkInput;
+        private readonly AlgorithmIdentifier m_algorithmIdentifier;
+        private readonly DerBitString m_signature;
+
+        private PopoSigningKey(Asn1Sequence seq)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
+            int index = 0;
+
+            if (seq[index] is Asn1TaggedObject tagObj)
+            {
+                index++;
+
+                m_poposkInput = PopoSigningKeyInput.GetInstance(
+                    Asn1Utilities.GetContextBaseUniversal(tagObj, 0, false, Asn1Tags.Sequence));
+            }
+            m_algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
+            m_signature = DerBitString.GetInstance(seq[index]);
         }
 
         /**
@@ -54,30 +46,18 @@ namespace Org.BouncyCastle.Asn1.Crmf
          * @param signature a signature over the DER-encoded value of poposkIn,
          *     or the DER-encoded value of certReq if poposkIn is null.
          */
-        public PopoSigningKey(
-            PopoSigningKeyInput poposkIn,
-            AlgorithmIdentifier aid,
-            DerBitString signature)
+        public PopoSigningKey(PopoSigningKeyInput poposkIn, AlgorithmIdentifier aid, DerBitString signature)
         {
-            this.poposkInput = poposkIn;
-            this.algorithmIdentifier = aid;
-            this.signature = signature;
+            m_poposkInput = poposkIn;
+            m_algorithmIdentifier = aid;
+            m_signature = signature;
         }
 
-        public virtual PopoSigningKeyInput PoposkInput
-        {
-            get { return poposkInput; }
-        }
+        public virtual PopoSigningKeyInput PoposkInput => m_poposkInput;
 
-        public virtual AlgorithmIdentifier AlgorithmIdentifier
-        {
-            get { return algorithmIdentifier; }
-        }
+        public virtual AlgorithmIdentifier AlgorithmIdentifier => m_algorithmIdentifier;
 
-        public virtual DerBitString Signature
-        {
-            get { return signature; }
-        }
+        public virtual DerBitString Signature => m_signature;
 
         /**
          * <pre>
@@ -101,9 +81,9 @@ namespace Org.BouncyCastle.Asn1.Crmf
         public override Asn1Object ToAsn1Object()
         {
             Asn1EncodableVector v = new Asn1EncodableVector(3);
-            v.AddOptionalTagged(false, 0, poposkInput);
-            v.Add(algorithmIdentifier);
-            v.Add(signature);
+            v.AddOptionalTagged(false, 0, m_poposkInput);
+            v.Add(m_algorithmIdentifier);
+            v.Add(m_signature);
             return new DerSequence(v);
         }
     }