MireaBackend/Endpoint/Configuration/Validation/SetupTokenService.cs

28 lines
681 B
C#
Raw Normal View History

2024-05-28 06:56:25 +03:00
using Mirea.Api.Endpoint.Common.Interfaces;
using System;
2024-10-07 02:13:35 +03:00
namespace Mirea.Api.Endpoint.Configuration.ConfigurationChecks;
2024-05-28 06:56:25 +03:00
public class SetupTokenService : ISetupToken
{
public ReadOnlyMemory<byte>? Token { get; private set; }
public bool MatchToken(ReadOnlySpan<byte> token)
{
if (Token == null || token.Length != Token.Value.Length)
return false;
var token2 = Token.Value.Span;
int result = 0;
for (int i = 0; i < Token.Value.Length; i++)
result |= token2[i] ^ token[i];
return result == 0;
}
public void SetToken(ReadOnlySpan<byte> token)
{
Token = token.ToArray();
}
}