diff options
Diffstat (limited to 'crypto/src/asn1/cmp/OobCertHash.cs')
-rw-r--r-- | crypto/src/asn1/cmp/OobCertHash.cs | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/crypto/src/asn1/cmp/OobCertHash.cs b/crypto/src/asn1/cmp/OobCertHash.cs index 209113167..f1531f309 100644 --- a/crypto/src/asn1/cmp/OobCertHash.cs +++ b/crypto/src/asn1/cmp/OobCertHash.cs @@ -40,29 +40,25 @@ namespace Org.BouncyCastle.Asn1.Cmp private OobCertHash(Asn1Sequence seq) { - int index = seq.Count - 1; + int count = seq.Count, pos = 0; + if (count < 1 || count > 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - m_hashVal = DerBitString.GetInstance(seq[index--]); + m_hashAlg = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, true, AlgorithmIdentifier.GetInstance); + m_certId = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, true, CertId.GetInstance); + m_hashVal = DerBitString.GetInstance(seq[pos++]); - for (int i = index; i >= 0; i--) - { - Asn1TaggedObject tObj = (Asn1TaggedObject)seq[i]; - - if (tObj.HasContextTag(0)) - { - m_hashAlg = AlgorithmIdentifier.GetInstance(tObj, true); - } - else if (tObj.HasContextTag(1)) - { - m_certId = CertId.GetInstance(tObj, true); - } - else - { - throw new ArgumentException("unknown tag: " + Asn1Utilities.GetTagText(tObj)); - } - } + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } + public OobCertHash(AlgorithmIdentifier hashAlg, CertId certId, DerBitString hashVal) + { + m_hashAlg = hashAlg; + m_certId = certId; + m_hashVal = hashVal ?? throw new ArgumentNullException(nameof(hashVal)); + } + public virtual CertId CertID => m_certId; public virtual AlgorithmIdentifier HashAlg => m_hashAlg; |