1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-09-05 22:53:11 +02:00
Files
Minecraft-Phantom-Panel/Utils/Phantom.Utils.Rpc/New/RpcCertificateThumbprint.cs

32 lines
1023 B
C#

using System.Collections.Immutable;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace Phantom.Utils.Rpc.New;
public sealed record RpcCertificateThumbprint {
private const int Length = 20;
public static RpcCertificateThumbprint From(ReadOnlySpan<byte> bytes) {
return new RpcCertificateThumbprint([..bytes]);
}
internal static RpcCertificateThumbprint From(X509Certificate certificate) {
return new RpcCertificateThumbprint([..certificate.GetCertHash()]);
}
public ImmutableArray<byte> Bytes { get; init; }
private RpcCertificateThumbprint(ImmutableArray<byte> bytes) {
if (bytes.Length != Length) {
throw new ArgumentOutOfRangeException(nameof(bytes), "Invalid thumbprint length: " + bytes.Length + ". Thumbprint length must be exactly " + Length + " bytes.");
}
this.Bytes = bytes;
}
internal bool Check(X509Certificate certificate) {
return CryptographicOperations.FixedTimeEquals(Bytes.AsSpan(), certificate.GetCertHash());
}
}