diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-04 23:44:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-06-04 23:44:11 +0700 |
commit | cea0366cdf7450e96b663a2ee18ad37c2fdeb5cc (patch) | |
tree | 4226642a7547dc373400e385b04a3d2e6f12eed6 /crypto/src/asn1/crmf/PopoSigningKey.cs | |
parent | ASN.1: Add support methods for optional elements (diff) | |
download | BouncyCastle.NET-ed25519-cea0366cdf7450e96b663a2ee18ad37c2fdeb5cc.tar.xz |
Refactoring in Asn1.Crmf
Diffstat (limited to 'crypto/src/asn1/crmf/PopoSigningKey.cs')
-rw-r--r-- | crypto/src/asn1/crmf/PopoSigningKey.cs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crypto/src/asn1/crmf/PopoSigningKey.cs b/crypto/src/asn1/crmf/PopoSigningKey.cs index 2d30e1a67..00138ddb3 100644 --- a/crypto/src/asn1/crmf/PopoSigningKey.cs +++ b/crypto/src/asn1/crmf/PopoSigningKey.cs @@ -1,4 +1,6 @@ -using Org.BouncyCastle.Asn1.X509; +using System; + +using Org.BouncyCastle.Asn1.X509; namespace Org.BouncyCastle.Asn1.Crmf { @@ -25,17 +27,18 @@ namespace Org.BouncyCastle.Asn1.Crmf private PopoSigningKey(Asn1Sequence seq) { - int index = 0; + int count = seq.Count; + if (count < 2 || count > 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); + + int pos = 0; - if (seq[index] is Asn1TaggedObject tagObj) - { - index++; + m_poposkInput = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, false, PopoSigningKeyInput.GetInstance); + m_algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[pos++]); + m_signature = DerBitString.GetInstance(seq[pos++]); - m_poposkInput = PopoSigningKeyInput.GetInstance( - Asn1Utilities.GetContextBaseUniversal(tagObj, 0, false, Asn1Tags.Sequence)); - } - m_algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]); - m_signature = DerBitString.GetInstance(seq[index]); + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } /** @@ -49,8 +52,8 @@ namespace Org.BouncyCastle.Asn1.Crmf public PopoSigningKey(PopoSigningKeyInput poposkIn, AlgorithmIdentifier aid, DerBitString signature) { m_poposkInput = poposkIn; - m_algorithmIdentifier = aid; - m_signature = signature; + m_algorithmIdentifier = aid ?? throw new ArgumentNullException(nameof(aid)); + m_signature = signature ?? throw new ArgumentNullException(nameof(signature)); } public virtual PopoSigningKeyInput PoposkInput => m_poposkInput; |