FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

crypto: add sync methods, deprecate optional callbacks by jonathanong · Pull Request #189 · nodejs/node · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 9 additions & 5 deletions lib/crypto.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,15 @@ exports.setEngine = function setEngine(id, flags) {
return binding.setEngine(id, flags);
};

exports.randomBytes = randomBytes;
exports.pseudoRandomBytes = pseudoRandomBytes;

exports.rng = randomBytes;
exports.prng = pseudoRandomBytes;
exports.randomBytes = util.deprecateSync(randomBytes, '`crypto.randomBytes(size)` is deprecated. Please use `crypto.randomBytesSync(size)` instead.');
exports.randomBytesSync = randomBytes;
exports.pseudoRandomBytes = util.deprecateSync(pseudoRandomBytes, '`crypto.pseudoRandomBytes(size)` is deprecated. Please use `crypto.pseudoRandomBytesSync(size)` instead.');
exports.pseudoRandomBytesSync = pseudoRandomBytes;

exports.rng = util.deprecateSync(randomBytes, '`crypto.rng(size)` is deprecated. Please us `crypto.rngSync(size)` instead.');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

“Please us” → “Please use” for these last two messages.

exports.rngSync = randomBytes;
exports.prng = util.deprecateSync(pseudoRandomBytes, '`crypto.prng(size)` is deprecated. Please us `crypto.prngSync(size)` instead.');
exports.prngSync = pseudoRandomBytes;


exports.getCiphers = function() {
Expand Down
36 changes: 36 additions & 0 deletions lib/util.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ exports.deprecate = function(fn, msg) {
return deprecated;
};

// Mark that the synchronous version of a function is deprecated.
// This is essentially the same as `exports.deprecate()`,
// except it only warns if the last argument is not a callback function.
exports.deprecateSync = function(fn, msg) {
// Allow for deprecating things in the process of starting up.
if (isUndefined(global.process)) {
return function() {
return exports.deprecateSync(fn, msg).apply(this, arguments);
};
}

if (process.noDeprecation === true) {
return fn;
}

var warned = false;
function deprecated() {
var cb = arguments[arguments.length - 1];
if (isFunction(cb))
return fn.apply(this, arguments);

if (!warned) {
if (process.throwDeprecation) {
throw new Error(msg);
} else if (process.traceDeprecation) {
console.trace(msg);
} else {
console.error(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}

return deprecated;
};

var debugs = {};
var debugEnviron;
Expand Down

Back | FazBrowse Home | New Git URL