summary refs log tree commit diff
path: root/crypto/src/cmp/CmpUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cmp/CmpUtilities.cs')
-rw-r--r--crypto/src/cmp/CmpUtilities.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/src/cmp/CmpUtilities.cs b/crypto/src/cmp/CmpUtilities.cs
new file mode 100644
index 000000000..d4e2c89bf
--- /dev/null
+++ b/crypto/src/cmp/CmpUtilities.cs
@@ -0,0 +1,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);
+        }
+    }
+}