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 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())));
|
private static readonly Lazy<RSAFactory<RSAFactoryParams>> LazyInstance = new(() => new(Options.Create<RSAFactoryParams>(new())));
|
||||||
|
|
||||||
public static RSAFactory<RSAFactoryParams> Static => LazyInstance.Value;
|
public static RSAFactory<RSAFactoryParams> Static => LazyInstance.Value;
|
||||||
@ -14,25 +25,7 @@ namespace DigitalData.Core.Security
|
|||||||
private readonly RSAFactoryParams _params;
|
private readonly RSAFactoryParams _params;
|
||||||
|
|
||||||
private readonly IEnumerable<string> _lowerFileTags;
|
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;
|
private readonly PbeParameters _pbeParameters;
|
||||||
|
|
||||||
public RSAFactory(IOptions<TRSAFactoryParams> options)
|
public RSAFactory(IOptions<TRSAFactoryParams> options)
|
||||||
@ -43,6 +36,7 @@ namespace DigitalData.Core.Security
|
|||||||
_pbeParameters = new PbeParameters(_params.PbeEncryptionAlgorithm, _params.PbeHashAlgorithmName, _params.PbeIterationCount);
|
_pbeParameters = new PbeParameters(_params.PbeEncryptionAlgorithm, _params.PbeHashAlgorithmName, _params.PbeIterationCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: make the validation using regex
|
||||||
public void ValidateFormatterParams(string issuer, string audience)
|
public void ValidateFormatterParams(string issuer, string audience)
|
||||||
{
|
{
|
||||||
void ValidateForbidden(string value, string paramName)
|
void ValidateForbidden(string value, string paramName)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user