26 lines
1.2 KiB
C#
26 lines
1.2 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
|
|
|
|
/// <summary>Stable delivery GUIDs for persisted alarm queue rows.</summary>
|
|
public static class AlarmDeliveryIds
|
|
{
|
|
/// <summary>
|
|
/// Converts an existing durable row key into a nonzero version-8 GUID. Version 1 of this encoding hashes
|
|
/// UTF-8 "OtOpcUa.AlarmDelivery/v1\0" followed by the exact persisted key with SHA-256, takes the first
|
|
/// 16 bytes, sets the UUID version/variant bits, and interprets the bytes in network order.
|
|
/// This encoding must remain stable across retries, upgrades and replicated failover.
|
|
/// </summary>
|
|
/// <param name="queueId">The persisted row key, never a hash recomputed from the current payload.</param>
|
|
/// <returns>The row's stable delivery identity.</returns>
|
|
public static Guid FromQueueId(string queueId)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(queueId);
|
|
var digest = SHA256.HashData(Encoding.UTF8.GetBytes("OtOpcUa.AlarmDelivery/v1\0" + queueId));
|
|
digest[6] = (byte)((digest[6] & 0x0F) | 0x80);
|
|
digest[8] = (byte)((digest[8] & 0x3F) | 0x80);
|
|
return new Guid(digest.AsSpan(0, 16), bigEndian: true);
|
|
}
|
|
}
|