summary refs log tree commit diff
path: root/crypto/src/asn1/crmf/PKMacValue.cs
blob: 67e5ce6cc9d6b6735e6cecb0487e99826d9623f2 (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
using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.X509;

namespace Org.BouncyCastle.Asn1.Crmf
{
    /**
     * Password-based MAC value for use with POPOSigningKeyInput.
     */
    public class PKMacValue
        : Asn1Encodable
    {
        public static PKMacValue GetInstance(object obj)
        {
            if (obj == null)
                return null;
            if (obj is PKMacValue pkMacValue)
                return pkMacValue;
            return new PKMacValue(Asn1Sequence.GetInstance(obj));
        }

        public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit)
        {
            return new PKMacValue(Asn1Sequence.GetInstance(obj, isExplicit));
        }

        private readonly AlgorithmIdentifier m_algID;
        private readonly DerBitString m_macValue;

        private PKMacValue(Asn1Sequence seq)
        {
            m_algID = AlgorithmIdentifier.GetInstance(seq[0]);
            m_macValue = DerBitString.GetInstance(seq[1]);
        }

        /**
         * Creates a new PKMACValue.
         * @param params parameters for password-based MAC
         * @param value MAC of the DER-encoded SubjectPublicKeyInfo
         */
        public PKMacValue(PbmParameter pbmParams, DerBitString macValue)
            : this(new AlgorithmIdentifier(CmpObjectIdentifiers.passwordBasedMac, pbmParams), macValue)
        {
        }

        /**
         * Creates a new PKMACValue.
         * @param aid CMPObjectIdentifiers.passwordBasedMAC, with PBMParameter
         * @param value MAC of the DER-encoded SubjectPublicKeyInfo
         */
        public PKMacValue(AlgorithmIdentifier algID, DerBitString macValue)
        {
            m_algID = algID;
            m_macValue = macValue;
        }

        public virtual AlgorithmIdentifier AlgID => m_algID;

        public virtual DerBitString MacValue => m_macValue;

        /**
         * <pre>
         * PKMACValue ::= SEQUENCE {
         *      algId  AlgorithmIdentifier,
         *      -- algorithm value shall be PasswordBasedMac 1.2.840.113533.7.66.13
         *      -- parameter value is PBMParameter
         *      value  BIT STRING }
         * </pre>
         * @return a basic ASN.1 object representation.
         */
        public override Asn1Object ToAsn1Object() => new DerSequence(m_algID, m_macValue);
    }
}