refactor: Aktualisierung der DefaultRSAKeyNameFormatter Signatur und Logik in RSAFactory
- Die Methode `DefaultRSAKeyNameFormatter` wurde geändert, um einen `visibilityTag`- und `expiration`-Parameter aufzunehmen. - Redundante bedingte Logik für das Anhängen von Tags wurde entfernt und der Formatter für bessere Lesbarkeit und Skalierbarkeit umstrukturiert. - Gewährleistung der Abwärtskompatibilität mit der Versionierung durch bedingte Behandlung von `passwordVersion`.
This commit is contained in:
parent
5991444efd
commit
3aa5ad782f
@ -7,6 +7,17 @@ namespace DigitalData.Core.Security
|
||||
{
|
||||
public class RSAFactory<TRSAFactoryParams> : IRSAFactory<TRSAFactoryParams> where TRSAFactoryParams : RSAFactoryParams
|
||||
{
|
||||
public static string DefaultRSAKeyNameFormatter(string separator, string issuer, string audience, string visibilityTag, DateOnly expiration, Version? passwordVersion = null)
|
||||
{
|
||||
var sb = new StringBuilder(issuer.Length + audience.Length + separator.Length * 2 + 20);
|
||||
sb.Append(issuer).Append(separator).Append(audience).Append(separator).Append(visibilityTag).Append(separator).Append(expiration);
|
||||
|
||||
if (passwordVersion is not null)
|
||||
sb.Append(separator).Append(passwordVersion);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static readonly Lazy<RSAFactory<RSAFactoryParams>> LazyInstance = new(() => new(Options.Create<RSAFactoryParams>(new())));
|
||||
|
||||
public static RSAFactory<RSAFactoryParams> Static => LazyInstance.Value;
|
||||
@ -15,24 +26,6 @@ namespace DigitalData.Core.Security
|
||||
|
||||
private readonly IEnumerable<string> _lowerFileTags;
|
||||
|
||||
//TODO: make the validation using regex
|
||||
public static string DefaultRSAKeyNameFormatter(string separator, string issuer, string audience, string encryptedPrivateKeyFileTag, string privateKeyFileTag, string publicKeyFileTag, bool isPrivate = true, Version? passwordVersion = null)
|
||||
{
|
||||
var sb = new StringBuilder(issuer.Length + audience.Length + separator.Length * 2 + 20);
|
||||
sb.Append(issuer).Append(separator).Append(audience).Append(separator);
|
||||
|
||||
if (passwordVersion is null && isPrivate)
|
||||
sb.Append(privateKeyFileTag);
|
||||
else if (isPrivate)
|
||||
sb.Append(encryptedPrivateKeyFileTag).Append(separator).Append(passwordVersion);
|
||||
else if (passwordVersion is null)
|
||||
sb.Append(publicKeyFileTag);
|
||||
else
|
||||
sb.Append(publicKeyFileTag).Append(separator).Append(passwordVersion);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private readonly PbeParameters _pbeParameters;
|
||||
|
||||
public RSAFactory(IOptions<TRSAFactoryParams> options)
|
||||
@ -43,6 +36,7 @@ namespace DigitalData.Core.Security
|
||||
_pbeParameters = new PbeParameters(_params.PbeEncryptionAlgorithm, _params.PbeHashAlgorithmName, _params.PbeIterationCount);
|
||||
}
|
||||
|
||||
//TODO: make the validation using regex
|
||||
public void ValidateFormatterParams(string issuer, string audience)
|
||||
{
|
||||
void ValidateForbidden(string value, string paramName)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user