This commit is contained in:
StellaOps Bot
2025-12-09 00:20:52 +02:00
parent 3d01bf9edc
commit bc0762e97d
261 changed files with 14033 additions and 4427 deletions

View File

@@ -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));
}
}

View File

@@ -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;