Files
servo/components/script
Kingsley Yung 7342ee0627 script: Properly implement supportedAlgorithms of WebCrypto (#41563)
WebCrypto API has an internal object `supportedAlgorithms`
<https://w3c.github.io/webcrypto/#dfn-supportedAlgorithms> that maps the
all supported algorithms and operations to their desired IDL dictionary
types. It is mainly used by the "normalize an algorithm" algorithm
<https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm>.
We currently implement it as a large `match` block in the
`normalize_algorithm` function.

This patch properly implements the internal object `supportedAlgorithms`
as a new enum type `SupportedAlgorithm`.

By doing so, we can reduce a lot of string comparison to enum matching,
which can be done faster. This patch also separates the dictionary
conversion away from the `match` block to make our code cleaner.
Furthermore, the `exportKey()` method can now utilize the new
`SupportedAlgorithm` to properly check against the algorithm
registration, instead of hard-coding an list of unsupported algorithms
by itself.

Testing: Refactoring. Existing tests suffice.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-12-29 06:22:24 +00:00
..
2025-10-02 07:51:19 +00:00