using System.Security.Cryptography;
using ZB.MOM.WW.Secrets.Abstractions;
namespace ZB.MOM.WW.Secrets.Tests.Fakes;
///
/// A hand-written test double (the family does not use Moq).
/// Generates a random 32-byte master key once at construction and returns it stably, alongside
/// a caller-supplied . Two instances with the same string
/// still hold different key bytes, which lets a test prove that a matching KEK id but wrong key
/// material fails closed.
///
public sealed class FakeMasterKeyProvider : IMasterKeyProvider
{
private readonly byte[] _key;
///
/// Creates a provider with a freshly generated random 32-byte master key and the given
/// .
///
/// The stable, non-secret key identifier this provider reports.
public FakeMasterKeyProvider(string kekId = "k1")
{
KekId = kekId;
_key = RandomNumberGenerator.GetBytes(32);
}
///
/// Creates a provider that reuses an explicit 32-byte key. Use this to build a second
/// provider with the same key bytes as another (or, by omitting it, a different random key).
///
/// The stable, non-secret key identifier this provider reports.
/// The exact 32-byte master key material to use.
public FakeMasterKeyProvider(string kekId, byte[] key)
{
KekId = kekId;
_key = (byte[])key.Clone();
}
///
public string KekId { get; }
///
public ReadOnlyMemory GetMasterKey() => _key;
}