fix: Nullprüfungen und Initialisierung nach der Deserialisierung hinzufügen
- Nullprüfungen in `OnDeserialized` implementiert, um `Directory` und `FileName` für Decryptoren festzulegen. - `FileName` mit `FileNameFormat` dynamisch erstellt. - `TypeTagOf` verfeinert, um den richtigen Tag zu bestimmen, und Fehlerbehandlung für nicht unterstützte Kryptografietypen hinzugefügt.
This commit is contained in:
parent
fa5d0f1b26
commit
08ffe821ff
@ -1,14 +1,37 @@
|
|||||||
using DigitalData.Core.Abstractions.Security;
|
using DigitalData.Core.Abstractions.Security;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace DigitalData.Core.Security.Config
|
namespace DigitalData.Core.Security.Config
|
||||||
{
|
{
|
||||||
public class AsymCryptParams : RSAFactoryParams
|
public class AsymCryptParams : RSAFactoryParams
|
||||||
{
|
{
|
||||||
|
public string Directory { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 0: Issuer - 1: Audience - 2: Type tag - 3: Version
|
||||||
|
/// </summary>
|
||||||
|
public string FileNameFormat { get; init; } = "{0}_-_{1}_-_{2}_-_{3}.pem";
|
||||||
|
|
||||||
|
public string EncryptorTag { get; init; } = "public";
|
||||||
|
|
||||||
|
public string DecryptorTag { get; init; } = "private";
|
||||||
|
|
||||||
|
public string EncryptedDecryptorTag { get; init; } = "enc-private";
|
||||||
|
|
||||||
public IEnumerable<IRSADecryptor> Decryptors { get; init; } = new List<IRSADecryptor>();
|
public IEnumerable<IRSADecryptor> Decryptors { get; init; } = new List<IRSADecryptor>();
|
||||||
|
|
||||||
public IEnumerable<IRSAEncryptor> Encryptors { get; init; } = new List<IRSAEncryptor>();
|
public IEnumerable<IRSAEncryptor> Encryptors { get; init; } = new List<IRSAEncryptor>();
|
||||||
|
|
||||||
|
private string TypeTagOf(IRSACryptographer crypt)
|
||||||
|
{
|
||||||
|
if (crypt is IRSAEncryptor)
|
||||||
|
return EncryptorTag;
|
||||||
|
else if (crypt is IRSADecryptor decryptor)
|
||||||
|
return decryptor.Encrypt ? EncryptedDecryptorTag : DecryptorTag;
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Unknown cryptographer type. The crypt parameter must be either IRSAEncryptor or IRSADecryptor.");
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnDeserialized()
|
public override void OnDeserialized()
|
||||||
{
|
{
|
||||||
base.OnDeserialized();
|
base.OnDeserialized();
|
||||||
@ -16,8 +39,16 @@ namespace DigitalData.Core.Security.Config
|
|||||||
foreach (var decryptor in Decryptors)
|
foreach (var decryptor in Decryptors)
|
||||||
{
|
{
|
||||||
// set default path
|
// set default path
|
||||||
if(decryptor.Pem is null && decryptor.FileName is null)
|
if (decryptor.Pem is null)
|
||||||
dec
|
{
|
||||||
|
decryptor.Directory ??= Directory;
|
||||||
|
decryptor.FileName ??= string.Format(
|
||||||
|
FileNameFormat,
|
||||||
|
decryptor.Issuer,
|
||||||
|
decryptor.Audience,
|
||||||
|
TypeTagOf(decryptor),
|
||||||
|
Secrets.Version);
|
||||||
|
}
|
||||||
|
|
||||||
decryptor.Init();
|
decryptor.Init();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user