diff options
Diffstat (limited to 'crypto/src/asn1/crmf/CertReqMsg.cs')
-rw-r--r-- | crypto/src/asn1/crmf/CertReqMsg.cs | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/crypto/src/asn1/crmf/CertReqMsg.cs b/crypto/src/asn1/crmf/CertReqMsg.cs index 1832a34cc..5e56f68c9 100644 --- a/crypto/src/asn1/crmf/CertReqMsg.cs +++ b/crypto/src/asn1/crmf/CertReqMsg.cs @@ -25,21 +25,18 @@ namespace Org.BouncyCastle.Asn1.Crmf private CertReqMsg(Asn1Sequence seq) { - m_certReq = CertRequest.GetInstance(seq[0]); + int count = seq.Count; + if (count < 1 || count > 3) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); - for (int pos = 1; pos < seq.Count; ++pos) - { - object o = seq[pos]; + int pos = 0; - if (o is Asn1TaggedObject || o is ProofOfPossession) - { - m_pop = ProofOfPossession.GetInstance(o); - } - else - { - m_regInfo = Asn1Sequence.GetInstance(o); - } - } + m_certReq = CertRequest.GetInstance(seq[pos++]); + m_pop = Asn1Utilities.ReadOptional(seq, ref pos, ProofOfPossession.GetOptional); + m_regInfo = Asn1Utilities.ReadOptional(seq, ref pos, Asn1Sequence.GetOptional); + + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } /** @@ -50,13 +47,9 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public CertReqMsg(CertRequest certReq, ProofOfPossession popo, AttributeTypeAndValue[] regInfo) { - this.m_certReq = certReq ?? throw new ArgumentNullException(nameof(certReq)); - this.m_pop = popo; - - if (regInfo != null) - { - this.m_regInfo = new DerSequence(regInfo); - } + m_certReq = certReq ?? throw new ArgumentNullException(nameof(certReq)); + m_pop = popo; + m_regInfo = regInfo == null ? null : new DerSequence(regInfo); } public virtual CertRequest CertReq => m_certReq; @@ -81,7 +74,7 @@ namespace Org.BouncyCastle.Asn1.Crmf */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(2); + Asn1EncodableVector v = new Asn1EncodableVector(3); v.Add(m_certReq); v.AddOptional(m_pop, m_regInfo); return new DerSequence(v); |