namespace StellaOps.Cryptography.Kms; /// /// Configuration for PKCS#11-based HSM integrations. /// public sealed class Pkcs11Options { private TimeSpan _metadataCacheDuration = TimeSpan.FromMinutes(5); private TimeSpan _publicKeyCacheDuration = TimeSpan.FromMinutes(5); /// /// Gets or sets the native PKCS#11 library path. /// public string LibraryPath { get; set; } = string.Empty; /// /// Gets or sets an optional slot identifier (decimal or hexadecimal). Mutually exclusive with . /// public string? SlotId { get; set; } /// /// Gets or sets an optional token label to select the target slot. Mutually exclusive with . /// public string? TokenLabel { get; set; } /// /// Gets or sets the PKCS#11 private key label. /// public string? PrivateKeyLabel { get; set; } /// /// Gets or sets the PKCS#11 public key label (optional; falls back to ). /// public string? PublicKeyLabel { get; set; } /// /// Gets or sets the PIN used for user authentication. /// public string? UserPin { get; set; } /// /// Gets or sets an optional PKCS#11 mechanism identifier (default: CKM_ECDSA). /// public uint MechanismId { get; set; } = (uint)Net.Pkcs11Interop.Common.CKM.CKM_ECDSA; /// /// Gets or sets the cache duration for metadata requests (slot/key info). /// public TimeSpan MetadataCacheDuration { get => _metadataCacheDuration; set => _metadataCacheDuration = EnsurePositive(value, TimeSpan.FromMinutes(5)); } /// /// Gets or sets the cache duration for public key material. /// public TimeSpan PublicKeyCacheDuration { get => _publicKeyCacheDuration; set => _publicKeyCacheDuration = EnsurePositive(value, TimeSpan.FromMinutes(5)); } private static TimeSpan EnsurePositive(TimeSpan value, TimeSpan fallback) => value <= TimeSpan.Zero ? fallback : value; }