Skip to content

Use ValueAsnReader in more places where it is easy to do so#125346

Merged
vcsjones merged 1 commit intodotnet:mainfrom
vcsjones:use-valueasnreader-more
Mar 10, 2026
Merged

Use ValueAsnReader in more places where it is easy to do so#125346
vcsjones merged 1 commit intodotnet:mainfrom
vcsjones:use-valueasnreader-more

Conversation

@vcsjones
Copy link
Member

@vcsjones vcsjones commented Mar 9, 2026

We could drop in ValueAsnReader in a few places where AsnReader was being used, so let's get rid of those allocations.

I am trying to spanify the XML / XSLT loader next.

Copilot AI review requested due to automatic review settings March 9, 2026 20:23
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

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

Reduces allocations in ASN.1 parsing across the crypto stack by switching several straightforward AsnReader usages to the stack-only ValueAsnReader, aligning with existing “spanified” parsing patterns used elsewhere in System.Security.Cryptography.

Changes:

  • Replaced AsnReader with ValueAsnReader in multiple X.509 and PKCS parsing paths where the reader does not need to escape.
  • Updated integer reads to use ValueAsnReader.ReadIntegerBytes() span-returning API (removing .Span accessors).
  • Updated IV/parameter parsing in PKCS managed PAL to use span-based input.

Reviewed changes

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

Show a summary per file
File Description
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509EnhancedKeyUsageExtension.cs Uses ValueAsnReader for EKU sequence decoding to avoid reader object allocation.
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ManagedCertificateFinder.cs Uses ValueAsnReader for template name ASN.1 string decoding.
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/EccKeyFormatHelper.cs Uses ValueAsnReader for ECC specified-curve parameter decoding; updates integer byte reads to spans.
src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSignature.cs Uses ValueAsnReader for DER DSA signature parsing in DsaDerToIeee.
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs Uses ValueAsnReader for IV octet-string parsing from algorithm parameters.
src/libraries/Common/src/System/Security/Cryptography/RSAAppleCrypto.macOS.cs Uses ValueAsnReader for initial sequence/tag inspection during legacy key export.
src/libraries/Common/src/System/Security/Cryptography/RSAAppleCrypto.cs Uses ValueAsnReader for initial sequence/tag inspection during key export.

You can also share your feedback on Copilot code review. Take the survey.

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