Repository navigation
node:crypto: refuse both names of a scrypt option when the second is read, with a bindgen exclusive member
#47430
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
c4d60b6
ffd8155
298fedf
803b2f6
436a706
30383ae
2a25c79
aba698b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -707,16 +707,6 @@ pub(crate) struct Argon2<Bytes> { | |
|
|
||
| impl Scrypt { | ||
| fn new(global: &JSGlobalObject, keylen: u32, options: &ScryptOptions) -> JsResult<Self> { | ||
|
Comment on lines
713
to
714
Contributor
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.
|
||
| if options.n.is_some() && options.cost.is_some() { | ||
| return Err(global.throw_incompatible_option_pair(b"N", b"cost")); | ||
| } | ||
| if options.r.is_some() && options.block_size.is_some() { | ||
| return Err(global.throw_incompatible_option_pair(b"r", b"blockSize")); | ||
| } | ||
| if options.p.is_some() && options.parallelization.is_some() { | ||
| return Err(global.throw_incompatible_option_pair(b"p", b"parallelization")); | ||
| } | ||
|
|
||
| const N_DEFAULT: u32 = 16384; | ||
| const R_DEFAULT: u32 = 8; | ||
| const P_DEFAULT: u32 = 1; | ||
|
|
@@ -725,9 +715,9 @@ impl Scrypt { | |
| let or_default = |value: Option<u32>, default| value.filter(|&n| n != 0).unwrap_or(default); | ||
|
|
||
| let ctx = Scrypt { | ||
| n: or_default(options.n.or(options.cost), N_DEFAULT), | ||
| r: or_default(options.r.or(options.block_size), R_DEFAULT), | ||
| p: or_default(options.p.or(options.parallelization), P_DEFAULT), | ||
| n: or_default(options.n, N_DEFAULT), | ||
| r: or_default(options.r, R_DEFAULT), | ||
| p: or_default(options.p, P_DEFAULT), | ||
| maxmem: options | ||
| .maxmem | ||
| .filter(|&maxmem| maxmem != 0) | ||
|
|
@@ -1070,8 +1060,15 @@ pub(crate) fn scrypt_with_defaults<'a>( | |
| password: StringOrJsBytes<'a>, | ||
| salt: StringOrJsBytes<'a>, | ||
| keylen: u32, | ||
| callback: JsLocal<'a, Callable>, | ||
| callback: JsLocal<'a>, | ||
| ) -> JsResult<()> { | ||
| let Some(callback) = callback.as_callable() else { | ||
| return Err(cx.global().throw_invalid_argument_type_value( | ||
| b"callback", | ||
| b"function", | ||
| callback.to_js(), | ||
| )); | ||
| }; | ||
| scrypt( | ||
| cx, | ||
| password, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Which code of scrypt's fourth argument runs when it is no function and no fifth follows: it is the callback, and it is described. | ||
| import { scrypt } from "node:crypto"; | ||
| function run() { | ||
| const box = { field: 1 }; | ||
| let count = 0; | ||
| const fourth = { | ||
| get constructor() { | ||
| count++; | ||
| box.field = 2; | ||
| return { name: "Named" }; | ||
| }, | ||
| }; | ||
| let message = "no error"; | ||
| try { | ||
| scrypt("a", "b", 8, fourth); | ||
| } catch (error) { | ||
| message = error.message; | ||
| } | ||
| console.log("scrypt callback |", message, "|", count, box.field); | ||
| } | ||
| run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Which code of a refused member of scrypt's options runs when a callback follows: the callee is known, and the values are local. | ||
| import { scrypt } from "node:crypto"; | ||
| function run() { | ||
| const box = { field: 1 }; | ||
| let count = 0; | ||
| const member = { | ||
| get constructor() { | ||
| count++; | ||
| box.field = 2; | ||
| return { name: "Named" }; | ||
| }, | ||
| }; | ||
| let message = "no error"; | ||
| try { | ||
| scrypt("a", "b", 8, { N: member }, () => {}); | ||
| } catch (error) { | ||
| message = error.message; | ||
| } | ||
| console.log("scrypt option |", message, "|", count, box.field); | ||
| } | ||
| run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // scrypt with an undefined fifth argument takes the fourth as the callback and reads no option of it. | ||
| import { scrypt } from "node:crypto"; | ||
| function run() { | ||
| const box = { field: 1 }; | ||
| let count = 0; | ||
| const options = { | ||
| get N() { | ||
| count++; | ||
| box.field = 2; | ||
| return 2; | ||
| }, | ||
| get cost() { | ||
| count++; | ||
| box.field = 3; | ||
| return "x"; | ||
| }, | ||
| }; | ||
| let message = "no error"; | ||
| try { | ||
| scrypt("a", "b", 8, options, undefined); | ||
| } catch (error) { | ||
| message = error.code + " " + error.message; | ||
| } | ||
| console.log("scrypt fifth undefined |", message, "|", count, box.field); | ||
| } | ||
| run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // scrypt refuses both names of an option when it reads the second, before it reads a later one and before it looks at the callback. | ||
| import { scrypt } from "node:crypto"; | ||
| function run() { | ||
| const read = []; | ||
| const options = { | ||
| get N() { | ||
| read.push("N"); | ||
| return 2; | ||
| }, | ||
| get cost() { | ||
| read.push("cost"); | ||
| return "x"; | ||
| }, | ||
| get r() { | ||
| read.push("r"); | ||
| return 1; | ||
| }, | ||
| }; | ||
| let message = "no error"; | ||
| try { | ||
| scrypt("a", "b", 8, options, 5); | ||
| } catch (error) { | ||
| message = error.code + " " + error.message; | ||
| } | ||
| console.log("scrypt pair |", message, "|", read.join()); | ||
| } | ||
| run(); |
Uh oh!
There was an error while loading. Please reload this page.