using System; using System.Collections.Generic; using System.Linq; using System.Text; using static StellaOps.Localization.T; namespace StellaOps.Provcache; public sealed partial class VeriKeyBuilder { /// /// Sets the VEX hash set hash (sorted aggregation of VEX statement hashes). /// /// The pre-computed VEX hash set hash. /// This builder for fluent chaining. public VeriKeyBuilder WithVexHashSet(string vexHashSetHash) { if (string.IsNullOrWhiteSpace(vexHashSetHash)) throw new ArgumentException(_t("common.provcache.vex_hash_required"), nameof(vexHashSetHash)); _vexHashSetHash = NormalizeHash(vexHashSetHash); return this; } /// /// Computes VEX hash set from individual VEX statement hashes. /// Hashes are sorted lexicographically before aggregation for determinism. /// /// Individual VEX statement hashes. /// This builder for fluent chaining. public VeriKeyBuilder WithVexStatementHashes(IEnumerable vexStatementHashes) { ArgumentNullException.ThrowIfNull(vexStatementHashes); var sortedHashes = vexStatementHashes .Where(h => !string.IsNullOrWhiteSpace(h)) .Select(NormalizeHash) .Order(StringComparer.Ordinal) .ToList(); if (sortedHashes.Count == 0) { _vexHashSetHash = ComputeHash(Encoding.UTF8.GetBytes("empty-vex-set")); } else { var concatenated = string.Join("|", sortedHashes); _vexHashSetHash = ComputeHash(Encoding.UTF8.GetBytes(concatenated)); } return this; } }