-
Notifications
You must be signed in to change notification settings - Fork 10
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
lib,build: use Web Crypto API in browser #360
Conversation
67d77f9
to
dc85ae8
Compare
lib/common-crypto-fallback.js
Outdated
@@ -0,0 +1,42 @@ | |||
'use strict'; | |||
|
|||
/*eslint-env browser*/ |
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.
nit: /* eslint-env browser */
lib/common-crypto-fallback.js
Outdated
|
||
/*eslint-env browser*/ | ||
|
||
// Browser adapter for required functions from node.js crypto module. |
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.
nit: Node.js
lib/common-crypto-fallback.js
Outdated
crypto = { | ||
randomBytes(count) { | ||
const buf = Buffer.alloc(count); | ||
for (let i = 0; i < count; i++) { |
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.
Not that essential as it's only three lines of code, but the function below could be reused here.
webpack.config.js
Outdated
@@ -35,6 +35,6 @@ module.exports = { | |||
net: false, | |||
tls: false, | |||
// TODO: support WebCrypto API in lib/common.js and uncomment 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.
This line is no longer necessary.
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
); | ||
crypto.randomFillSync = (buf) => { | ||
for (let i = 0; i < buf.length; i++) { | ||
buf[i] = Math.floor(0x100 * Math.random()); |
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.
Just a nit but maybe 256 instead of 0x100? Should be clearer.
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.
@lundibundi, I've specifically used 0x100
to emphasize the fact that the resulting number must fit into a byte.
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.
I don't see any difference one way or the other. 0x100
seems fine as it is, but no strong opinion.
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.
Same here, it's just that to me 256 is clearer (the fact that its a byte) than 0x100.
52eec64
to
3118289
Compare
PR-URL: #360 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Landed in d77434b. |
PR-URL: #360 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
No description provided.