-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(ext/crypto): import JWK key for HMAC #11716
Conversation
if (keyUsages.length == 0) { | ||
throw new DOMException("Key usage is empty", "SyntaxError"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the spec say to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://w3c.github.io/webcrypto/#SubtleCrypto-method-importKey (importKey Step 9)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but caveat emptor, I'm not a JWK expert.
ext/crypto/00_crypto.js
Outdated
StringPrototypeSplit( | ||
atob( | ||
StringPrototypeReplace( | ||
StringPrototypeReplace(key, /\-/g, "+"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using split()
and replace()
has the (global, user visible) side effect of clobbering RegExp.$_
, etc.
(Aside: I also feel this code is really hard to read.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@littledivy Can you split this across multiple lines rather than nesting these calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (also made it a bit more readable)
// 7. | ||
if ( | ||
normalizedAlgorithm.length > length || | ||
normalizedAlgorithm.length <= (length - 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks kind of weird to me. length === data.byteLength * 8
so is this trying to say if (length !== normalizedAlgoritm.length)
in a roundabout way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
Towards #11690