diff options
Diffstat (limited to 'crypto/src/asn1/cmp/RevAnnContent.cs')
-rw-r--r-- | crypto/src/asn1/cmp/RevAnnContent.cs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/crypto/src/asn1/cmp/RevAnnContent.cs b/crypto/src/asn1/cmp/RevAnnContent.cs index 5ac731fb8..e94beb0df 100644 --- a/crypto/src/asn1/cmp/RevAnnContent.cs +++ b/crypto/src/asn1/cmp/RevAnnContent.cs @@ -1,3 +1,5 @@ +using System; + using Org.BouncyCastle.Asn1.Crmf; using Org.BouncyCastle.Asn1.X509; @@ -35,24 +37,27 @@ namespace Org.BouncyCastle.Asn1.Cmp public RevAnnContent(PkiStatusEncodable status, CertId certID, Asn1GeneralizedTime willBeRevokedAt, Asn1GeneralizedTime badSinceDate, X509Extensions crlDetails) { - m_status = status; - m_certID = certID; - m_willBeRevokedAt = willBeRevokedAt; - m_badSinceDate = badSinceDate; + m_status = status ?? throw new ArgumentNullException(nameof(status)); + m_certID = certID ?? throw new ArgumentNullException(nameof(certID)); + m_willBeRevokedAt = willBeRevokedAt ?? throw new ArgumentNullException(nameof(willBeRevokedAt)); + m_badSinceDate = badSinceDate ?? throw new ArgumentNullException(nameof(badSinceDate)); m_crlDetails = crlDetails; } private RevAnnContent(Asn1Sequence seq) { - m_status = PkiStatusEncodable.GetInstance(seq[0]); - m_certID = CertId.GetInstance(seq[1]); - m_willBeRevokedAt = Asn1GeneralizedTime.GetInstance(seq[2]); - m_badSinceDate = Asn1GeneralizedTime.GetInstance(seq[3]); + int count = seq.Count, pos = 0; + if (count < 4 || count > 5) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); + + m_status = PkiStatusEncodable.GetInstance(seq[pos++]); + m_certID = CertId.GetInstance(seq[pos++]); + m_willBeRevokedAt = Asn1GeneralizedTime.GetInstance(seq[pos++]); + m_badSinceDate = Asn1GeneralizedTime.GetInstance(seq[pos++]); + m_crlDetails = Asn1Utilities.ReadOptional(seq, ref pos, X509Extensions.GetOptional); - if (seq.Count > 4) - { - m_crlDetails = X509Extensions.GetInstance(seq[4]); - } + if (pos != count) + throw new ArgumentException("Unexpected elements in sequence", nameof(seq)); } public virtual PkiStatusEncodable Status => m_status; |