refactor: code restructuring
This commit is contained in:
28
Endpoint/Configuration/Validation/SetupTokenService.cs
Normal file
28
Endpoint/Configuration/Validation/SetupTokenService.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Mirea.Api.Endpoint.Common.Interfaces;
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Configuration.ConfigurationChecks;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user