summary refs log tree commit diff
path: root/crypto/src/asn1/crmf/EncryptedValue.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/crmf/EncryptedValue.cs')
-rw-r--r--crypto/src/asn1/crmf/EncryptedValue.cs62
1 files changed, 29 insertions, 33 deletions
diff --git a/crypto/src/asn1/crmf/EncryptedValue.cs b/crypto/src/asn1/crmf/EncryptedValue.cs
index 7c5cf18b4..ad3a4c3f7 100644
--- a/crypto/src/asn1/crmf/EncryptedValue.cs
+++ b/crypto/src/asn1/crmf/EncryptedValue.cs
@@ -7,6 +7,17 @@ namespace Org.BouncyCastle.Asn1.Crmf
     public class EncryptedValue
         : Asn1Encodable
     {
+        public static EncryptedValue GetInstance(object obj)
+        {
+            if (obj is EncryptedValue)
+                return (EncryptedValue)obj;
+
+            if (obj != null)
+                return new EncryptedValue(Asn1Sequence.GetInstance(obj));
+
+            return null;
+        }
+
         private readonly AlgorithmIdentifier intendedAlg;
         private readonly AlgorithmIdentifier symmAlg;
         private readonly DerBitString encSymmKey;
@@ -17,45 +28,31 @@ namespace Org.BouncyCastle.Asn1.Crmf
         private EncryptedValue(Asn1Sequence seq)
         {
             int index = 0;
-            while (seq[index] is Asn1TaggedObject)
+            while (seq[index++] is Asn1TaggedObject tObj)
             {
-                Asn1TaggedObject tObj = (Asn1TaggedObject)seq[index];
-
                 switch (tObj.TagNo)
                 {
-                    case 0:
-                        intendedAlg = AlgorithmIdentifier.GetInstance(tObj, false);
-                        break;
-                    case 1:
-                        symmAlg = AlgorithmIdentifier.GetInstance(tObj, false);
-                        break;
-                    case 2:
-                        encSymmKey = DerBitString.GetInstance(tObj, false);
-                        break;
-                    case 3:
-                        keyAlg = AlgorithmIdentifier.GetInstance(tObj, false);
-                        break;
-                    case 4:
-                        valueHint = Asn1OctetString.GetInstance(tObj, false);
-                        break;
+                case 0:
+                    intendedAlg = AlgorithmIdentifier.GetInstance(tObj, false);
+                    break;
+                case 1:
+                    symmAlg = AlgorithmIdentifier.GetInstance(tObj, false);
+                    break;
+                case 2:
+                    encSymmKey = DerBitString.GetInstance(tObj, false);
+                    break;
+                case 3:
+                    keyAlg = AlgorithmIdentifier.GetInstance(tObj, false);
+                    break;
+                case 4:
+                    valueHint = Asn1OctetString.GetInstance(tObj, false);
+                    break;
                 }
-                ++index;
             }
 
             encValue = DerBitString.GetInstance(seq[index]);
         }
 
-        public static EncryptedValue GetInstance(object obj)
-        {
-            if (obj is EncryptedValue)
-                return (EncryptedValue)obj;
-
-            if (obj != null)
-                return new EncryptedValue(Asn1Sequence.GetInstance(obj));
-
-            return null;
-        }
-
         public EncryptedValue(
             AlgorithmIdentifier intendedAlg,
             AlgorithmIdentifier symmAlg,
@@ -65,9 +62,7 @@ namespace Org.BouncyCastle.Asn1.Crmf
             DerBitString encValue)
         {
             if (encValue == null)
-            {
-                throw new ArgumentNullException("encValue");
-            }
+                throw new ArgumentNullException(nameof(encValue));
 
             this.intendedAlg = intendedAlg;
             this.symmAlg = symmAlg;
@@ -109,6 +104,7 @@ namespace Org.BouncyCastle.Asn1.Crmf
 
         /**
          * <pre>
+         * (IMPLICIT TAGS)
          * EncryptedValue ::= SEQUENCE {
          *                     intendedAlg   [0] AlgorithmIdentifier  OPTIONAL,
          *                     -- the intended algorithm for which the value will be used