Skip to content

Commit

Permalink
Add hashLength
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico committed Apr 14, 2020
1 parent b1a03c3 commit 6d4416b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

<details>

Expand All @@ -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`.

<details>

Expand Down Expand Up @@ -104,3 +104,5 @@ deno-argon2
```

## License

[MIT](LICENSE)
3 changes: 2 additions & 1 deletion examples/hash-with-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface HashOptions<T extends {} = {}> {
timeCost: number;
threadMode: ThreadMode;
lanes: number;
hashLength: number;
}

export function version() {
Expand Down
6 changes: 6 additions & 0 deletions native/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct HashOptions {
lanes: Option<u32>,
#[serde(rename(deserialize = "threadMode"))]
thread_mode: Option<u8>,
#[serde(rename(deserialize = "hashLength"))]
hash_length: Option<u32>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -108,6 +110,10 @@ fn hash_internal(data: &[u8]) -> Result<String, Error> {
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,
Expand Down

0 comments on commit 6d4416b

Please sign in to comment.