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

lib,build: use Web Crypto API in browser #360

Closed
wants to merge 1 commit into from

Conversation

belochub
Copy link
Member

@belochub belochub commented Aug 7, 2018

No description provided.

@@ -0,0 +1,42 @@
'use strict';

/*eslint-env browser*/
Copy link
Member

Choose a reason for hiding this comment

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

nit: /* eslint-env browser */


/*eslint-env browser*/

// Browser adapter for required functions from node.js crypto module.
Copy link
Member

Choose a reason for hiding this comment

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

nit: Node.js

crypto = {
randomBytes(count) {
const buf = Buffer.alloc(count);
for (let i = 0; i < count; i++) {
Copy link
Member

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.

@@ -35,6 +35,6 @@ module.exports = {
net: false,
tls: false,
// TODO: support WebCrypto API in lib/common.js and uncomment this
Copy link
Member

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.

@aqrln aqrln added the lib label Aug 7, 2018
Copy link
Member

@lundibundi lundibundi left a 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());
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

belochub added a commit that referenced this pull request Aug 8, 2018
PR-URL: #360
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@belochub
Copy link
Member Author

belochub commented Aug 8, 2018

Landed in d77434b.

@belochub belochub closed this Aug 8, 2018
@belochub belochub deleted the use-browser-web-crypto-api branch August 8, 2018 21:35
belochub added a commit that referenced this pull request Aug 30, 2018
PR-URL: #360
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@belochub belochub mentioned this pull request Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants