Skip to content

SignedCms add tests and reduce allocations #116400

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PranavSenthilnathan
Copy link
Member

  • Add a test verifying that NoSignature works when a cert with an unknown SPKI is supplied
  • Add TState to a couple of sites to reduce allocations
  • Use stackalloc/arraypool for an allocation

Contributes to #115578

@PranavSenthilnathan PranavSenthilnathan self-assigned this Jun 7, 2025
@Copilot Copilot AI review requested due to automatic review settings June 7, 2025 07:09
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 introduces additional tests for the SignedCms functionality with a particular focus on verifying behavior when a certificate with an unknown SPKI is supplied while also refactoring internal methods to reduce allocations.

  • Added tests to validate the NoSignature behavior with an unknown algorithm certificate
  • Updated several internal methods in SignerInfo.cs to use generic state parameters and optimized memory usage with stackalloc/arraypool techniques

Reviewed Changes

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

File Description
src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedCmsTests.cs Added tests for NoSignature behavior and default digest computation
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs Updated verify callback methods and optimized allocation using stackalloc and arraypool
Comments suppressed due to low confidence (2)

src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs:680

  • The use of the magic number 0x31 here could be clarified by either defining it as a named constant or adding a comment explaining its significance in the encoding process.
encoded[0] = 0x31;

src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/SignerInfo.cs:928

  • [nitpick] Consider renaming the tuple element '@this' to a more descriptive name (e.g., 'signerInfo') to improve code clarity in the callback methods.
static (state, contentToVerify) => state.signatureProcessor.VerifySignature(

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.

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.

3 participants