summary refs log tree commit diff
path: root/crypto/src/asn1/cms/TimeStampAndCRL.cs
blob: a76ce76805409d4d13260c2af7e14e571cbfb8c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;

using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Cms
{
    public class TimeStampAndCrl
		: Asn1Encodable
	{
        public static TimeStampAndCrl GetInstance(object obj)
        {
			if (obj == null)
				return null;
            if (obj is TimeStampAndCrl timeStampAndCrl)
                return timeStampAndCrl;
            return new TimeStampAndCrl(Asn1Sequence.GetInstance(obj));
        }

        public static TimeStampAndCrl GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
        {
            return new TimeStampAndCrl(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
        }

        private readonly ContentInfo m_timeStamp;
		private readonly CertificateList m_crl;

		public TimeStampAndCrl(ContentInfo timeStamp)
			: this(timeStamp, null)
		{
		}

        public TimeStampAndCrl(ContentInfo timeStamp, CertificateList crl)
        {
            m_timeStamp = timeStamp ?? throw new ArgumentNullException(nameof(timeStamp));
            m_crl = crl;
        }

        private TimeStampAndCrl(Asn1Sequence seq)
		{
            int count = seq.Count, pos = 0;
            if (count < 1 || count > 2)
                throw new ArgumentException("Bad sequence size: " + count, nameof(seq));

            m_timeStamp = ContentInfo.GetInstance(seq[pos++]);
            m_crl = Asn1Utilities.ReadOptional(seq, ref pos, CertificateList.GetOptional);

            if (pos != count)
                throw new ArgumentException("Unexpected elements in sequence", nameof(seq));
		}

		public virtual ContentInfo TimeStampToken => m_timeStamp;

		public virtual CertificateList Crl => m_crl;

		/**
		 * <pre>
		 * TimeStampAndCRL ::= SEQUENCE {
		 *     timeStamp   TimeStampToken,          -- according to RFC 3161
		 *     crl         CertificateList OPTIONAL -- according to RFC 5280
		 *  }
		 * </pre>
		 * @return
		 */
		public override Asn1Object ToAsn1Object()
		{
			return m_crl == null
				?  new DerSequence(m_timeStamp)
                :  new DerSequence(m_timeStamp, m_crl);
		}
	}
}