Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/Sign.SignatureProviders.TrustedSigning/RSATrustedSigning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class RSATrustedSigning : RSA
private readonly CertificateProfileClient _client;
private readonly string _accountName;
private readonly string _certificateProfileName;
private readonly X509Certificate2 _certificate;
private readonly RSA _rsaPublicKey;

public RSATrustedSigning(
CertificateProfileClient client,
Expand All @@ -26,11 +26,18 @@ public RSATrustedSigning(
_client = client;
_accountName = accountName;
_certificateProfileName = certificateProfileName;
_certificate = certificate;
_rsaPublicKey = certificate.GetRSAPublicKey()!;
}

private RSA PublicKey
=> _certificate.GetRSAPublicKey()!;
protected override void Dispose(bool disposing)
{
if (disposing)
{
_rsaPublicKey.Dispose();
}

base.Dispose(disposing);
}

public override RSAParameters ExportParameters(bool includePrivateParameters)
{
Expand All @@ -39,7 +46,7 @@ public override RSAParameters ExportParameters(bool includePrivateParameters)
throw new NotSupportedException();
}

return PublicKey.ExportParameters(false);
return _rsaPublicKey.ExportParameters(false);
}

public override void ImportParameters(RSAParameters parameters)
Expand All @@ -55,7 +62,7 @@ public override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RS
}

public override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
=> PublicKey.VerifyHash(hash, signature, hashAlgorithm, padding);
=> _rsaPublicKey.VerifyHash(hash, signature, hashAlgorithm, padding);

protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<X509Certificate2> GetCertificateAsync(CancellationToken cancel

public async Task<RSA> GetRsaAsync(CancellationToken cancellationToken)
{
X509Certificate2 certificate = await GetCertificateAsync(cancellationToken);
using X509Certificate2 certificate = await GetCertificateAsync(cancellationToken);
return new RSATrustedSigning(_client, _accountName, _certificateProfileName, certificate);
}
}
Expand Down