mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-18 18:24:56 +02:00
.config
.run
.workdir
Agent
Common
Docker
Server
Utils
Phantom.Utils.Collections
Phantom.Utils.Collections.Tests
Phantom.Utils.Cryptography
Base24.cs
Phantom.Utils.Cryptography.csproj
Sha1String.cs
StableHashCode.cs
TokenGenerator.cs
Phantom.Utils.Events
Phantom.Utils.IO
Phantom.Utils.Rpc
Phantom.Utils.Runtime
Phantom.Utils.Runtime.Tests
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
34 lines
769 B
C#
34 lines
769 B
C#
namespace Phantom.Utils.Cryptography;
|
|
|
|
public sealed class Sha1String {
|
|
public static Sha1String FromString(string? hash) {
|
|
if (hash is not { Length: 40 } || hash.Any(static c => !char.IsAsciiHexDigit(c))) {
|
|
throw new ArgumentException("Invalid SHA-1 hash.", nameof(hash));
|
|
}
|
|
|
|
return new Sha1String(hash.ToLowerInvariant());
|
|
}
|
|
|
|
public static Sha1String FromBytes(byte[] bytes) {
|
|
return FromString(Convert.ToHexString(bytes));
|
|
}
|
|
|
|
private readonly string hash;
|
|
|
|
private Sha1String(string hash) {
|
|
this.hash = hash;
|
|
}
|
|
|
|
public override bool Equals(object? obj) {
|
|
return obj is Sha1String other && hash == other.hash;
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
return hash.GetHashCode();
|
|
}
|
|
|
|
public override string ToString() {
|
|
return hash;
|
|
}
|
|
}
|