summary refs log tree commit diff
path: root/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-06-20 21:29:18 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-06-20 21:29:18 +0700
commit3b505be299fc4e147598605a9ee30c10a7e3eb85 (patch)
tree946d70722499668b38ed038c2311d92ac08a373a /crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
parentAdd Try... methods to DerInteger for small value accessors (diff)
downloadBouncyCastle.NET-ed25519-3b505be299fc4e147598605a9ee30c10a7e3eb85.tar.xz
Refactoring in Asn1.Pkcs
Diffstat (limited to 'crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs')
-rw-r--r--crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs55
1 files changed, 25 insertions, 30 deletions
diff --git a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
index bf0e1aaeb..39f3e9c3e 100644
--- a/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
+++ b/crypto/src/asn1/pkcs/EncryptedPrivateKeyInfo.cs
@@ -7,26 +7,6 @@ namespace Org.BouncyCastle.Asn1.Pkcs
     public class EncryptedPrivateKeyInfo
         : Asn1Encodable
     {
-        private readonly AlgorithmIdentifier algId;
-        private readonly Asn1OctetString data;
-
-		private EncryptedPrivateKeyInfo(Asn1Sequence seq)
-        {
-			if (seq.Count != 2)
-				throw new ArgumentException("Wrong number of elements in sequence", "seq");
-
-            algId = AlgorithmIdentifier.GetInstance(seq[0]);
-            data = Asn1OctetString.GetInstance(seq[1]);
-        }
-
-		public EncryptedPrivateKeyInfo(
-            AlgorithmIdentifier	algId,
-            byte[]				encoding)
-        {
-            this.algId = algId;
-            this.data = new DerOctetString(encoding);
-        }
-
         public static EncryptedPrivateKeyInfo GetInstance(object obj)
         {
             if (obj == null)
@@ -36,16 +16,34 @@ namespace Org.BouncyCastle.Asn1.Pkcs
             return new EncryptedPrivateKeyInfo(Asn1Sequence.GetInstance(obj));
         }
 
-		public AlgorithmIdentifier EncryptionAlgorithm
-		{
-			get { return algId; }
-		}
+        public static EncryptedPrivateKeyInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
+        {
+            return new EncryptedPrivateKeyInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
 
-		public byte[] GetEncryptedData()
+        private readonly AlgorithmIdentifier m_encryptionAlgorithm;
+        private readonly Asn1OctetString m_encryptedData;
+
+		private EncryptedPrivateKeyInfo(Asn1Sequence seq)
+        {
+            int count = seq.Count;
+            if (count != 2)
+                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
+
+            m_encryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
+            m_encryptedData = Asn1OctetString.GetInstance(seq[1]);
+        }
+
+        public EncryptedPrivateKeyInfo(AlgorithmIdentifier algId, byte[] encoding)
         {
-            return data.GetOctets();
+            m_encryptionAlgorithm = algId ?? throw new ArgumentNullException(nameof(algId));
+            m_encryptedData = new DerOctetString(encoding);
         }
 
+        public AlgorithmIdentifier EncryptionAlgorithm => m_encryptionAlgorithm;
+
+        public byte[] GetEncryptedData() => m_encryptedData.GetOctets();
+
 		/**
          * Produce an object suitable for an Asn1OutputStream.
          * <pre>
@@ -61,9 +59,6 @@ namespace Org.BouncyCastle.Asn1.Pkcs
          * }
          * </pre>
          */
-        public override Asn1Object ToAsn1Object()
-        {
-			return new DerSequence(algId, data);
-        }
+        public override Asn1Object ToAsn1Object() => new DerSequence(m_encryptionAlgorithm, m_encryptedData);
     }
 }