summary refs log tree commit diff
path: root/crypto/src/asn1/cms/OriginatorPublicKey.cs
blob: 8c7c6b50ff0773d3620e53777b78356f32527283 (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
using Org.BouncyCastle.Asn1.X509;

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

        public static OriginatorPublicKey GetInstance(Asn1TaggedObject obj, bool explicitly)
        {
            return GetInstance(Asn1Sequence.GetInstance(obj, explicitly));
        }

        private readonly AlgorithmIdentifier m_algorithm;
        private readonly DerBitString m_publicKey;

        public OriginatorPublicKey(AlgorithmIdentifier algorithm, byte[] publicKey)
            : this(algorithm, new DerBitString(publicKey))
        {
        }

        public OriginatorPublicKey(AlgorithmIdentifier algorithm, DerBitString publicKey)
        {
            m_algorithm = algorithm;
            m_publicKey = publicKey;
        }

        private OriginatorPublicKey(Asn1Sequence seq)
        {
            m_algorithm = AlgorithmIdentifier.GetInstance(seq[0]);
            m_publicKey = DerBitString.GetInstance(seq[1]);
        }

        public AlgorithmIdentifier Algorithm => m_algorithm;

        public DerBitString PublicKey => m_publicKey;

		/**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * OriginatorPublicKey ::= Sequence {
         *     algorithm AlgorithmIdentifier,
         *     publicKey BIT STRING
         * }
         * </pre>
         */
        public override Asn1Object ToAsn1Object() => new DerSequence(m_algorithm, m_publicKey);
    }
}