Skip to content

Commit

Permalink
fix(bcrypt): fix runtime symbol error and update sdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Jul 2, 2024
1 parent d5231ab commit c30bc1b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions crates/bcrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
napi-ohos = { version = "*" }
napi-derive-ohos = { version = "*" }
napi-ohos = { version = "1.0.0-beta.2" }
napi-derive-ohos = { version = "1.0.0-beta.2" }
base64 = { version = "0.22" }
bcrypt = "0.15"
blowfish = { version = "0.9", features = ["bcrypt"] }
getrandom = "0.2"
global-alloc = { workspace = true }

[build-dependencies]
napi-build-ohos = { version = "*" }
napi-build-ohos = { version = "1.0.0-beta.2" }

[profile.release]
lto = true
Expand Down
1 change: 1 addition & 0 deletions crates/bcrypt/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main() {
napi_build_ohos::setup();
println!("cargo:rustc-link-lib=static=clang_rt.builtins");
}
7 changes: 7 additions & 0 deletions crates/bcrypt/package/main/module.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"module": {
"name": "@ohos-rs/bcrypt",
"type": "har",
"deviceTypes": ["default", "tablet", "2in1"]
},
}
22 changes: 18 additions & 4 deletions crates/bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ pub fn gen_salt_js(round: u32, version: Option<String>) -> Result<AsyncTask<salt
pub fn hash_sync(
input: Either<String, Buffer>,
cost: Option<u32>,
salt: Option<Buffer>,
salt: Option<Either<String, Buffer>>,
) -> Result<String> {
let salt = if let Some(salt) = salt {
let mut s = [0u8; 16];
s.copy_from_slice(salt.as_ref());
match salt {
Either::A(salt_str) => {
s.copy_from_slice(salt_str.as_bytes());
}
Either::B(salt_buf) => {
s.copy_from_slice(salt_buf.as_ref());
}
};
s
} else {
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
Expand All @@ -67,11 +74,18 @@ pub fn hash_sync(
pub fn hash(
input: Either<String, JsBuffer>,
cost: Option<u32>,
salt: Option<Buffer>,
salt: Option<Either<String,Buffer>>,
) -> Result<AsyncTask<HashTask>> {
let salt = if let Some(salt) = salt {
let mut s = [0u8; 16];
s.copy_from_slice(salt.as_ref());
match salt {
Either::A(salt_str) => {
s.copy_from_slice(salt_str.as_bytes());
}
Either::B(salt_buf) => {
s.copy_from_slice(salt_buf.as_ref());
}
};
s
} else {
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
Expand Down

0 comments on commit c30bc1b

Please sign in to comment.