Files
git.stella-ops.org/src/StellaOps.Notify.Connectors.Shared/ConnectorHashing.cs
master 48f3071e2a Add tests and implement StubBearer authentication for Signer endpoints
- Created SignerEndpointsTests to validate the SignDsse and VerifyReferrers endpoints.
- Implemented StubBearerAuthenticationDefaults and StubBearerAuthenticationHandler for token-based authentication.
- Developed ConcelierExporterClient for managing Trivy DB settings and export operations.
- Added TrivyDbSettingsPageComponent for UI interactions with Trivy DB settings, including form handling and export triggering.
- Implemented styles and HTML structure for Trivy DB settings page.
- Created NotifySmokeCheck tool for validating Redis event streams and Notify deliveries.
2025-10-21 09:37:07 +03:00

32 lines
1003 B
C#

using System;
using System.Security.Cryptography;
using System.Text;
namespace StellaOps.Notify.Connectors.Shared;
/// <summary>
/// Common hashing helpers for Notify connector metadata.
/// </summary>
public static class ConnectorHashing
{
/// <summary>
/// Computes a lowercase hex SHA-256 hash and truncates it to the requested number of bytes.
/// </summary>
public static string ComputeSha256Hash(string value, int lengthBytes = 8)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Value must not be null or whitespace.", nameof(value));
}
if (lengthBytes <= 0 || lengthBytes > 32)
{
throw new ArgumentOutOfRangeException(nameof(lengthBytes), "Length must be between 1 and 32 bytes.");
}
var bytes = Encoding.UTF8.GetBytes(value.Trim());
var hash = SHA256.HashData(bytes);
return Convert.ToHexString(hash.AsSpan(0, lengthBytes)).ToLowerInvariant();
}
}