stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
@@ -10,7 +10,7 @@ namespace StellaOps.ReachGraph.Hashing;
|
||||
/// <summary>
|
||||
/// Computes BLAKE3-256 digests for reachability graphs using canonical serialization.
|
||||
/// </summary>
|
||||
public sealed class ReachGraphDigestComputer
|
||||
public sealed partial class ReachGraphDigestComputer
|
||||
{
|
||||
private readonly CanonicalReachGraphSerializer _serializer;
|
||||
|
||||
@@ -73,42 +73,4 @@ public sealed class ReachGraphDigestComputer
|
||||
return string.Equals(computed, expectedDigest, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse a digest string into its algorithm and hash components.
|
||||
/// </summary>
|
||||
/// <param name="digest">The digest string (e.g., "blake3:abc123...").</param>
|
||||
/// <returns>Tuple of (algorithm, hash) or null if invalid format.</returns>
|
||||
public static (string Algorithm, string Hash)? ParseDigest(string digest)
|
||||
{
|
||||
if (string.IsNullOrEmpty(digest))
|
||||
return null;
|
||||
|
||||
var colonIndex = digest.IndexOf(':');
|
||||
if (colonIndex <= 0 || colonIndex >= digest.Length - 1)
|
||||
return null;
|
||||
|
||||
var algorithm = digest[..colonIndex];
|
||||
var hash = digest[(colonIndex + 1)..];
|
||||
|
||||
return (algorithm, hash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate that a digest string has the correct format for BLAKE3.
|
||||
/// </summary>
|
||||
/// <param name="digest">The digest string to validate.</param>
|
||||
/// <returns>True if valid BLAKE3 digest format, false otherwise.</returns>
|
||||
public static bool IsValidBlake3Digest(string digest)
|
||||
{
|
||||
var parsed = ParseDigest(digest);
|
||||
if (parsed is null)
|
||||
return false;
|
||||
|
||||
var (algorithm, hash) = parsed.Value;
|
||||
|
||||
// BLAKE3-256 produces 64 hex characters (32 bytes)
|
||||
return string.Equals(algorithm, "blake3", StringComparison.OrdinalIgnoreCase) &&
|
||||
hash.Length == 64 &&
|
||||
hash.All(c => char.IsAsciiHexDigit(c));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user