Update IFingerprintManager
This commit is contained in:
@@ -75,7 +75,7 @@ namespace Akari.Prototype.Server.Cli.Commands
|
||||
table.AddColumn(new TableColumn("[bold yellow]Name[/]").LeftAligned());
|
||||
table.AddColumn(new TableColumn("[bold blue]Token[/]").LeftAligned());
|
||||
|
||||
foreach (var (name, hash) in _fingerprintManager.FingerprintsHash)
|
||||
foreach (var (name, hash) in _fingerprintManager)
|
||||
{
|
||||
table.AddRow($"[silver]{name}[/]", $"[grey]{hash}[/]");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using Isopoh.Cryptography.Argon2;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -60,13 +61,50 @@ namespace Akari.Prototype.Server.Services
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(_fingerprintsHash));
|
||||
}
|
||||
|
||||
public bool Add(string name, string hash)
|
||||
{
|
||||
if (_fingerprintsHash.TryAdd(name, hash))
|
||||
{
|
||||
SaveFingerprints();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Contains(string name)
|
||||
{
|
||||
return _fingerprintsHash.ContainsKey(name);
|
||||
}
|
||||
|
||||
public bool Remove(string name)
|
||||
{
|
||||
var result = _fingerprintsHash.Remove(name);
|
||||
if (_fingerprintsHash.Remove(name))
|
||||
{
|
||||
SaveFingerprints();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Set(string name, string hash)
|
||||
{
|
||||
_fingerprintsHash[name] = hash;
|
||||
|
||||
SaveFingerprints();
|
||||
}
|
||||
|
||||
return result;
|
||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||
{
|
||||
return _fingerprintsHash.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void VerifyFingerprint(string name, string token)
|
||||
|
||||
@@ -6,11 +6,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server.Services
|
||||
{
|
||||
public interface IFingerprintManager
|
||||
public interface IFingerprintManager : IEnumerable<KeyValuePair<string, string>>
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, string>> FingerprintsHash { get; }
|
||||
|
||||
bool Add(string name, string hash);
|
||||
bool Contains(string name);
|
||||
bool Remove(string name);
|
||||
void Set(string name, string hash);
|
||||
|
||||
void VerifyFingerprint(string name, string token);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user