Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-feature=+sse4.2"]
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+sse4.2"]
[target.x86_64-apple-darwin]
rustflags = ["-C", "target-feature=+sse4.2"]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
8 changes: 5 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: >-
set -e &&
rustup target add x86_64-unknown-linux-gnu &&
yarn lerna exec "yarn build --target x86_64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix &&
strip packages/*/*.node
- host: ubuntu-latest
Expand All @@ -59,8 +60,9 @@ jobs:
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: |
yarn lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
build: >-
rustup target add aarch64-unknown-linux-gnu &&
yarn lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix &&
llvm-strip packages/*/*.node
- host: ubuntu-latest
target: 'armv7-unknown-linux-gnueabihf'
Expand Down Expand Up @@ -109,7 +111,7 @@ jobs:
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
toolchain: nightly-2023-01-11
targets: ${{ matrix.settings.target }}

- name: Cache cargo registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
toolchain: nightly-2023-01-11
components: rustfmt, clippy

- name: 'Install dependencies'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
]

[profile.release]
codegen-units = 4
codegen-units = 1
lto = true
overflow-checks = false
strip = 'symbols'
2 changes: 1 addition & 1 deletion packages/argon2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ global_alloc = { path = "../../crates/alloc" }
napi-derive = { version = "2", default-features = false, features = [
"type-def",
] }
rand = { version = "0.8", features = ["getrandom"] }
rand = { version = "0.8", features = ["nightly", "simd_support", "getrandom"] }

[build-dependencies]
napi-build = "2"
20 changes: 10 additions & 10 deletions packages/argon2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl Task for HashTask {
let salt = SaltString::generate(&mut OsRng);
let hasher = self.options.to_argon();
hasher
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
.hash_password(self.password.as_slice(), &salt)
.map_err(|err| Error::new(Status::GenericFailure, format!("{}", err)))
.map_err(|err| Error::new(Status::GenericFailure, format!("{err}")))
.map(|h| h.to_string())
}

Expand Down Expand Up @@ -185,7 +185,7 @@ impl Task for RawHashTask {
let hasher = self
.options
.to_argon()
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?;
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?;
let output_len = hasher
.params()
.output_len()
Expand All @@ -194,7 +194,7 @@ impl Task for RawHashTask {

hasher
.hash_password_into(self.password.as_slice(), salt.as_bytes(), &mut output)
.map_err(|err| Error::new(Status::GenericFailure, format!("{}", err)))
.map_err(|err| Error::new(Status::GenericFailure, format!("{err}")))
.map(|_| output)
}

Expand Down Expand Up @@ -251,11 +251,11 @@ impl Task for VerifyTask {

fn compute(&mut self) -> Result<Self::Output> {
let parsed_hash = argon2::PasswordHash::new(self.hashed.as_str())
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?;
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?;
let argon2 = self.options.to_argon();
Ok(
argon2
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
.verify_password(self.password.as_bytes(), &parsed_hash)
.is_ok(),
)
Expand All @@ -278,12 +278,12 @@ pub fn verify(
password: match password {
Either::A(s) => s,
Either::B(b) => String::from_utf8(b.to_vec())
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?,
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?,
},
hashed: match hashed {
Either::A(s) => s,
Either::B(b) => String::from_utf8(b.to_vec())
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?,
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?,
},
options: options.unwrap_or_default(),
},
Expand All @@ -302,12 +302,12 @@ pub fn verify_sync(
password: match password {
Either::A(s) => s,
Either::B(b) => String::from_utf8(b.to_vec())
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?,
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?,
},
hashed: match hashed {
Either::A(s) => s,
Either::B(b) => String::from_utf8(b.to_vec())
.map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?,
.map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?,
},
options: options.unwrap_or_default(),
};
Expand Down
2 changes: 1 addition & 1 deletion packages/bcrypt/src/hash_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl HashTask {
pub fn hash(buf: &[u8], salt: [u8; 16], cost: u32) -> Result<String> {
bcrypt::hash_with_salt(buf, cost, salt)
.map(|hash_part| hash_part.to_string())
.map_err(|err| Error::new(Status::GenericFailure, format!("{}", err)))
.map_err(|err| Error::new(Status::GenericFailure, format!("{err}")))
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn gen_salt_sync(round: u32, version: String) -> Result<String> {
let salt = gen_salt().map_err(|err| {
Error::new(
Status::GenericFailure,
format!("Generate salt failed {}", err),
format!("Generate salt failed {err}"),
)
})?;
Ok(format_salt(
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn hash_sync(
s.copy_from_slice(salt.as_ref());
s
} else {
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
};
match input {
Either::A(s) => HashTask::hash(s.as_bytes(), salt, cost.unwrap_or(DEFAULT_COST)),
Expand All @@ -80,7 +80,7 @@ pub fn hash(
s.copy_from_slice(salt.as_ref());
s
} else {
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{}", err)))?
gen_salt().map_err(|err| Error::new(Status::InvalidArg, format!("{err}")))?
};
let task = HashTask::new(
AsyncHashInput::from_either(input)?,
Expand Down Expand Up @@ -127,7 +127,7 @@ fn version_from_str(version: &str) -> Result<Version> {
"2x" => Ok(Version::TwoY),
_ => Err(Error::new(
Status::InvalidArg,
format!("{} is not a valid version", version),
format!("{version} is not a valid version"),
)),
}
}
4 changes: 2 additions & 2 deletions packages/bcrypt/src/salt_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn format_salt(rounds: u32, version: &Version, salt: &[u8; 16]) -> St
base64::engine::fast_portable::PAD,
),
);
format!("${}${:0>2}${}", version, rounds, base64_string)
format!("${version}${rounds:0>2}${base64_string}")
}

pub struct SaltTask {
Expand All @@ -41,7 +41,7 @@ impl Task for SaltTask {
let random = gen_salt().map_err(|err| {
Error::new(
Status::GenericFailure,
format!("Generate salt failed {}", err),
format!("Generate salt failed {err}"),
)
})?;
Ok(format_salt(self.round, &self.version, &random))
Expand Down
2 changes: 1 addition & 1 deletion packages/crc32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
crc32c = { version = "0.6" }
crc32fast = { version = "1.3" }
crc32fast = { version = "1.3", features = ["nightly"] }
global_alloc = { path = "../../crates/alloc" }
napi = { version = "2", default-features = false, features = ["napi3"] }
napi-derive = { version = "2", default-features = false }
Expand Down
76 changes: 1 addition & 75 deletions packages/crc32/build.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,5 @@
extern crate napi_build;

use std::env;
use std::fs::File;
use std::io::{self, Write};
use std::path::{Path, PathBuf};

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

const CASTAGNOLI_POLY: u32 = 0x82f63b78;

fn main() -> Result<()> {
fn main() {
napi_build::setup();

let out_dir = match env::var_os("OUT_DIR") {
None => return Err(From::from("OUT_DIR environment variable not defined")),
Some(out_dir) => PathBuf::from(out_dir),
};
write_crc_tables(&out_dir)?;

Ok(())
}

fn write_crc_tables(out_dir: &Path) -> Result<()> {
let out_path = out_dir.join("crc32_table.rs");
let mut out = io::BufWriter::new(File::create(out_path)?);

let table = make_table(CASTAGNOLI_POLY);
let table16 = make_table16(CASTAGNOLI_POLY);

writeln!(out, "pub const TABLE: [u32; 256] = [")?;
for &x in table.iter() {
writeln!(out, " {},", x)?;
}
writeln!(out, "];\n")?;

writeln!(out, "pub const TABLE16: [[u32; 256]; 16] = [")?;
for table in table16.iter() {
writeln!(out, " [")?;
for &x in table.iter() {
writeln!(out, " {},", x)?;
}
writeln!(out, " ],")?;
}
writeln!(out, "];")?;

out.flush()?;

Ok(())
}

fn make_table16(poly: u32) -> [[u32; 256]; 16] {
let mut tab = [[0; 256]; 16];
tab[0] = make_table(poly);
for i in 0..256 {
let mut crc = tab[0][i];
for j in 1..16 {
crc = (crc >> 8) ^ tab[0][crc as u8 as usize];
tab[j][i] = crc;
}
}
tab
}

fn make_table(poly: u32) -> [u32; 256] {
let mut tab = [0; 256];
for i in 0u32..256u32 {
let mut crc = i;
for _ in 0..8 {
if crc & 1 == 1 {
crc = (crc >> 1) ^ poly;
} else {
crc >>= 1;
}
}
tab[i as usize] = crc;
}
tab
}
32 changes: 17 additions & 15 deletions packages/crc32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ extern crate global_alloc;

use crc32c::crc32c_append;
use crc32fast::Hasher;
use napi::bindgen_prelude::{Buffer, Either};
use napi::{bindgen_prelude::Either, JsBuffer, Result};
use napi_derive::*;

#[napi(js_name = "crc32c")]
pub fn crc32c(input: Either<String, Buffer>, initial_state: Option<u32>) -> u32 {
crc32c_append(
initial_state.unwrap_or(0),
match &input {
Either::A(s) => s.as_bytes(),
Either::B(b) => b.as_ref(),
},
)
pub fn crc32c(input: Either<String, JsBuffer>, initial_state: Option<u32>) -> Result<u32> {
Ok(match input {
Either::A(s) => crc32c_append(initial_state.unwrap_or(0), s.as_bytes()),
Either::B(b) => crc32c_append(initial_state.unwrap_or(0), &b.into_value()?),
})
}

#[napi]
pub fn crc32(input: Either<String, Buffer>, initial_state: Option<u32>) -> u32 {
pub fn crc32(input: Either<String, JsBuffer>, initial_state: Option<u32>) -> Result<u32> {
let mut hasher = Hasher::new_with_initial(initial_state.unwrap_or(0));
hasher.update(match &input {
Either::A(s) => s.as_bytes(),
Either::B(b) => b.as_ref(),
});
hasher.finalize()
match input {
Either::A(s) => {
hasher.update(s.as_bytes());
}
Either::B(b) => {
let b = b.into_value()?;
hasher.update(&b);
}
};
Ok(hasher.finalize())
}
2 changes: 1 addition & 1 deletion packages/deno-lint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
export function lint(
fileName: string,
sourceCode: string | Buffer,
allRules?: boolean | string | undefined | null
allRules?: boolean | string | undefined | null,
): Array<string>
export function denolint(dirname: string, configPath: string): boolean
Loading