Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(extensions/crypto): implement subtle.digest #10796

Merged

Conversation

caspervonb
Copy link
Contributor

@caspervonb caspervonb commented May 30, 2021

Superceedes #9069

Co-authored-by: Yacine Hmito yacinehmito@users.noreply.github.com

@caspervonb caspervonb changed the title Implement crypto.subtle.digest WIP: feat(extensions/crypto): implement subtle.digest May 30, 2021
extensions/crypto/01_crypto.js Outdated Show resolved Hide resolved
@caspervonb caspervonb changed the title WIP: feat(extensions/crypto): implement subtle.digest feat(extensions/crypto): implement subtle.digest Jun 2, 2021
@bartlomieju bartlomieju added this to the 1.11.0 milestone Jun 3, 2021
Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this is being picked up again, thanks Casper!

Comment on lines +63 to +65
const registeredAlgorithms = supportedAlgorithms[op];
const algorithmName = Object.keys(registeredAlgorithms)
.find((key) => key.toLowerCase() == initialAlgorithm.name.toLowerCase());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not thrilled by how roundabout and complicated this approach is. Could simply be:

// Should match op_crypto_subtle_digest() in extensions/crypto/lib.rs 
function digestToId(name) {
  switch (name) {
    case "SHA-1": return 0;
    case "SHA-256": return 1;
    case "SHA-384": return 2;
    case "SHA-512": return 3;
  }
  throw new DOMException(/* ... */);
}

name = name.toUpperCase();
const id = digestToId(name);
const normalizedAlgorithm = { name };
// etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial pass was like that, now the whole normalisation thing follows the spec very literally

extensions/crypto/lib.rs Outdated Show resolved Hide resolved

algorithm = webidl.converters.AlgorithmIdentifier(algorithm, {
context: "Argument 1",
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for seeing this through :-)

@lucacasonato lucacasonato merged commit 3f9187c into denoland:main Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants