mirror of
https://github.com/servo/servo
synced 2026-05-12 09:56:50 +02:00
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>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -405,7 +405,7 @@ pub(crate) fn import_key(
|
||||
// set to hash and op set to digest.
|
||||
let normalized_hash = normalize_algorithm(
|
||||
cx,
|
||||
&Operation::Digest,
|
||||
Operation::Digest,
|
||||
&AlgorithmIdentifier::String(DOMString::from(hash)),
|
||||
can_gc,
|
||||
)?;
|
||||
|
||||
@@ -421,7 +421,7 @@ pub(crate) fn import_key(
|
||||
// set to hash and op set to digest.
|
||||
let normalized_hash = normalize_algorithm(
|
||||
cx,
|
||||
&Operation::Digest,
|
||||
Operation::Digest,
|
||||
&AlgorithmIdentifier::String(DOMString::from(hash)),
|
||||
can_gc,
|
||||
)?;
|
||||
|
||||
@@ -385,7 +385,7 @@ pub(crate) fn import_key(
|
||||
// set to hash and op set to digest.
|
||||
let normalized_hash = normalize_algorithm(
|
||||
cx,
|
||||
&Operation::Digest,
|
||||
Operation::Digest,
|
||||
&AlgorithmIdentifier::String(DOMString::from(hash)),
|
||||
can_gc,
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user