summary refs log tree commit diff
path: root/crypto/src/asn1/cms/EncryptedData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms/EncryptedData.cs')
-rw-r--r--crypto/src/asn1/cms/EncryptedData.cs62
1 files changed, 23 insertions, 39 deletions
diff --git a/crypto/src/asn1/cms/EncryptedData.cs b/crypto/src/asn1/cms/EncryptedData.cs
index 4136994e6..fe0ff2c23 100644
--- a/crypto/src/asn1/cms/EncryptedData.cs
+++ b/crypto/src/asn1/cms/EncryptedData.cs
@@ -19,58 +19,41 @@ namespace Org.BouncyCastle.Asn1.Cms
             return new EncryptedData(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
         }
 
-        private readonly DerInteger				version;
-		private readonly EncryptedContentInfo	encryptedContentInfo;
-		private readonly Asn1Set				unprotectedAttrs;
+        private readonly DerInteger m_version;
+        private readonly EncryptedContentInfo m_encryptedContentInfo;
+        private readonly Asn1Set m_unprotectedAttrs;
 
-		public EncryptedData(
-			EncryptedContentInfo encInfo)
-			: this(encInfo, null)
-		{
-		}
-
-		public EncryptedData(
-			EncryptedContentInfo	encInfo,
-			Asn1Set					unprotectedAttrs)
-		{
-			if (encInfo == null)
-				throw new ArgumentNullException("encInfo");
+        public EncryptedData(EncryptedContentInfo encInfo)
+            : this(encInfo, null)
+        {
+        }
 
-			this.version = new DerInteger((unprotectedAttrs == null) ? 0 : 2);
-			this.encryptedContentInfo = encInfo;
-			this.unprotectedAttrs = unprotectedAttrs;
+        public EncryptedData(EncryptedContentInfo encInfo, Asn1Set unprotectedAttrs)
+        {
+			m_version = unprotectedAttrs == null ? DerInteger.Zero : DerInteger.Two;
+			m_encryptedContentInfo = encInfo ?? throw new ArgumentNullException(nameof(encInfo));
+			m_unprotectedAttrs = unprotectedAttrs;
 		}
 
 		private EncryptedData(Asn1Sequence seq)
 		{
-			int count = seq.Count;
+			int count = seq.Count, pos = 0;
 			if (count < 2 || count > 3)
 				throw new ArgumentException("Bad sequence size: " + count, nameof(seq));
 
-			int pos = 0;
-
-			this.version = DerInteger.GetInstance(seq[pos++]);
-			this.encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[pos++]);
-			this.unprotectedAttrs = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, Asn1Set.GetInstance);
+			m_version = DerInteger.GetInstance(seq[pos++]);
+			m_encryptedContentInfo = EncryptedContentInfo.GetInstance(seq[pos++]);
+			m_unprotectedAttrs = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, Asn1Set.GetInstance);
 
             if (pos != count)
                 throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
         }
 
-        public virtual DerInteger Version
-		{
-			get { return version; }
-		}
+		public virtual DerInteger Version => m_version;
 
-		public virtual EncryptedContentInfo EncryptedContentInfo
-		{
-			get { return encryptedContentInfo; }
-		}
+		public virtual EncryptedContentInfo EncryptedContentInfo => m_encryptedContentInfo;
 
-		public virtual Asn1Set UnprotectedAttrs
-		{
-			get { return unprotectedAttrs; }
-		}
+		public virtual Asn1Set UnprotectedAttrs => m_unprotectedAttrs;
 
 		/**
 		* <pre>
@@ -83,11 +66,12 @@ namespace Org.BouncyCastle.Asn1.Cms
 		*/
 		public override Asn1Object ToAsn1Object()
 		{
-			Asn1EncodableVector v = new Asn1EncodableVector(version, encryptedContentInfo);
+			Asn1EncodableVector v = new Asn1EncodableVector(3);
+			v.Add(m_version, m_encryptedContentInfo);
 
-			if (unprotectedAttrs != null)
+			if (m_unprotectedAttrs != null)
 			{
-				v.Add(new BerTaggedObject(false, 1, unprotectedAttrs));
+				v.Add(new BerTaggedObject(false, 1, m_unprotectedAttrs));
 			}
 
 			return new BerSequence(v);