diff options
Diffstat (limited to 'crypto/src/asn1/cmp/KeyRecRepContent.cs')
-rw-r--r-- | crypto/src/asn1/cmp/KeyRecRepContent.cs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/crypto/src/asn1/cmp/KeyRecRepContent.cs b/crypto/src/asn1/cmp/KeyRecRepContent.cs index e465346eb..ec604f644 100644 --- a/crypto/src/asn1/cmp/KeyRecRepContent.cs +++ b/crypto/src/asn1/cmp/KeyRecRepContent.cs @@ -26,28 +26,18 @@ namespace Org.BouncyCastle.Asn1.Cmp private KeyRecRepContent(Asn1Sequence seq) { - m_status = PkiStatusInfo.GetInstance(seq[0]); + int count = seq.Count, pos = 0; + if (count < 1 || count > 4) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - for (int pos = 1; pos < seq.Count; ++pos) - { - Asn1TaggedObject tObj = Asn1TaggedObject.GetInstance(seq[pos], Asn1Tags.ContextSpecific); + m_status = PkiStatusInfo.GetInstance(seq[pos++]); + m_newSigCert = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 0, true, CmpCertificate.GetInstance); + m_caCerts = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 1, true, Asn1Sequence.GetInstance); + m_keyPairHist = Asn1Utilities.ReadOptionalContextTagged(seq, ref pos, 2, true, Asn1Sequence.GetInstance); - switch (tObj.TagNo) - { - case 0: - m_newSigCert = CmpCertificate.GetInstance(tObj.GetExplicitBaseObject()); - break; - case 1: - m_caCerts = Asn1Sequence.GetInstance(tObj.GetExplicitBaseObject()); - break; - case 2: - m_keyPairHist = Asn1Sequence.GetInstance(tObj.GetExplicitBaseObject()); - break; - default: - throw new ArgumentException("unknown tag number: " + tObj.TagNo); - } - } - } + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); + } public virtual PkiStatusInfo Status => m_status; |