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

using Org.BouncyCastle.Asn1;

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

        private readonly DerObjectIdentifier bagID;
        private readonly Asn1Object bagValue;
        private readonly Asn1Set bagAttributes;

		public SafeBag(
            DerObjectIdentifier	oid,
            Asn1Object			obj)
        {
            this.bagID = oid;
            this.bagValue = obj;
            this.bagAttributes = null;
        }

		public SafeBag(
            DerObjectIdentifier	oid,
            Asn1Object			obj,
            Asn1Set				bagAttributes)
        {
            this.bagID = oid;
            this.bagValue = obj;
            this.bagAttributes = bagAttributes;
        }

		private SafeBag(Asn1Sequence seq)
        {
            this.bagID = (DerObjectIdentifier)seq[0];
            this.bagValue = ((Asn1TaggedObject)seq[1]).GetObject();
            if (seq.Count == 3)
            {
                this.bagAttributes = (Asn1Set)seq[2];
            }
        }

		public DerObjectIdentifier BagID
		{
			get { return bagID; }
		}

		public Asn1Object BagValue
		{
			get { return bagValue; }
		}

		public Asn1Set BagAttributes
		{
			get { return bagAttributes; }
		}

        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(bagID, new DerTaggedObject(0, bagValue));
            v.AddOptional(bagAttributes);
            return new DerSequence(v);
        }
    }
}