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

namespace Org.BouncyCastle.Asn1.Pkcs
{
    public class CertBag
        : Asn1Encodable
    {
        public static CertBag GetInstance(object obj)
        {
            if (obj is CertBag)
                return (CertBag)obj;
            if (obj == null)
                return null;
            return new CertBag(Asn1Sequence.GetInstance(obj));
        }

        private readonly DerObjectIdentifier m_certID;
        private readonly Asn1Object m_certValue;

		private CertBag(Asn1Sequence seq)
        {
			if (seq.Count != 2)
				throw new ArgumentException("Wrong number of elements in sequence", nameof(seq));

            this.m_certID = DerObjectIdentifier.GetInstance(seq[0]);
            this.m_certValue = Asn1TaggedObject.GetInstance(seq[1]).GetObject();
        }

		public CertBag(DerObjectIdentifier certID, Asn1Object certValue)
        {
            m_certID = certID;
            m_certValue = certValue;
        }

        public virtual DerObjectIdentifier CertID => m_certID;

        public virtual Asn1Object CertValue => m_certValue;

		public override Asn1Object ToAsn1Object()
        {
			return new DerSequence(m_certID, new DerTaggedObject(0, m_certValue));
        }
    }
}