1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-16 03:31:43 +02:00
Files
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Phantom.Utils
Collections
Cryptography
Base24.cs
Sha1String.cs
StableHashCode.cs
TokenGenerator.cs
IO
Processes
Result
Runtime
Tasks
Threading
Phantom.Utils.csproj
Phantom.Utils.Actor
Phantom.Utils.Events
Phantom.Utils.Logging
Phantom.Utils.Rpc
Phantom.Utils.Tests
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
2023-04-07 01:33:13 +02:00

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;
}
}