diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-18 16:12:06 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-18 16:12:06 +0700 |
commit | 740c25a020c7539c99e82dd4531492c5b6bbd787 (patch) | |
tree | 998874b3c9d7b80636919b44de639218c9622f29 /crypto/src/asn1/cms/EncryptedContentInfo.cs | |
parent | DerInteger constants for small values (diff) | |
download | BouncyCastle.NET-ed25519-740c25a020c7539c99e82dd4531492c5b6bbd787.tar.xz |
Refactoring in Asn1.Cms
Diffstat (limited to 'crypto/src/asn1/cms/EncryptedContentInfo.cs')
-rw-r--r-- | crypto/src/asn1/cms/EncryptedContentInfo.cs | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/crypto/src/asn1/cms/EncryptedContentInfo.cs b/crypto/src/asn1/cms/EncryptedContentInfo.cs index af697af5d..94a5c00c2 100644 --- a/crypto/src/asn1/cms/EncryptedContentInfo.cs +++ b/crypto/src/asn1/cms/EncryptedContentInfo.cs @@ -25,48 +25,38 @@ namespace Org.BouncyCastle.Asn1.Cms #pragma warning restore CS0618 // Type or member is obsolete } - private DerObjectIdentifier contentType; - private AlgorithmIdentifier contentEncryptionAlgorithm; - private Asn1OctetString encryptedContent; + private DerObjectIdentifier m_contentType; + private AlgorithmIdentifier m_contentEncryptionAlgorithm; + private Asn1OctetString m_encryptedContent; - public EncryptedContentInfo( - DerObjectIdentifier contentType, - AlgorithmIdentifier contentEncryptionAlgorithm, - Asn1OctetString encryptedContent) + public EncryptedContentInfo(DerObjectIdentifier contentType, AlgorithmIdentifier contentEncryptionAlgorithm, + Asn1OctetString encryptedContent) { - this.contentType = contentType; - this.contentEncryptionAlgorithm = contentEncryptionAlgorithm; - this.encryptedContent = encryptedContent; + m_contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); + m_contentEncryptionAlgorithm = contentEncryptionAlgorithm ?? throw new ArgumentNullException(nameof(contentEncryptionAlgorithm)); + m_encryptedContent = encryptedContent; } [Obsolete("Use 'GetInstance' instead")] - public EncryptedContentInfo( - Asn1Sequence seq) + public EncryptedContentInfo(Asn1Sequence seq) { - contentType = (DerObjectIdentifier) seq[0]; - contentEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[1]); + int count = seq.Count, pos = 0; + if (count < 2 || count > 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - if (seq.Count > 2) - { - encryptedContent = Asn1OctetString.GetInstance( - (Asn1TaggedObject) seq[2], false); - } - } + m_contentType = DerObjectIdentifier.GetInstance(seq[pos++]); + m_contentEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[pos++]); + m_encryptedContent = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, Asn1OctetString.GetInstance); - public DerObjectIdentifier ContentType - { - get { return contentType; } + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } - public AlgorithmIdentifier ContentEncryptionAlgorithm - { - get { return contentEncryptionAlgorithm; } - } + public DerObjectIdentifier ContentType => m_contentType; - public Asn1OctetString EncryptedContent - { - get { return encryptedContent; } - } + public AlgorithmIdentifier ContentEncryptionAlgorithm => m_contentEncryptionAlgorithm; + + public Asn1OctetString EncryptedContent => m_encryptedContent; /** * Produce an object suitable for an Asn1OutputStream. @@ -80,12 +70,12 @@ namespace Org.BouncyCastle.Asn1.Cms */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector( - contentType, contentEncryptionAlgorithm); + Asn1EncodableVector v = new Asn1EncodableVector(3); + v.Add(m_contentType, m_contentEncryptionAlgorithm); - if (encryptedContent != null) + if (m_encryptedContent != null) { - v.Add(new BerTaggedObject(false, 0, encryptedContent)); + v.Add(new BerTaggedObject(false, 0, m_encryptedContent)); } return new BerSequence(v); |