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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/runtime/crypto/PBKDF2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ impl PBKDF2 {
);
}

let slice = arg4.to_slice(global_this)?;
'invalid: {
let slice = arg4.to_slice(global_this)?;
match evp::lookup_ignore_case(slice.slice()) {
Some(alg) => match alg {
Algorithm::Shake128 | Algorithm::Shake256 => break 'invalid,
Expand All @@ -171,18 +171,12 @@ impl PBKDF2 {
}
}

if !global_this.has_exception() {
let slice = arg4.to_slice(global_this)?;
let name = slice.slice();
return Err(global_this
.err(
bun_jsc::ErrorCode::CRYPTO_INVALID_DIGEST,
format_args!("Invalid digest: {}", bstr::BStr::new(name)),
)
.throw());
// `slice` drops here.
}
return Err(bun_jsc::JsError::Thrown);
return Err(global_this
.err(
bun_jsc::ErrorCode::CRYPTO_INVALID_DIGEST,
format_args!("Invalid digest: {}", bstr::BStr::new(slice.slice())),
)
.throw());
};

let mut out = PBKDF2 {
Expand Down
28 changes: 11 additions & 17 deletions src/runtime/crypto/PasswordObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::Write as _;
use bun_core::ZigString;
use bun_io::KeepAlive;
use bun_jsc::{
self as jsc, CallFrame, JSFunction, JSGlobalObject, JSValue, JsError, JsResult, WorkPoolTask,
self as jsc, CallFrame, JSFunction, JSGlobalObject, JSValue, JsResult, WorkPoolTask,
};
// `bun_jsc::{AnyTask, ConcurrentTask, EventLoop}` are *modules* (re-exported from
// `bun_event_loop`); pull the concrete types out by name.
Expand Down Expand Up @@ -836,14 +836,11 @@ pub(crate) fn js_password_object_verify(
algorithm = match algorithm_from_zig_string(&algorithm_string) {
Some(a) => Some(a),
None => {
if !global_object.has_exception() {
return Err(global_object.throw_invalid_argument_type(
"verify",
"algorithm",
UNKNOWN_PASSWORD_ALGORITHM_MESSAGE,
));
}
return Err(JsError::Thrown);
return Err(global_object.throw_invalid_argument_type(
"verify",
"algorithm",
UNKNOWN_PASSWORD_ALGORITHM_MESSAGE,
));
}
};
}
Expand Down Expand Up @@ -917,14 +914,11 @@ pub(crate) fn js_password_object_verify_sync(
algorithm = match algorithm_from_zig_string(&algorithm_string) {
Some(a) => Some(a),
None => {
if !global_object.has_exception() {
return Err(global_object.throw_invalid_argument_type(
"verify",
"algorithm",
UNKNOWN_PASSWORD_ALGORITHM_MESSAGE,
));
}
return Ok(JSValue::ZERO);
return Err(global_object.throw_invalid_argument_type(
"verify",
"algorithm",
UNKNOWN_PASSWORD_ALGORITHM_MESSAGE,
));
}
};
}
Expand Down
Loading