using System.Collections.Generic; namespace StellaOps.Cryptography; /// /// High-level cryptographic capabilities supported by StellaOps providers. /// public enum CryptoCapability { PasswordHashing, Signing, Verification, SymmetricEncryption, KeyDerivation, ContentHashing } /// /// Identifies a stored key or certificate handle. /// public sealed record CryptoKeyReference(string KeyId, string? ProviderHint = null); /// /// Contract implemented by crypto providers (BCL, CryptoPro, OpenSSL, etc.). /// public interface ICryptoProvider { string Name { get; } bool Supports(CryptoCapability capability, string algorithmId); IPasswordHasher GetPasswordHasher(string algorithmId); /// /// Retrieves a content hasher for the supplied algorithm. /// /// Hash algorithm identifier (e.g., SHA-256, GOST-R-34.11-2012-256). /// Hasher instance. ICryptoHasher GetHasher(string algorithmId); /// /// Retrieves a signer for the supplied algorithm and key reference. /// /// Signing algorithm identifier (e.g., ES256). /// Key reference. /// Signer instance. ICryptoSigner GetSigner(string algorithmId, CryptoKeyReference keyReference); /// /// Creates an ephemeral verifier from raw public key bytes (verification-only, no key persistence). /// Used for scenarios like DSSE verification where public keys are provided inline. /// /// Signing algorithm identifier (e.g., RS256, ES256). /// Public key in SubjectPublicKeyInfo format (DER-encoded). /// Ephemeral signer instance (supports VerifyAsync only). ICryptoSigner CreateEphemeralVerifier(string algorithmId, ReadOnlySpan publicKeyBytes) => throw new NotSupportedException($"Provider '{Name}' does not support ephemeral verification."); /// /// Adds or replaces signing key material managed by this provider. /// /// Key material descriptor. void UpsertSigningKey(CryptoSigningKey signingKey); /// /// Removes signing key material by key identifier. /// /// Identifier to remove. /// true if the key was removed. bool RemoveSigningKey(string keyId); /// /// Lists signing key descriptors managed by this provider. /// IReadOnlyCollection GetSigningKeys(); } /// /// Registry managing provider discovery and policy selection. /// public interface ICryptoProviderRegistry { IReadOnlyCollection Providers { get; } bool TryResolve(string preferredProvider, out ICryptoProvider provider); ICryptoProvider ResolveOrThrow(CryptoCapability capability, string algorithmId); /// /// Resolves a signer for the supplied algorithm and key reference using registry policy. /// /// Capability required (typically ). /// Algorithm identifier. /// Key reference. /// Optional provider hint. /// Resolved signer. CryptoSignerResolution ResolveSigner( CryptoCapability capability, string algorithmId, CryptoKeyReference keyReference, string? preferredProvider = null); /// /// Resolves a content hasher for the supplied algorithm using registry policy. /// /// Hash algorithm identifier (e.g., SHA-256, GOST-R-34.11-2012-256). /// Optional provider hint. /// Resolved hasher with provider name. CryptoHasherResolution ResolveHasher(string algorithmId, string? preferredProvider = null); } public sealed record CryptoSignerResolution(ICryptoSigner Signer, string ProviderName); public sealed record CryptoHasherResolution(ICryptoHasher Hasher, string ProviderName); /// /// Content hasher for computing cryptographic digests. /// public interface ICryptoHasher { /// /// Algorithm identifier (e.g., SHA-256, GOST-R-34.11-2012-256). /// string AlgorithmId { get; } /// /// Computes the hash of the given data. /// byte[] ComputeHash(ReadOnlySpan data); /// /// Computes the hash and returns it as a lowercase hex string. /// string ComputeHashHex(ReadOnlySpan data); }