28 lines
669 B
C#
28 lines
669 B
C#
using Mirea.Api.Endpoint.Common.Interfaces;
|
|
using System;
|
|
|
|
namespace Mirea.Api.Endpoint.Configuration.General;
|
|
|
|
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();
|
|
}
|
|
} |