mirror of
				https://github.com/chylex/Minecraft-Phantom-Panel.git
				synced 2025-10-31 11:17:15 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Diagnostics.CodeAnalysis;
 | |
| using System.Security.Cryptography;
 | |
| using MemoryPack;
 | |
| 
 | |
| namespace Phantom.Common.Data.Agent;
 | |
| 
 | |
| [MemoryPackable]
 | |
| [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
 | |
| public sealed partial class AgentAuthToken {
 | |
| 	internal const int Length = 12;
 | |
| 
 | |
| 	[MemoryPackOrder(0)]
 | |
| 	[MemoryPackInclude]
 | |
| 	private readonly byte[] bytes;
 | |
| 
 | |
| 	internal AgentAuthToken(byte[]? bytes) {
 | |
| 		if (bytes == null) {
 | |
| 			throw new ArgumentNullException(nameof(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(AgentAuthToken providedAuthToken) {
 | |
| 		return CryptographicOperations.FixedTimeEquals(bytes, providedAuthToken.bytes);
 | |
| 	}
 | |
| 
 | |
| 	internal void WriteTo(Span<byte> span) {
 | |
| 		bytes.CopyTo(span);
 | |
| 	}
 | |
| 
 | |
| 	public static AgentAuthToken Generate() {
 | |
| 		return new AgentAuthToken(RandomNumberGenerator.GetBytes(Length));
 | |
| 	}
 | |
| }
 |