summary refs log tree commit diff
path: root/crypto/src/asn1/x509/qualified/SemanticsInformation.cs
blob: 36a15edecef4737d28c8f2251d6cf0d9d63498ba (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;

using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1.X509.Qualified
{
    /**
    * The SemanticsInformation object.
    * <pre>
    *       SemanticsInformation ::= SEQUENCE {
    *         semanticsIdentifier        OBJECT IDENTIFIER   OPTIONAL,
    *         nameRegistrationAuthorities NameRegistrationAuthorities
    *                                                         OPTIONAL }
    *         (WITH COMPONENTS {..., semanticsIdentifier PRESENT}|
    *          WITH COMPONENTS {..., nameRegistrationAuthorities PRESENT})
    *
    *     NameRegistrationAuthorities ::=  SEQUENCE SIZE (1..MAX) OF
    *         GeneralName
    * </pre>
    */
    public class SemanticsInformation
		: Asn1Encodable
    {
        private readonly DerObjectIdentifier	semanticsIdentifier;
        private readonly GeneralName[]			nameRegistrationAuthorities;

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

			if (obj is Asn1Sequence)
            {
                return new SemanticsInformation(Asn1Sequence.GetInstance(obj));
            }

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

		public SemanticsInformation(Asn1Sequence seq)
        {
            if (seq.Count < 1)
                throw new ArgumentException("no objects in SemanticsInformation");

			var e = seq.GetEnumerator();
			e.MoveNext();
            var obj = e.Current;
            if (obj is DerObjectIdentifier oid)
            {
                semanticsIdentifier = oid;
                if (e.MoveNext())
                {
                    obj = e.Current;
                }
                else
                {
                    obj = null;
                }
            }

            if (obj != null)
            {
                this.nameRegistrationAuthorities = Asn1Sequence.GetInstance(obj).MapElements(GeneralName.GetInstance);
            }
        }

        public SemanticsInformation(
            DerObjectIdentifier semanticsIdentifier,
            GeneralName[] generalNames)
        {
            this.semanticsIdentifier = semanticsIdentifier;
            this.nameRegistrationAuthorities = generalNames;
        }

		public SemanticsInformation(
			DerObjectIdentifier semanticsIdentifier)
        {
            this.semanticsIdentifier = semanticsIdentifier;
        }

        public SemanticsInformation(
			GeneralName[] generalNames)
        {
            this.nameRegistrationAuthorities = generalNames;
        }

		public DerObjectIdentifier SemanticsIdentifier 
        {
            get { return semanticsIdentifier; }
        }

		public GeneralName[] GetNameRegistrationAuthorities()
        {
            return nameRegistrationAuthorities;
        }

        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(2);
            v.AddOptional(semanticsIdentifier);

            if (null != nameRegistrationAuthorities)
            {
                v.Add(new DerSequence(nameRegistrationAuthorities));
            }

            return new DerSequence(v);
        }
    }
}