Add Application configuration #11
9
Endpoint/Common/Interfaces/ISetupToken.cs
Normal file
9
Endpoint/Common/Interfaces/ISetupToken.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Mirea.Api.Endpoint.Common.Interfaces;
|
||||
|
||||
public interface ISetupToken
|
||||
{
|
||||
bool MatchToken(ReadOnlySpan<byte> token);
|
||||
void SetToken(ReadOnlySpan<byte> token);
|
||||
}
|
28
Endpoint/Configuration/General/SetupTokenService.cs
Normal file
28
Endpoint/Configuration/General/SetupTokenService.cs
Normal file
@ -0,0 +1,28 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Mirea.Api.DataAccess.Application;
|
||||
using Mirea.Api.DataAccess.Persistence;
|
||||
using Mirea.Api.Endpoint.Common.Interfaces;
|
||||
using Mirea.Api.Endpoint.Common.Services;
|
||||
using Mirea.Api.Endpoint.Configuration;
|
||||
using Mirea.Api.Endpoint.Configuration.General;
|
||||
@ -50,6 +51,7 @@ public class Program
|
||||
builder.Services.AddPersistence(builder.Configuration.Get<GeneralConfig>()?.DbSettings?.ConnectionStringSql ?? string.Empty);
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddSingleton<ISetupToken, SetupTokenService>();
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policy =>
|
||||
|
Loading…
Reference in New Issue
Block a user