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,13 +1,36 @@
|
||||
using DigitalData.Core.Abstractions.Security;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace DigitalData.Core.Security.Config
|
||||
{
|
||||
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<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()
|
||||
{
|
||||
@ -16,8 +39,16 @@ namespace DigitalData.Core.Security.Config
|
||||
foreach (var decryptor in Decryptors)
|
||||
{
|
||||
// set default path
|
||||
if(decryptor.Pem is null && decryptor.FileName is null)
|
||||
dec
|
||||
if (decryptor.Pem is null)
|
||||
{
|
||||
decryptor.Directory ??= Directory;
|
||||
decryptor.FileName ??= string.Format(
|
||||
FileNameFormat,
|
||||
decryptor.Issuer,
|
||||
decryptor.Audience,
|
||||
TypeTagOf(decryptor),
|
||||
Secrets.Version);
|
||||
}
|
||||
|
||||
decryptor.Init();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user