summary refs log tree commit diff
path: root/crypto/src/cmp/CmpUtilities.cs
blob: d4e2c89bff6349e7ab44557ba31bcb328757d870 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Operators.Utilities;

namespace Org.BouncyCastle.Cmp
{
    internal static class CmpUtilities
    {
        internal static byte[] CalculateCertHash(Asn1Encodable asn1Encodable, AlgorithmIdentifier signatureAlgorithm,
            IDigestAlgorithmFinder digestAlgorithmFinder)
        {
            var digestAlgorithm = digestAlgorithmFinder.Find(signatureAlgorithm)
                ?? throw new CmpException("cannot find digest algorithm from signature algorithm");

            return X509.X509Utilities.CalculateDigest(digestAlgorithm.Algorithm, asn1Encodable);
        }
    }
}