diff --git a/src/Toimik.WarcProtocol/DigestFactory.cs b/src/Toimik.WarcProtocol/DigestFactory.cs
index 0f55486..2f9a331 100644
--- a/src/Toimik.WarcProtocol/DigestFactory.cs
+++ b/src/Toimik.WarcProtocol/DigestFactory.cs
@@ -16,19 +16,59 @@
namespace Toimik.WarcProtocol;
-using System.Security.Cryptography;
+using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Digests;
+using System;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
public class DigestFactory(string hashName)
{
public string HashName { get; } = hashName;
+ [ExcludeFromCodeCoverage]
public virtual string CreateDigest(byte[] buffer)
{
- using var algorithm = HashAlgorithm.Create(HashName);
+ IDigest digest = HashName.ToUpper() switch
+ {
+ "BLAKE2B" => new Blake2bDigest(),
+ "BLAKE2S" => new Blake2sDigest(),
+ "BLAKE2XS" => new Blake2xsDigest(),
+ "GOST3411_2012_256" => new Gost3411_2012_256Digest(),
+ "GOST3411_2012_512" => new Gost3411_2012_512Digest(),
+ "GOST3411" => new Gost3411Digest(),
+ "HARAKA256" => new Haraka256Digest(),
+ "HARAKA512" => new Haraka512Digest(),
+ "KECCAK" => new KeccakDigest(),
+ "MD2" => new MD2Digest(),
+ "MD4" => new MD4Digest(),
+ "MD5" => new MD5Digest(),
+ "NULL" => new NullDigest(),
+ "RIPEMD128" => new RipeMD128Digest(),
+ "RIPEMD160" => new RipeMD160Digest(),
+ "RIPEMD256" => new RipeMD256Digest(),
+ "RIPEMD320" => new RipeMD320Digest(),
+ "SHA1" => new Sha1Digest(),
+ "SHA224" => new Sha224Digest(),
+ "SHA256" => new Sha256Digest(),
+ "SHA384" => new Sha384Digest(),
+ "SHA3" => new Sha3Digest(),
+ "SHA512" => new Sha512Digest(),
+ "SHAKE" => new ShakeDigest(),
+ "SM3" => new SM3Digest(),
+ "TIGER" => new TigerDigest(),
+ "WHIRLPOOL" => new WhirlpoolDigest(),
+ _ => throw new ArgumentException($"Unsupported hash algorithm: {HashName}"),
+ };
+ digest.Reset();
+ digest.BlockUpdate(
+ buffer,
+ 0,
+ buffer.Length);
+
+ byte[] bytes = new byte[digest.GetDigestSize()];
+ digest.DoFinal(bytes, 0);
- // It is assumed that the hash name is valid
- var bytes = algorithm!.ComputeHash(buffer);
var builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
diff --git a/src/Toimik.WarcProtocol/Toimik.WarcProtocol.csproj b/src/Toimik.WarcProtocol/Toimik.WarcProtocol.csproj
index 6e2cadb..b9da7ab 100644
--- a/src/Toimik.WarcProtocol/Toimik.WarcProtocol.csproj
+++ b/src/Toimik.WarcProtocol/Toimik.WarcProtocol.csproj
@@ -4,9 +4,9 @@
net8.0
enable
Toimik.WarcProtocol
- 0.10.4
+ 0.10.5
Nurhafiz
- 0.10.4
+ 0.10.5
true
Toimik
@@ -24,6 +24,7 @@
+
all