summary refs log tree commit diff
path: root/crypto/src/asn1/cmp/CrlStatus.cs
blob: f5cf091f48e9baa2913e05c74989d3484ddeba08 (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
using System;

using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Cmp
{
    /**
     * CRLStatus ::= SEQUENCE {
     * source       CRLSource,
     * thisUpdate   Time OPTIONAL }
     */
    public class CrlStatus
        : Asn1Encodable
    {
        public static CrlStatus GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is CrlStatus crlStatus)
                return crlStatus;
            return new CrlStatus(Asn1Sequence.GetInstance(obj));
        }

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

        private readonly CrlSource m_source;
        private readonly Time m_thisUpdate;

        private CrlStatus(Asn1Sequence sequence)
        {
            int count = sequence.Count;
            if (count < 1 || count > 2)
                throw new ArgumentException("expected sequence size of 1 or 2, got " + count);

            m_source = CrlSource.GetInstance(sequence[0]);

            if (sequence.Count == 2)
            {
                m_thisUpdate = Time.GetInstance(sequence[1]);
            }
        }

        public CrlStatus(CrlSource source, Time thisUpdate)
        {
            m_source = source;
            m_thisUpdate = thisUpdate;
        }

        public virtual CrlSource Source => m_source;

        public virtual Time ThisUpdate => m_thisUpdate;

        public override Asn1Object ToAsn1Object()
        {
            if (m_thisUpdate == null)
                return new DerSequence(m_source);

            return new DerSequence(m_source, m_thisUpdate);
        }
    }
}