1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-18 18:24:56 +02:00
Files
.config
.run
.workdir
Agent
Common
Phantom.Common.Data
Agent
Backups
Instance
Java
Minecraft
Replies
AllowedPorts.cs
AuthToken.cs
ConnectionCommonKey.cs
Optional.cs
Phantom.Common.Data.csproj
PortRange.cs
RamAllocationUnits.cs
Result.cs
Phantom.Common.Data.Tests
Phantom.Common.Data.Web
Phantom.Common.Messages.Agent
Phantom.Common.Messages.Web
Controller
Docker
Utils
Web
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
2024-03-30 17:08:57 +01:00

38 lines
1007 B
C#

using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using MemoryPack;
namespace Phantom.Common.Data;
[MemoryPackable(GenerateType.VersionTolerant)]
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public sealed partial class AuthToken {
internal const int Length = 12;
[MemoryPackOrder(0)]
[MemoryPackInclude]
private readonly byte[] bytes;
internal AuthToken(byte[]? bytes) {
ArgumentNullException.ThrowIfNull(bytes);
if (bytes.Length != Length) {
throw new ArgumentOutOfRangeException(nameof(bytes), "Invalid token length: " + bytes.Length + ". Token length must be exactly " + Length + " bytes.");
}
this.bytes = bytes;
}
public bool FixedTimeEquals(AuthToken providedAuthToken) {
return CryptographicOperations.FixedTimeEquals(bytes, providedAuthToken.bytes);
}
internal void WriteTo(Span<byte> span) {
bytes.CopyTo(span);
}
public static AuthToken Generate() {
return new AuthToken(RandomNumberGenerator.GetBytes(Length));
}
}