up
This commit is contained in:
@@ -79,6 +79,7 @@ public class CryptoProviderRegistryTests
|
||||
{
|
||||
private readonly Dictionary<string, FakeSigner> signers = new(StringComparer.Ordinal);
|
||||
private readonly HashSet<(CryptoCapability Capability, string Algorithm)> supported;
|
||||
private readonly Dictionary<string, FakeHasher> hashers = new(StringComparer.Ordinal);
|
||||
|
||||
public FakeCryptoProvider(string name)
|
||||
{
|
||||
@@ -91,6 +92,10 @@ public class CryptoProviderRegistryTests
|
||||
public FakeCryptoProvider WithSupport(CryptoCapability capability, string algorithm)
|
||||
{
|
||||
supported.Add((capability, algorithm));
|
||||
if (capability == CryptoCapability.ContentHashing && !hashers.ContainsKey(algorithm))
|
||||
{
|
||||
hashers[algorithm] = new FakeHasher(algorithm);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -108,6 +113,16 @@ public class CryptoProviderRegistryTests
|
||||
public IPasswordHasher GetPasswordHasher(string algorithmId)
|
||||
=> throw new NotSupportedException();
|
||||
|
||||
public ICryptoHasher GetHasher(string algorithmId)
|
||||
{
|
||||
if (!hashers.TryGetValue(algorithmId, out var hasher))
|
||||
{
|
||||
throw new InvalidOperationException($"Hasher '{algorithmId}' not registered.");
|
||||
}
|
||||
|
||||
return hasher;
|
||||
}
|
||||
|
||||
public ICryptoSigner GetSigner(string algorithmId, CryptoKeyReference keyReference)
|
||||
{
|
||||
if (!signers.TryGetValue(keyReference.KeyId, out var signer))
|
||||
@@ -169,4 +184,15 @@ public class CryptoProviderRegistryTests
|
||||
Use = JsonWebKeyUseNames.Sig
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class FakeHasher : ICryptoHasher
|
||||
{
|
||||
public FakeHasher(string algorithmId) => AlgorithmId = algorithmId;
|
||||
|
||||
public string AlgorithmId { get; }
|
||||
|
||||
public byte[] ComputeHash(ReadOnlySpan<byte> data) => Array.Empty<byte>();
|
||||
|
||||
public string ComputeHashHex(ReadOnlySpan<byte> data) => Convert.ToHexStringLower(ComputeHash(data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Org.BouncyCastle.Crypto.Prng;
|
||||
using Org.BouncyCastle.Security;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Org.BouncyCastle.Pkcs;
|
||||
using StellaOps.Cryptography;
|
||||
using StellaOps.Cryptography.Plugin.SmSoft;
|
||||
using Xunit;
|
||||
|
||||
Reference in New Issue
Block a user