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

using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.X509;

namespace Org.BouncyCastle.Crmf
{
    internal class PKMacValueVerifier
    {
        private readonly PKMacBuilder m_builder;

        internal PKMacValueVerifier(PKMacBuilder builder)
        {
            m_builder = builder;
        }

#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
        internal virtual bool IsValid(PKMacValue value, ReadOnlySpan<char> password, SubjectPublicKeyInfo keyInfo)
        {
            m_builder.SetParameters(PbmParameter.GetInstance(value.AlgID.Parameters));

            var macFactory = m_builder.Build(password);

            return X509Utilities.VerifyMac(macFactory, keyInfo, value.MacValue);
        }
#else
        internal virtual bool IsValid(PKMacValue value, char[] password, SubjectPublicKeyInfo keyInfo)
        {
            m_builder.SetParameters(PbmParameter.GetInstance(value.AlgID.Parameters));

            var macFactory = m_builder.Build(password);

            return X509Utilities.VerifyMac(macFactory, keyInfo, value.MacValue);
        }
#endif
    }
}