Skip to content

Commit 46ce2a9

Browse files
authored
Merge pull request #99 from napi-rs/upgrade-napi
chore: upgrade napi-rs to 0.4.7
2 parents 8bd5dbb + ae0b0a5 commit 46ce2a9

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,24 @@ jobs:
234234
- name: Run simple tests
235235
run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs node:${{ matrix.node }}-alpine sh -c "node ./scripts/simple-tests.js"
236236

237+
dependabot:
238+
needs:
239+
- test_musl_binding
240+
- test_binding
241+
runs-on: ubuntu-latest
242+
steps:
243+
- name: auto-merge
244+
uses: ridedott/dependabot-auto-merge-action@master
245+
with:
246+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
247+
237248
publish:
238249
name: Publish
239250
if: "startsWith(github.event.head_commit.message, 'chore(release): publish')"
240251
runs-on: ubuntu-latest
241-
needs: test_binding
252+
needs:
253+
- test_binding
254+
- test_musl_binding
242255

243256
steps:
244257
- uses: actions/checkout@v2

packages/bcrypt/src/hash_task.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ use napi::{Env, Error, JsBuffer, JsString, Result, Status, Task};
33
use crate::lib_bcrypt::hash;
44

55
pub struct HashTask {
6-
buf: JsBuffer,
6+
buf: &'static [u8],
77
cost: u32,
88
}
99

1010
impl HashTask {
1111
pub fn new(buf: JsBuffer, cost: u32) -> HashTask {
12-
HashTask { buf, cost }
12+
HashTask {
13+
buf: buf.data,
14+
cost,
15+
}
1316
}
1417

1518
#[inline]
16-
pub fn hash(buf: JsBuffer, cost: u32) -> Result<String> {
19+
pub fn hash(buf: &[u8], cost: u32) -> Result<String> {
1720
hash(buf, cost).map_err(|_| Error::from_status(Status::GenericFailure))
1821
}
1922
}

packages/bcrypt/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn js_salt(ctx: CallContext) -> Result<JsString> {
5858
fn js_hash(ctx: CallContext) -> Result<JsString> {
5959
let password = ctx.get::<JsBuffer>(0)?;
6060
let cost = ctx.get::<JsNumber>(1)?;
61-
let result = HashTask::hash(password, cost.try_into()?)?;
61+
let result = HashTask::hash(&password, cost.try_into()?)?;
6262
ctx.env.create_string(result.as_str())
6363
}
6464

@@ -74,7 +74,7 @@ fn js_async_hash(ctx: CallContext) -> Result<JsObject> {
7474
fn js_verify(ctx: CallContext) -> Result<JsBoolean> {
7575
let password = ctx.get::<JsBuffer>(0)?;
7676
let hash = ctx.get::<JsBuffer>(1)?;
77-
let result = VerifyTask::verify(password, hash)
77+
let result = VerifyTask::verify(&password, &hash)
7878
.map_err(|e| Error::new(Status::GenericFailure, format!("{}", e)))?;
7979
ctx.env.get_boolean(result)
8080
}

packages/bcrypt/src/verify_task.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ use crate::lib_bcrypt::verify;
44
use napi::{Env, Error, JsBoolean, JsBuffer, Result, Status, Task};
55

66
pub struct VerifyTask {
7-
password: JsBuffer,
8-
hash: JsBuffer,
7+
password: &'static [u8],
8+
hash: &'static [u8],
99
}
1010

1111
impl VerifyTask {
1212
pub fn new(password: JsBuffer, hash: JsBuffer) -> VerifyTask {
13-
Self { password, hash }
13+
Self {
14+
password: password.data,
15+
hash: hash.data,
16+
}
1417
}
1518

1619
#[inline]
17-
pub fn verify(password: JsBuffer, hash: JsBuffer) -> Result<bool> {
20+
pub fn verify(password: &[u8], hash: &[u8]) -> Result<bool> {
1821
verify(
1922
&password,
2023
str::from_utf8(&hash).map_err(|_| Error::from_status(Status::StringExpected))?,

0 commit comments

Comments
 (0)