From 6d4416bb633ba6384c1c3b5055c299213ccabb28 Mon Sep 17 00:00:00 2001 From: Federico Date: Tue, 14 Apr 2020 22:55:16 +0200 Subject: [PATCH] Add hashLength --- README.md | 6 ++++-- examples/hash-with-options.ts | 3 ++- lib/common.ts | 1 + native/command.rs | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad43a73..917dd1e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Deno.test("User#password should be an argon2id variant password", async () => { ### CLI -It is possible to install deno-argon2 as a CLI tool insatiable via `deno install`. +The library can be installed as a CLI tool via `deno install`.
@@ -64,7 +64,7 @@ After install run `--help` to inspect all possible commands. ## Permissions -This library automatically download the static library and initialize Deno plugin via [plugin_prepare](https://github.com/manyuanrong/deno-plugin-prepare) and it requires `--allow-read .deno_plugins`, `--allow-write .deno_plugins` and `--allow-plugin` to be specified. +The library automatically download the static library and initialize Deno plugin via [plugin_prepare](https://github.com/manyuanrong/deno-plugin-prepare) and it requires `--allow-read`, `--allow-write`, `--allow-net` and `--allow-plugin`.
@@ -104,3 +104,5 @@ deno-argon2 ``` ## License + +[MIT](LICENSE) diff --git a/examples/hash-with-options.ts b/examples/hash-with-options.ts index bb16537..cf997c6 100644 --- a/examples/hash-with-options.ts +++ b/examples/hash-with-options.ts @@ -2,7 +2,7 @@ import { hash, Variant, Version, ThreadMode } from "../lib/dev.ts"; import { encode } from "../lib/deps.ts"; let salt = crypto.getRandomValues( - new Uint8Array(Math.max(8, Math.random() * 32)), + new Uint8Array(20), ); let secret = encode("my-super-secret"); @@ -16,6 +16,7 @@ console.log(await hash("test", { timeCost: 10, threadMode: ThreadMode.Parallel, lanes: 4, + hashLength: 32, data: { hashedAt: Date.now(), requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941", diff --git a/lib/common.ts b/lib/common.ts index f091e5d..c44c1d5 100644 --- a/lib/common.ts +++ b/lib/common.ts @@ -26,6 +26,7 @@ export interface HashOptions { timeCost: number; threadMode: ThreadMode; lanes: number; + hashLength: number; } export function version() { diff --git a/native/command.rs b/native/command.rs index 1e7e935..b8dafcd 100644 --- a/native/command.rs +++ b/native/command.rs @@ -19,6 +19,8 @@ pub struct HashOptions { lanes: Option, #[serde(rename(deserialize = "threadMode"))] thread_mode: Option, + #[serde(rename(deserialize = "hashLength"))] + hash_length: Option, } #[derive(Deserialize)] @@ -108,6 +110,10 @@ fn hash_internal(data: &[u8]) -> Result { config.lanes = lanes; } + if let Some(hash_length) = params.options.hash_length { + config.hash_length = hash_length; + } + if let Some(thread_mode) = params.options.thread_mode { match thread_mode { 0 => config.thread_mode = ThreadMode::Sequential,