- 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.
57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
using DigitalData.Core.Abstractions.Security;
|
|
|
|
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()
|
|
{
|
|
base.OnDeserialized();
|
|
|
|
foreach (var decryptor in Decryptors)
|
|
{
|
|
// set default path
|
|
if (decryptor.Pem is null)
|
|
{
|
|
decryptor.Directory ??= Directory;
|
|
decryptor.FileName ??= string.Format(
|
|
FileNameFormat,
|
|
decryptor.Issuer,
|
|
decryptor.Audience,
|
|
TypeTagOf(decryptor),
|
|
Secrets.Version);
|
|
}
|
|
|
|
decryptor.Init();
|
|
}
|
|
}
|
|
}
|
|
} |