diff options
Diffstat (limited to 'crypto/src/asn1/tsp/TimeStampResp.cs')
-rw-r--r-- | crypto/src/asn1/tsp/TimeStampResp.cs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crypto/src/asn1/tsp/TimeStampResp.cs b/crypto/src/asn1/tsp/TimeStampResp.cs index cc9c2ed4d..3d8fb63f9 100644 --- a/crypto/src/asn1/tsp/TimeStampResp.cs +++ b/crypto/src/asn1/tsp/TimeStampResp.cs @@ -2,11 +2,10 @@ using System; using Org.BouncyCastle.Asn1.Cmp; using Org.BouncyCastle.Asn1.Cms; -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.Tsp { - public class TimeStampResp + public class TimeStampResp : Asn1Encodable { public static TimeStampResp GetInstance(object obj) @@ -18,17 +17,22 @@ namespace Org.BouncyCastle.Asn1.Tsp return new TimeStampResp(Asn1Sequence.GetInstance(obj)); } - public static TimeStampResp GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) - { - return new TimeStampResp(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); - } + public static TimeStampResp GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new TimeStampResp(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); + + public static TimeStampResp GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new TimeStampResp(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); private readonly PkiStatusInfo m_pkiStatusInfo; private readonly ContentInfo m_timeStampToken; private TimeStampResp(Asn1Sequence seq) { - m_pkiStatusInfo = PkiStatusInfo.GetInstance(seq[0]); + int count = seq.Count; + if (count < 1 || count > 2) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); + + m_pkiStatusInfo = PkiStatusInfo.GetInstance(seq[0]); if (seq.Count > 1) { @@ -38,7 +42,7 @@ namespace Org.BouncyCastle.Asn1.Tsp public TimeStampResp(PkiStatusInfo pkiStatusInfo, ContentInfo timeStampToken) { - m_pkiStatusInfo = pkiStatusInfo; + m_pkiStatusInfo = pkiStatusInfo ?? throw new ArgumentNullException(nameof(pkiStatusInfo)); m_timeStampToken = timeStampToken; } @@ -55,10 +59,9 @@ namespace Org.BouncyCastle.Asn1.Tsp */ public override Asn1Object ToAsn1Object() { - Asn1EncodableVector v = new Asn1EncodableVector(2); - v.Add(m_pkiStatusInfo); - v.AddOptional(m_timeStampToken); - return new DerSequence(v); + return m_timeStampToken == null + ? new DerSequence(m_pkiStatusInfo) + : new DerSequence(m_pkiStatusInfo, m_timeStampToken); } } } |