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

using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Cmp
{
    /**
     * GenMsg:    {id-it TBD1}, SEQUENCE SIZE (1..MAX) OF CRLStatus
     * GenRep:    {id-it TBD2}, SEQUENCE SIZE (1..MAX) OF
     * CertificateList  |  < absent >
     * <p>
     * CRLSource ::= CHOICE {
     * dpn          [0] DistributionPointName,
     * issuer       [1] GeneralNames }
     * </p>
     */
    public class CrlSource
        : Asn1Encodable, IAsn1Choice
    {
        public static CrlSource GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is CrlSource crlSource)
                return crlSource;
            return new CrlSource(Asn1TaggedObject.GetInstance(obj));
        }

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

        private readonly DistributionPointName m_dpn;
        private readonly GeneralNames m_issuer;

        private CrlSource(Asn1TaggedObject taggedObject)
        {
            switch (taggedObject.TagNo)
            {
            case 0:
                m_dpn = DistributionPointName.GetInstance(taggedObject, true);
                m_issuer = null;
                break;
            case 1:
                m_dpn = null;
                m_issuer = GeneralNames.GetInstance(taggedObject, true);
                break;
            default:
                throw new ArgumentException("unknown tag: " + Asn1Utilities.GetTagText(taggedObject));
            }
        }

        public CrlSource(DistributionPointName dpn, GeneralNames issuer)
        {
            if ((dpn == null) == (issuer == null))
                throw new ArgumentException("either dpn or issuer must be set");

            m_dpn = dpn;
            m_issuer = issuer;
        }

        public virtual DistributionPointName Dpn => m_dpn;

        public virtual GeneralNames Issuer => m_issuer;

        public override Asn1Object ToAsn1Object()
        {
            if (m_dpn != null)
                return new DerTaggedObject(true, 0, m_dpn);
            if (m_issuer != null)
                return new DerTaggedObject(true, 1, m_issuer);
            throw new InvalidOperationException();
        }
    }
}