summary refs log tree commit diff
path: root/crypto/src/cmp/GeneralPkiMessage.cs
blob: ad55a8005e0cf745e5e59538412d75aa5ddbe61c (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
namespace Org.BouncyCastle.Asn1.Cmp
{
    public class GeneralPKIMessage
    {
        private readonly PkiMessage pkiMessage;

        private static PkiMessage parseBytes(byte[] encoding)
        {
            return PkiMessage.GetInstance(Asn1Object.FromByteArray(encoding));
        }


        /// <summary>
        /// Wrap a PKIMessage ASN.1 structure.
        /// </summary>
        /// <param name="pkiMessage">PKI message.</param>
        public GeneralPKIMessage(PkiMessage pkiMessage)
        {
            this.pkiMessage = pkiMessage;
        }

        /// <summary>
        /// Create a PKIMessage from the passed in bytes.
        /// </summary>
        /// <param name="encoding">BER/DER encoding of the PKIMessage</param>
        public GeneralPKIMessage(byte[] encoding) : this(parseBytes(encoding))
        {
        }

        public PkiHeader Header
        {
            get
            {
                return pkiMessage.Header;
            }
        }

        public PkiBody Body
        {
            get
            {
                return pkiMessage.Body;
            }
        }

        /// <summary>
        /// Return true if this message has protection bits on it. A return value of true
        /// indicates the message can be used to construct a ProtectedPKIMessage.
        /// </summary>
        public bool HasProtection
        {
            get { return pkiMessage.Protection != null; }
        }

        public PkiMessage ToAsn1Structure()
        {
            return pkiMessage;
        }
    }
}