summary refs log tree commit diff
path: root/crypto/src/asn1/crmf/PKMacValue.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/crmf/PKMacValue.cs')
-rw-r--r--crypto/src/asn1/crmf/PKMacValue.cs62
1 files changed, 22 insertions, 40 deletions
diff --git a/crypto/src/asn1/crmf/PKMacValue.cs b/crypto/src/asn1/crmf/PKMacValue.cs
index e104c08dd..67e5ce6cc 100644
--- a/crypto/src/asn1/crmf/PKMacValue.cs
+++ b/crypto/src/asn1/crmf/PKMacValue.cs
@@ -1,8 +1,5 @@
-using System;
-
-using Org.BouncyCastle.Asn1.Cmp;
+using Org.BouncyCastle.Asn1.Cmp;
 using Org.BouncyCastle.Asn1.X509;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Crmf
 {
@@ -12,29 +9,27 @@ namespace Org.BouncyCastle.Asn1.Crmf
     public class PKMacValue
         : Asn1Encodable
     {
-        private readonly AlgorithmIdentifier  algID;
-        private readonly DerBitString         macValue;
-
-        private PKMacValue(Asn1Sequence seq)
+        public static PKMacValue GetInstance(object obj)
         {
-            this.algID = AlgorithmIdentifier.GetInstance(seq[0]);
-            this.macValue = DerBitString.GetInstance(seq[1]);
+            if (obj == null)
+                return null;
+            if (obj is PKMacValue pkMacValue)
+                return pkMacValue;
+            return new PKMacValue(Asn1Sequence.GetInstance(obj));
         }
 
-        public static PKMacValue GetInstance(object obj)
+        public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit)
         {
-            if (obj is PKMacValue)
-                return (PKMacValue)obj;
-
-            if (obj is Asn1Sequence)
-                return new PKMacValue((Asn1Sequence)obj);
-
-            throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
+            return new PKMacValue(Asn1Sequence.GetInstance(obj, isExplicit));
         }
 
-        public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit)
+        private readonly AlgorithmIdentifier m_algID;
+        private readonly DerBitString m_macValue;
+
+        private PKMacValue(Asn1Sequence seq)
         {
-            return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
+            m_algID = AlgorithmIdentifier.GetInstance(seq[0]);
+            m_macValue = DerBitString.GetInstance(seq[1]);
         }
 
         /**
@@ -42,9 +37,7 @@ namespace Org.BouncyCastle.Asn1.Crmf
          * @param params parameters for password-based MAC
          * @param value MAC of the DER-encoded SubjectPublicKeyInfo
          */
-        public PKMacValue(
-            PbmParameter pbmParams,
-            DerBitString macValue)
+        public PKMacValue(PbmParameter pbmParams, DerBitString macValue)
             : this(new AlgorithmIdentifier(CmpObjectIdentifiers.passwordBasedMac, pbmParams), macValue)
         {
         }
@@ -54,23 +47,15 @@ namespace Org.BouncyCastle.Asn1.Crmf
          * @param aid CMPObjectIdentifiers.passwordBasedMAC, with PBMParameter
          * @param value MAC of the DER-encoded SubjectPublicKeyInfo
          */
-        public PKMacValue(
-            AlgorithmIdentifier algID,
-            DerBitString        macValue)
+        public PKMacValue(AlgorithmIdentifier algID, DerBitString macValue)
         {
-            this.algID = algID;
-            this.macValue = macValue;
+            m_algID = algID;
+            m_macValue = macValue;
         }
 
-        public virtual AlgorithmIdentifier AlgID
-        {
-            get { return algID; }
-        }
+        public virtual AlgorithmIdentifier AlgID => m_algID;
 
-        public virtual DerBitString MacValue
-        {
-            get { return macValue; }
-        }
+        public virtual DerBitString MacValue => m_macValue;
 
         /**
          * <pre>
@@ -82,9 +67,6 @@ namespace Org.BouncyCastle.Asn1.Crmf
          * </pre>
          * @return a basic ASN.1 object representation.
          */
-        public override Asn1Object ToAsn1Object()
-        {
-            return new DerSequence(algID, macValue);
-        }
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_algID, m_macValue);
     }
 }