using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StellaOps.Provcache; public sealed partial class VeriKeyBuilder { /// /// Sets the signer set hash (sorted certificate chain hashes). /// /// The pre-computed signer set hash. /// This builder for fluent chaining. public VeriKeyBuilder WithSignerSetHash(string signerSetHash) { if (string.IsNullOrWhiteSpace(signerSetHash)) throw new ArgumentException("Signer set hash cannot be null or empty.", nameof(signerSetHash)); _signerSetHash = NormalizeHash(signerSetHash); return this; } /// /// Computes signer set hash from individual certificate hashes. /// Hashes are sorted lexicographically before aggregation for determinism. /// /// Individual certificate hashes. /// This builder for fluent chaining. public VeriKeyBuilder WithCertificateHashes(IEnumerable certificateHashes) { ArgumentNullException.ThrowIfNull(certificateHashes); var sortedHashes = certificateHashes .Where(h => !string.IsNullOrWhiteSpace(h)) .Select(NormalizeHash) .Order(StringComparer.Ordinal) .ToList(); if (sortedHashes.Count == 0) { _signerSetHash = ComputeHash(Encoding.UTF8.GetBytes("empty-signer-set")); } else { var concatenated = string.Join("|", sortedHashes); _signerSetHash = ComputeHash(Encoding.UTF8.GetBytes(concatenated)); } return this; } }