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

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Math;

namespace Org.BouncyCastle.Asn1.Pkcs
{
    /**
     * the infamous Pfx from Pkcs12
     */
    public class Pfx
        : Asn1Encodable
    {
        private ContentInfo	contentInfo;
        private MacData		macData;

		public Pfx(
            Asn1Sequence seq)
        {
            BigInteger version = ((DerInteger) seq[0]).Value;
            if (version.IntValue != 3)
            {
                throw new ArgumentException("wrong version for PFX PDU");
            }

			contentInfo = ContentInfo.GetInstance(seq[1]);

			if (seq.Count == 3)
            {
                macData = MacData.GetInstance(seq[2]);
            }
        }

		public Pfx(
            ContentInfo	contentInfo,
            MacData		macData)
        {
            this.contentInfo = contentInfo;
            this.macData = macData;
        }

		public ContentInfo AuthSafe
		{
			get { return contentInfo; }
		}

		public MacData MacData
		{
			get { return macData; }
		}

		public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
				new DerInteger(3), contentInfo);

			if (macData != null)
            {
                v.Add(macData);
            }

			return new BerSequence(v);
        }
    }
}