54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Sets the VEX hash set hash (sorted aggregation of VEX statement hashes).
|
|
/// </summary>
|
|
/// <param name="vexHashSetHash">The pre-computed VEX hash set hash.</param>
|
|
/// <returns>This builder for fluent chaining.</returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Computes VEX hash set from individual VEX statement hashes.
|
|
/// Hashes are sorted lexicographically before aggregation for determinism.
|
|
/// </summary>
|
|
/// <param name="vexStatementHashes">Individual VEX statement hashes.</param>
|
|
/// <returns>This builder for fluent chaining.</returns>
|
|
public VeriKeyBuilder WithVexStatementHashes(IEnumerable<string> 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;
|
|
}
|
|
}
|