using DigitalData.Core.Abstractions.Security; namespace DigitalData.Core.Security.Config { public class AsymCryptParams : RSAFactoryParams { public string Directory { get; init; } = string.Empty; /// /// 0: Issuer - 1: Audience - 2: Type tag - 3: Version /// 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 Decryptors { get; init; } = new List(); public IEnumerable Encryptors { get; init; } = new List(); 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(); var cryptographers = Encryptors.Cast().Concat(Decryptors.Cast()); foreach (var crypt in cryptographers) { // set default path if (crypt.Pem is null) { crypt.Directory ??= Directory; crypt.FileName ??= string.Format( FileNameFormat, crypt.Issuer, crypt.Audience, TypeTagOf(crypt), Secrets.Version); } crypt.Init(); } } } }