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

crypto.randomBytes documentation needs improvement #3081

Closed
brendanashworth opened this issue Sep 26, 2015 · 2 comments
Closed

crypto.randomBytes documentation needs improvement #3081

brendanashworth opened this issue Sep 26, 2015 · 2 comments
Labels
crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors.

Comments

@brendanashworth
Copy link
Contributor

The crypto.randomBytes documentation is quite confusing on whether or not the function throws on a lack of entropy. The code shows that it does, but the note below says that it does not. I'm currently under the impression that it does not throw on low entropy, so this needs to be fixed. Here is how it looks now:

crypto.randomBytes(size[, callback])

Generates cryptographically strong pseudo-random data. Usage:

// async
crypto.randomBytes(256, function(ex, buf) {
  if (ex) throw ex;
  console.log('Have %d bytes of random data: %s', buf.length, buf);
});
// sync
try {
  var buf = crypto.randomBytes(256);
  console.log('Have %d bytes of random data: %s', buf.length, buf);
} catch (ex) {
  // handle error
  // most likely, entropy sources are drained
}

NOTE: This will block if there is insufficient entropy, although it should normally never take longer than a few milliseconds. The only time when this may conceivably block is right after boot, when the whole system is still low on entropy.

Refs to: #3073 (comment) and following discussion, e5e5980, f68a116, and RAND_bytes() docs. Also #813.

@brendanashworth brendanashworth added crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. labels Sep 26, 2015
@brendanashworth brendanashworth added the good first issue Issues that are suitable for first-time contributors. label Sep 27, 2015
@brendanashworth brendanashworth changed the title doc: crypto.randomBytes documentation needs improvement crypto.randomBytes documentation needs improvement Sep 27, 2015
@JungMinu
Copy link
Member

@brendanashworth I will take care of this :)

@brendanashworth
Copy link
Contributor Author

ref: #3087

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. doc Issues and PRs related to the documentations. good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

No branches or pull requests

2 participants