summary refs log tree commit diff
path: root/crypto/src/asn1/ocsp/CertStatus.cs
blob: 8a4d2242d0c71a94ba2a8208cbfd519d076bac4c (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
89
90
91
92
93
94
95
96
97
using System;

using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1.Ocsp
{
    public class CertStatus
        : Asn1Encodable, IAsn1Choice
    {
        private readonly int			tagNo;
        private readonly Asn1Encodable	value;

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

		public CertStatus(
            RevokedInfo info)
        {
            tagNo = 1;
            value = info;
        }

		public CertStatus(
            int				tagNo,
            Asn1Encodable	value)
        {
            this.tagNo = tagNo;
            this.value = value;
        }

		public CertStatus(Asn1TaggedObject choice)
        {
            this.tagNo = choice.TagNo;

			switch (choice.TagNo)
            {
            case 0:
                value = Asn1Null.GetInstance(choice, false);
                break;
            case 1:
				value = RevokedInfo.GetInstance(choice, false);
				break;
			case 2:
                value = Asn1Null.GetInstance(choice, false);
                break;
			default:
				throw new ArgumentException("Unknown tag encountered: " + Asn1Utilities.GetTagText(choice));
            }
        }

		public static CertStatus GetInstance(
            object obj)
        {
            if (obj == null || obj is CertStatus)
            {
                return (CertStatus)obj;
            }

			if (obj is Asn1TaggedObject)
            {
                return new CertStatus((Asn1TaggedObject)obj);
            }

            throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
        }

		public int TagNo
		{
			get { return tagNo; }
		}

		public Asn1Encodable Status
		{
			get { return 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, tagNo, value);
        }
    }
}