-
Notifications
You must be signed in to change notification settings - Fork 5k
Dispose all resources used in CmsSignature #115666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dispose all resources used in CmsSignature #115666
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the handling of signing keys in CmsSignature to ensure all disposable resources are consistently disposed. The changes include:
- Introducing a new helper method GetSigningKey to centralize key retrieval and disposal.
- Updating the implementations for RSA, DSA, ECDsa, and SlhDsa to use the new helper method.
- Minor renaming adjustments for clarity in key-related parameters.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
CmsSignature.cs | Added GetSigningKey helper to encapsulate key retrieval and disposal logic. |
CmsSignature.SlhDsa.cs | Updated signing logic to use GetSigningKey for consistent disposal. |
CmsSignature.RSA.cs | Refactored signing and verification for RSA to leverage GetSigningKey and ensure proper resource disposal. |
CmsSignature.ECDsa.cs | Replaced direct disposal of keys with GetSigningKey and adjusted parameter naming. |
CmsSignature.DSA.cs | Updated DSA signing to use GetSigningKey for improved resource management. |
.../System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.RSA.cs
Show resolved
Hide resolved
...ystem.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.ECDsa.cs
Show resolved
Hide resolved
.../System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.DSA.cs
Show resolved
Hide resolved
...ystem.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.ECDsa.cs
Show resolved
Hide resolved
.../System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.RSA.cs
Outdated
Show resolved
Hide resolved
...stem.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.SlhDsa.cs
Show resolved
Hide resolved
...ries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.cs
Outdated
Show resolved
Hide resolved
certificate.GetDSAPublicKey(); | ||
|
||
if (dsa == null) | ||
using (GetSigningKey(key, certificate, silent, DSACertificateExtensions.GetDSAPublicKey, out DSA? dsa)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Using DSACertificateExtensions.GetDSAPublicKey
is more succinct, but the main reason for changing to this is because I was getting errors due to dotnet/roslyn-analyzers#4282.
Dispose keys in CmsSignature more consistently.
Contributes to #115578