refactor(RSACryptographer): Verzeichnis und Dateiname wurden entfernt.
- Datei-Leseprozess in init-Methode entfernt.
This commit is contained in:
@@ -10,18 +10,14 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
public string Pem
|
||||
{
|
||||
get => _pem
|
||||
?? throw new InvalidOperationException($"Pem is not initialized. Please ensure that the PEM is set or properly loaded from the file. Issuer: {Issuer}, Audience: {Audience}.");
|
||||
?? throw PemIsNullException;
|
||||
init => _pem = value;
|
||||
}
|
||||
|
||||
internal bool IsPemNull => _pem is null;
|
||||
|
||||
public string? PemPath => FileName is null ? null : Path.Combine(Directory ?? string.Empty, FileName);
|
||||
|
||||
public string? Directory { get; set; }
|
||||
|
||||
public string? FileName { get; set; }
|
||||
|
||||
private InvalidOperationException PemIsNullException => new($"Pem is not initialized. Please ensure that the PEM is set or properly loaded from the file. Issuer: {Issuer}, Audience: {Audience}.");
|
||||
|
||||
public RSAEncryptionPadding Padding { get; init; } = RSAEncryptionPadding.OaepSHA256;
|
||||
|
||||
protected virtual RSA RSA { get; } = RSA.Create();
|
||||
@@ -34,24 +30,10 @@ namespace DigitalData.Core.Security.Cryptographer
|
||||
|
||||
internal void SetPem(string pem) => _pem = pem;
|
||||
|
||||
public virtual void UnableToInitPemEvent() => throw new InvalidOperationException(
|
||||
$"Pem is not initialized and pem file is null. Issuer is {Issuer} and audience {Audience}.");
|
||||
|
||||
public virtual void FileNotFoundEvent() => throw new FileNotFoundException(
|
||||
$"Pem is not initialized and pem file is not found in {PemPath}. Issuer is {Issuer} and audience {Audience}.");
|
||||
|
||||
// TODO: make file read asynchronous, consider multiple routing
|
||||
public virtual void Init()
|
||||
{
|
||||
if(_pem is null)
|
||||
{
|
||||
if(PemPath is null)
|
||||
UnableToInitPemEvent();
|
||||
if (File.Exists(PemPath))
|
||||
_pem = File.ReadAllText(PemPath);
|
||||
else
|
||||
FileNotFoundEvent();
|
||||
}
|
||||
if (_pem is null)
|
||||
throw PemIsNullException;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user