Skip to content

Commit 1e8431b

Browse files
author
Federico Dionisi
committed
Release 0.6.0
Rename cli, apply format, rename internal native functions' names to be fairly unique.
1 parent c6b6b62 commit 1e8431b

File tree

10 files changed

+51
-62
lines changed

10 files changed

+51
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The library can be installed as a CLI tool via `deno install`.
5757
--allow-plugin \
5858
--allow-net \
5959
--unstable \
60-
argon2 https://deno.land/x/argon2/cli/mod.ts
60+
argon2 https://deno.land/x/argon2/cli/argon2
6161
```
6262
</details>
6363

cli/mod.ts renamed to cli/argon2

File renamed without changes.

cli/commands/hash.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ export let hash = new Command()
5858
.action(async (options) => {
5959
let password = await readStdin();
6060

61-
console.log(await argon2.hash(password, {
62-
salt: options.salt ? encode(options.salt) : undefined,
63-
secret: options.secret ? encode(options.secret) : undefined,
64-
memoryCost: options.memoryCost ? options.memoryCost : undefined,
65-
timeCost: options.timeCost ? options.timeCost : undefined,
66-
lanes: options.lanes ? options.lanes : undefined,
67-
threadMode: "threadMode" in options ? options.threadMode : undefined,
68-
variant: options.variant ? options.variant : undefined,
69-
data: options.data ? options.data : undefined,
70-
hashLength: options.hashLength ? options.hashLength : undefined,
71-
}));
61+
console.log(
62+
await argon2.hash(password, {
63+
salt: options.salt ? encode(options.salt) : undefined,
64+
secret: options.secret ? encode(options.secret) : undefined,
65+
memoryCost: options.memoryCost ? options.memoryCost : undefined,
66+
timeCost: options.timeCost ? options.timeCost : undefined,
67+
lanes: options.lanes ? options.lanes : undefined,
68+
threadMode: "threadMode" in options ? options.threadMode : undefined,
69+
variant: options.variant ? options.variant : undefined,
70+
data: options.data ? options.data : undefined,
71+
hashLength: options.hashLength ? options.hashLength : undefined,
72+
}),
73+
);
7274
});

examples/hash-with-options.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ let salt = crypto.getRandomValues(
77

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

10-
console.log(await hash("test", {
11-
salt,
12-
secret,
13-
variant: Variant.Argon2id,
14-
version: Version.V13,
15-
memoryCost: 8192,
16-
timeCost: 10,
17-
threadMode: ThreadMode.Parallel,
18-
lanes: 4,
19-
hashLength: 32,
20-
data: {
21-
hashedAt: Date.now(),
22-
requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941",
23-
},
24-
}));
10+
console.log(
11+
await hash("test", {
12+
salt,
13+
secret,
14+
variant: Variant.Argon2id,
15+
version: Version.V13,
16+
memoryCost: 8192,
17+
timeCost: 10,
18+
threadMode: ThreadMode.Parallel,
19+
lanes: 4,
20+
hashLength: 32,
21+
data: {
22+
hashedAt: Date.now(),
23+
requestId: "a00d22c0-4681-4351-8c8f-6f02a42dd941",
24+
},
25+
}),
26+
);

lib/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ export interface HashOptions<T extends {} = {}> {
3030
}
3131

3232
export function version() {
33-
return "0.5.2";
33+
return "0.6.0";
3434
}

lib/internal.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function installPlugin(
5757
await preparing;
5858

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

6262
if (typeof password !== "string") {
6363
throw new Argon2Error(
@@ -66,13 +66,11 @@ export async function installPlugin(
6666
);
6767
}
6868

69-
let salt = options.salt
70-
? options.salt
71-
: crypto.getRandomValues(
72-
new Uint8Array(
73-
Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE),
74-
),
75-
);
69+
let salt = options.salt ? options.salt : crypto.getRandomValues(
70+
new Uint8Array(
71+
Math.max(Math.round(Math.random() * 32), MIN_SALT_SIZE),
72+
),
73+
);
7674

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

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

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

116114
//@ts-ignore
117-
const { verify } = Deno.core.ops();
115+
let { argon2_verify } = Deno.core.ops();
118116

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

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

125123
if (buf[0] !== 1) {
126124
throw new Argon2Error(

lib/testing.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,15 @@ export function assertArgon2Encoded(
1414
password: string,
1515
options: Partial<AssertArgon2EncodedOptions> = {},
1616
): asserts password {
17-
let variant = options.variant
18-
? options.variant
19-
: "argon2(i|d|id)";
17+
let variant = options.variant ? options.variant : "argon2(i|d|id)";
2018

21-
let version = options.version
22-
? options.version
23-
: "(16|19)";
19+
let version = options.version ? options.version : "(16|19)";
2420

25-
let memoryCost = options.memoryCost
26-
? options.memoryCost
27-
: "([0-9])+";
21+
let memoryCost = options.memoryCost ? options.memoryCost : "([0-9])+";
2822

29-
let timeCost = options.timeCost
30-
? options.timeCost
31-
: "([0-9])+";
23+
let timeCost = options.timeCost ? options.timeCost : "([0-9])+";
3224

33-
let lanes = options.lanes
34-
? options.lanes
35-
: "([0-9])+";
25+
let lanes = options.lanes ? options.lanes : "([0-9])+";
3626

3727
let rx = new RegExp(
3828
`^\\$${variant}\\$v=${version}\\$m=${memoryCost},t=${timeCost},p=${lanes}\\$.+$`,

native/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ use deno_core::plugin_api::Interface;
88

99
#[no_mangle]
1010
fn deno_plugin_init(context: &mut dyn Interface) {
11-
context.register_op("hash", command::hash);
12-
context.register_op("verify", command::verify);
11+
context.register_op("argon2_hash", command::hash);
12+
context.register_op("argon2_verify", command::verify);
1313
}

tests/cli.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/run.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import "./lib.test.ts"
2-
import "./testing.test.ts"
1+
import "./lib.test.ts";
2+
import "./testing.test.ts";
33

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

0 commit comments

Comments
 (0)