mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-23 19:42:51 +01:00
19 lines
676 B
C#
19 lines
676 B
C#
namespace Phantom.Common.Data;
|
|
|
|
public readonly record struct ConnectionCommonKey(byte[] CertificatePublicKey, AuthToken AuthToken) {
|
|
private const byte TokenLength = AuthToken.Length;
|
|
|
|
public byte[] ToBytes() {
|
|
Span<byte> result = stackalloc byte[TokenLength + CertificatePublicKey.Length];
|
|
AuthToken.WriteTo(result[..TokenLength]);
|
|
CertificatePublicKey.CopyTo(result[TokenLength..]);
|
|
return result.ToArray();
|
|
}
|
|
|
|
public static ConnectionCommonKey FromBytes(byte[] agentKey) {
|
|
var authToken = new AuthToken(agentKey[..TokenLength]);
|
|
var certificatePublicKey = agentKey[TokenLength..];
|
|
return new ConnectionCommonKey(certificatePublicKey, authToken);
|
|
}
|
|
}
|