script: Use CryptoAlgorithm in name fields of subtle dictionaries#43055
Merged
Conversation
We currently use `String` to store cryptographic algorithm name in subtle dictionaries in WebCrypto code. The algorithm normalization guarantees that there are only a limited number of possible strings that can be assigned to the name fields. We switch to use the `CryptoAlgorithm` enum, which contains all possible algorithm names, to represent these values. This reduces string comparison and saves a small amount of memory. The constant string `ALG_*` in `subtlecrypto.rs`, which are the recognized algorithm name for the algorithms, are also removed since they are already embedded in the `CryptoAlgorithm` enum. Testing: Refactoring. Existing tests suffice. Fixes: Part of 42579 Signed-off-by: Kingsley Yung <[email protected]>
TimvdLippe
approved these changes
Mar 6, 2026
Contributor
TimvdLippe
left a comment
There was a problem hiding this comment.
This is a lot of refactoring, but given its simplicity I will approve. Trusting on both the compiler and WPT that no mistakes were introduced. Nice cleanup!
offline-ant
pushed a commit
to offline-ant/havi
that referenced
this pull request
Jun 4, 2026
…ervo#43055) We currently use `String` to store cryptographic algorithm name in subtle dictionaries in WebCrypto code. The algorithm normalization guarantees that there are only a limited number of possible strings that can be assigned to the name fields. We switch to use the `CryptoAlgorithm` enum, which contains all possible algorithm names, to represent these values. This reduces string comparison and saves a small amount of memory. The constant string `ALG_*` in `subtlecrypto.rs`, which are the recognized algorithm name for the algorithms, are also removed since they are already embedded in the `CryptoAlgorithm` enum. Testing: Refactoring. Existing tests suffice. Fixes: Part of servo#42579 Signed-off-by: Kingsley Yung <[email protected]> (cherry picked from commit 8df3819)
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 currently use
Stringto store cryptographic algorithm name in subtle dictionaries in WebCrypto code. The algorithm normalization guarantees that there are only a limited number of possible strings that can be assigned to the name fields.We switch to use the
CryptoAlgorithmenum, which contains all possible algorithm names, to represent these values. This reduces string comparison and saves a small amount of memory.The constant string
ALG_*insubtlecrypto.rs, which are the recognized algorithm name for the algorithms, are also removed since they are already embedded in theCryptoAlgorithmenum.Testing: Refactoring. Existing tests suffice.
Fixes: Part of #42579