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

using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Crmf
{
    public class SinglePubInfo
        : Asn1Encodable
    {
        private readonly DerInteger pubMethod;
        private readonly GeneralName pubLocation;

        private SinglePubInfo(Asn1Sequence seq)
        {
            pubMethod = DerInteger.GetInstance(seq[0]);

            if (seq.Count == 2)
            {
                pubLocation = GeneralName.GetInstance(seq[1]);
            }
        }

        public static SinglePubInfo GetInstance(object obj)
        {
            if (obj is SinglePubInfo)
                return (SinglePubInfo)obj;

            if (obj is Asn1Sequence)
                return new SinglePubInfo((Asn1Sequence)obj);

            throw new ArgumentException("Invalid object: " + obj.GetType().Name, "obj");
        }

        public virtual GeneralName PubLocation
        {
            get { return pubLocation; }
        }

        /**
         * <pre>
         * SinglePubInfo ::= SEQUENCE {
         *        pubMethod    INTEGER {
         *           dontCare    (0),
         *           x500        (1),
         *           web         (2),
         *           ldap        (3) },
         *       pubLocation  GeneralName OPTIONAL }
         * </pre>
         * @return a basic ASN.1 object representation.
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(pubMethod);
            v.AddOptional(pubLocation);
            return new DerSequence(v);
        }
    }
}