-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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: add scrypt() and scryptSync() methods #20816
Changes from 1 commit
58176e3
371103d
c188cc5
078bb0f
f1d9c7d
5691bdf
d669251
59ace57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Factor out some common code. The `checkUint()` function will also be used in a follow-up commit that adds scrypt support to core. PR-URL: #20816 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ const { | |
const { | ||
ERR_CRYPTO_ENGINE_UNKNOWN, | ||
ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH, | ||
ERR_INVALID_ARG_TYPE | ||
ERR_INVALID_ARG_TYPE, | ||
ERR_OUT_OF_RANGE, | ||
} = require('internal/errors').codes; | ||
const { Buffer } = require('buffer'); | ||
const { | ||
|
@@ -25,6 +26,9 @@ const { | |
const { | ||
isArrayBufferView | ||
} = require('internal/util/types'); | ||
const { | ||
INT_MAX | ||
} = process.binding('constants').crypto; | ||
|
||
var defaultEncoding = 'buffer'; | ||
|
||
|
@@ -84,6 +88,7 @@ function timingSafeEqual(buf1, buf2) { | |
} | ||
|
||
function checkIsArrayBufferView(name, buffer) { | ||
buffer = toBuf(buffer); | ||
if (!isArrayBufferView(buffer)) { | ||
throw new ERR_INVALID_ARG_TYPE( | ||
name, | ||
|
@@ -94,8 +99,19 @@ function checkIsArrayBufferView(name, buffer) { | |
return buffer; | ||
} | ||
|
||
function checkIsUint(name, value, errmsg = `>= 0 && <= ${INT_MAX}`) { | ||
if (typeof value !== 'number') | ||
throw new ERR_INVALID_ARG_TYPE(name, 'number', value); | ||
|
||
if (value < 0 || !Number.isInteger(value) || value > INT_MAX) | ||
throw new ERR_OUT_OF_RANGE(name, errmsg, value); | ||
|
||
return value; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validateInt32 doesn't do quite the same thing but take a look at the second-to-last commit. This is with #20816 (comment) in mind. |
||
|
||
module.exports = { | ||
checkIsArrayBufferView, | ||
checkIsUint, | ||
getCiphers, | ||
getCurves, | ||
getDefaultEncoding, | ||
|
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’m not sure we’d actually have to consider this semver-major anymore.