Skip to content

Commit

Permalink
Release 0.6.0
Browse files Browse the repository at this point in the history
Rename cli, apply format, rename internal native functions' names to be fairly unique.
  • Loading branch information
Federico Dionisi committed May 20, 2020
1 parent c6b6b62 commit 1e8431b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The library can be installed as a CLI tool via `deno install`.
--allow-plugin \
--allow-net \
--unstable \
argon2 https://deno.land/x/argon2/cli/mod.ts
argon2 https://deno.land/x/argon2/cli/argon2
```
</details>

Expand Down
File renamed without changes.
24 changes: 13 additions & 11 deletions cli/commands/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ export let hash = new Command()
.action(async (options) => {
let password = await readStdin();

console.log(await argon2.hash(password, {
salt: options.salt ? encode(options.salt) : undefined,
secret: options.secret ? encode(options.secret) : undefined,
memoryCost: options.memoryCost ? options.memoryCost : undefined,
timeCost: options.timeCost ? options.timeCost : undefined,
lanes: options.lanes ? options.lanes : undefined,
threadMode: "threadMode" in options ? options.threadMode : undefined,
variant: options.variant ? options.variant : undefined,
data: options.data ? options.data : undefined,
hashLength: options.hashLength ? options.hashLength : undefined,
}));
console.log(
await argon2.hash(password, {
salt: options.salt ? encode(options.salt) : undefined,
secret: options.secret ? encode(options.secret) : undefined,
memoryCost: options.memoryCost ? options.memoryCost : undefined,
timeCost: options.timeCost ? options.timeCost : undefined,
lanes: options.lanes ? options.lanes : undefined,
threadMode: "threadMode" in options ? options.threadMode : undefined,
variant: options.variant ? options.variant : undefined,
data: options.data ? options.data : undefined,
hashLength: options.hashLength ? options.hashLength : undefined,
}),
);
});
32 changes: 17 additions & 15 deletions examples/hash-with-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ let salt = crypto.getRandomValues(

let secret = encode("my-super-secret");

console.log(await hash("test", {
salt,
secret,
variant: Variant.Argon2id,
version: Version.V13,
memoryCost: 8192,
timeCost: 10,
threadMode: ThreadMode.Parallel,
lanes: 4,
hashLength: 32,
data: {
hashedAt: Date.now(),
requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941",
},
}));
console.log(
await hash("test", {
salt,
secret,
variant: Variant.Argon2id,
version: Version.V13,
memoryCost: 8192,
timeCost: 10,
threadMode: ThreadMode.Parallel,
lanes: 4,
hashLength: 32,
data: {
hashedAt: Date.now(),
requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941",
},
}),
);
2 changes: 1 addition & 1 deletion lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export interface HashOptions<T extends {} = {}> {
}

export function version() {
return "0.5.2";
return "0.6.0";
}
20 changes: 9 additions & 11 deletions lib/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function installPlugin(
await preparing;

//@ts-ignore
const { hash } = Deno.core.ops();
let { argon2_hash } = Deno.core.ops();

if (typeof password !== "string") {
throw new Argon2Error(
Expand All @@ -66,13 +66,11 @@ export async function installPlugin(
);
}

let salt = options.salt
? options.salt
: crypto.getRandomValues(
new Uint8Array(
Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE),
),
);
let salt = options.salt ? options.salt : crypto.getRandomValues(
new Uint8Array(
Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE),
),
);

if (salt.length < MIN_SALT_SIZE) {
throw new Argon2Error(
Expand All @@ -95,7 +93,7 @@ export async function installPlugin(

let buf = new Uint8Array(1);
//@ts-ignore
let result = Deno.core.dispatch(hash, args, buf)!;
let result = Deno.core.dispatch(argon2_hash, args, buf)!;

if (buf[0] !== 1) {
throw new Argon2Error(
Expand All @@ -114,13 +112,13 @@ export async function installPlugin(
await preparing;

//@ts-ignore
const { verify } = Deno.core.ops();
let { argon2_verify } = Deno.core.ops();

let args = encode(JSON.stringify({ password, hash }));

let buf = new Uint8Array(100);
//@ts-ignore
let result = Deno.core.dispatch(verify, args, buf)!;
let result = Deno.core.dispatch(argon2_verify, args, buf)!;

if (buf[0] !== 1) {
throw new Argon2Error(
Expand Down
20 changes: 5 additions & 15 deletions lib/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,15 @@ export function assertArgon2Encoded(
password: string,
options: Partial<AssertArgon2EncodedOptions> = {},
): asserts password {
let variant = options.variant
? options.variant
: "argon2(i|d|id)";
let variant = options.variant ? options.variant : "argon2(i|d|id)";

let version = options.version
? options.version
: "(16|19)";
let version = options.version ? options.version : "(16|19)";

let memoryCost = options.memoryCost
? options.memoryCost
: "([0-9])+";
let memoryCost = options.memoryCost ? options.memoryCost : "([0-9])+";

let timeCost = options.timeCost
? options.timeCost
: "([0-9])+";
let timeCost = options.timeCost ? options.timeCost : "([0-9])+";

let lanes = options.lanes
? options.lanes
: "([0-9])+";
let lanes = options.lanes ? options.lanes : "([0-9])+";

let rx = new RegExp(
`^\\$${variant}\\$v=${version}\\$m=${memoryCost},t=${timeCost},p=${lanes}\\$.+$`,
Expand Down
4 changes: 2 additions & 2 deletions native/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ use deno_core::plugin_api::Interface;

#[no_mangle]
fn deno_plugin_init(context: &mut dyn Interface) {
context.register_op("hash", command::hash);
context.register_op("verify", command::verify);
context.register_op("argon2_hash", command::hash);
context.register_op("argon2_verify", command::verify);
}
3 changes: 0 additions & 3 deletions tests/cli.ts

This file was deleted.

6 changes: 3 additions & 3 deletions tests/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "./lib.test.ts"
import "./testing.test.ts"
import "./lib.test.ts";
import "./testing.test.ts";

// @ts-ignore
Deno[Deno.internal].runTests()
Deno[Deno.internal].runTests();

0 comments on commit 1e8431b

Please sign in to comment.