Skip to content

Fix dispose pattern in PQC types #117096

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

Merged
merged 3 commits into from
Jun 30, 2025
Merged

Conversation

vcsjones
Copy link
Member

I don't think we have been following the dispose pattern correctly for a few of the PQC implementations. We should only call managed dispose methods if disposing is true.

Technically we should also be calling the base implementation, even though they do nothing right now.

This makes the dispose pattern usage more consistent with other cryptographic algorithms.

@Copilot Copilot AI review requested due to automatic review settings June 27, 2025 18:29
Copy link
Contributor

@Copilot Copilot AI left a 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 ensures that the dispose pattern in several PQC implementations follows the correct guidelines by calling managed dispose methods only when disposing is true and by invoking the base.Dispose method consistently. Key changes include:

  • Adding base.Dispose(disposing) in multiple Dispose methods.
  • Wrapping managed dispose calls with the disposing check in some implementations.
  • Standardizing the dispose pattern across different cryptographic types.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SlhDsaImplementation.OpenSsl.cs Added base.Dispose(disposing) but still missing the disposing check when calling _key?.Dispose().
src/libraries/Common/src/System/Security/Cryptography/MLKemCng.Windows.cs Added base.Dispose(disposing) but did not wrap _key.Dispose() with an if (disposing) check.
src/libraries/Common/src/System/Security/Cryptography/MLDsaImplementation.Windows.cs Added an explicit if (disposing) check before disposing _key and then calling base.Dispose(disposing).
src/libraries/Common/src/System/Security/Cryptography/MLDsaCng.Windows.cs Added an explicit if (disposing) check before disposing _key and then calling base.Dispose(disposing).

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@vcsjones vcsjones merged commit d136ec9 into dotnet:main Jun 30, 2025
81 of 87 checks passed
@vcsjones vcsjones deleted the pqc-dispose-pattern branch June 30, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants