- 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.
32 lines
1003 B
C#
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();
|
|
}
|
|
}
|