summary refs log tree commit diff
path: root/crypto/src/asn1/ocsp/CertStatus.cs
blob: e1d06ed19e99374e2fd536550fb8eddd963fb104 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;

namespace Org.BouncyCastle.Asn1.Ocsp
{
    public class CertStatus
        : Asn1Encodable, IAsn1Choice
    {
        public static CertStatus GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is CertStatus certStatus)
                return certStatus;
            return new CertStatus(Asn1TaggedObject.GetInstance(obj));
        }

        public static CertStatus GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
        {
            return Asn1Utilities.GetInstanceFromChoice(taggedObject, declaredExplicit, GetInstance);
        }

        private static Asn1Encodable GetValue(Asn1TaggedObject choice)
        {
            if (choice.HasContextTag())
            {
                switch (choice.TagNo)
                {
                case 0:
                    return Asn1Null.GetInstance(choice, false);
                case 1:
                    return RevokedInfo.GetInstance(choice, false);
                case 2:
                    return Asn1Null.GetInstance(choice, false);
                }
            }

            throw new ArgumentException("Unknown tag encountered: " + Asn1Utilities.GetTagText(choice));
        }

        private readonly int m_tagNo;
        private readonly Asn1Encodable m_value;

		/**
         * create a CertStatus object with a tag of zero.
         */
        public CertStatus()
        {
            m_tagNo = 0;
            m_value = DerNull.Instance;
        }

		public CertStatus(RevokedInfo info)
        {
            m_tagNo = 1;
            m_value = info ?? throw new ArgumentNullException(nameof(info));
        }

		public CertStatus(int tagNo, Asn1Encodable value)
        {
            m_tagNo = tagNo;
            m_value = value ?? throw new ArgumentNullException(nameof(value));
        }

        public CertStatus(Asn1TaggedObject choice)
        {
            m_tagNo = choice.TagNo;
            m_value = GetValue(choice);
        }

        public int TagNo => m_tagNo;

        public Asn1Encodable Status => m_value;

		/**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         *  CertStatus ::= CHOICE {
         *                  good        [0]     IMPLICIT Null,
         *                  revoked     [1]     IMPLICIT RevokedInfo,
         *                  unknown     [2]     IMPLICIT UnknownInfo }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            return new DerTaggedObject(false, m_tagNo, m_value);
        }
    }
}