Use ValueAsnReader in more places where it is easy to do so#125346
Merged
vcsjones merged 1 commit intodotnet:mainfrom Mar 10, 2026
Merged
Use ValueAsnReader in more places where it is easy to do so#125346vcsjones merged 1 commit intodotnet:mainfrom
vcsjones merged 1 commit intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
Contributor
There was a problem hiding this comment.
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
AsnReaderwithValueAsnReaderin 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.Spanaccessors). - 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.
bartonjs
approved these changes
Mar 9, 2026
This was referenced Mar 10, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.