From 1f0bd457e27efd3c317ff0d3ed74e79ab3be56f1 Mon Sep 17 00:00:00 2001 From: Aykut Yilmaz Date: Thu, 13 Feb 2025 05:32:57 +0100 Subject: [PATCH] refactor(deps): migrate to deno.json --- deno.json | 19 +++++++++++++++++++ deps.ts | 2 -- dev_deps.ts | 13 ------------- src/hkdf/mod.ts | 4 ++-- src/hmac/mod.ts | 9 ++++++--- tests/aes.test.ts | 3 ++- tests/block-modes.test.ts | 3 ++- tests/blowfish.test.ts | 3 ++- tests/cast5.test.ts | 3 ++- tests/des.test.ts | 3 ++- tests/hkdf.test.ts | 3 ++- tests/hmac.test.ts | 3 ++- tests/padding.test.ts | 2 +- tests/pbkdf2.test.ts | 3 ++- tests/tdes.test.ts | 3 ++- 15 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 deno.json delete mode 100644 deps.ts delete mode 100644 dev_deps.ts diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..133457f --- /dev/null +++ b/deno.json @@ -0,0 +1,19 @@ +{ + "lock": false, + "imports": { + "@std/assert": "jsr:@std/assert@^1.0.0", + "@std/encoding/hex": "jsr:@std/encoding@^1.0.0/hex", + "@std/hash": "https://deno.land/std@0.160.0/hash/mod.ts" + }, + "exports": { + "./aes": "./aes.ts", + "./block-modes": "./block-modes.ts", + "./blowfish": "./blowfish.ts", + "./cast5": "./cast5.ts", + "./des": "./des.ts", + "./hkdf": "./hkdf.ts", + "./hmac": "./hmac.ts", + "./pbkdf2": "./pbkdf2.ts", + "./tdes": "./tdes.ts" + } +} diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 9c048a2..0000000 --- a/deps.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { createHash } from "https://deno.land/std@0.92.0/hash/mod.ts"; -export type { SupportedAlgorithm } from "https://deno.land/std@0.92.0/hash/mod.ts"; diff --git a/dev_deps.ts b/dev_deps.ts deleted file mode 100644 index ca24873..0000000 --- a/dev_deps.ts +++ /dev/null @@ -1,13 +0,0 @@ -export { - assertEquals, - assertThrows, -} from "https://deno.land/std@0.194.0/testing/asserts.ts"; -import { decode, encode } from "https://deno.land/std@0.194.0/encoding/hex.ts"; - -export function decodeHex(hex: string): Uint8Array { - return decode(new TextEncoder().encode(hex)); -} - -export function encodeHex(bytes: Uint8Array): string { - return new TextDecoder().decode(encode(bytes)); -} diff --git a/src/hkdf/mod.ts b/src/hkdf/mod.ts index 069cd86..3288d31 100644 --- a/src/hkdf/mod.ts +++ b/src/hkdf/mod.ts @@ -1,5 +1,5 @@ -import { hmac, outputSizes } from "../hmac/mod.ts"; import type { SupportedAlgorithm } from "../hmac/mod.ts"; +import { hmac, outputSizes } from "../hmac/mod.ts"; export type { SupportedAlgorithm }; @@ -12,7 +12,7 @@ export function hkdf( ikm: Uint8Array, salt?: Uint8Array, info?: Uint8Array, -) { +): Uint8Array { const hashLen = outputSizes[hash]; if (!salt) salt = new Uint8Array(hashLen); diff --git a/src/hmac/mod.ts b/src/hmac/mod.ts index d711ae5..ae3257a 100644 --- a/src/hmac/mod.ts +++ b/src/hmac/mod.ts @@ -1,6 +1,5 @@ -import { createHash, SupportedAlgorithm } from "../../deps.ts"; - -export type { SupportedAlgorithm } from "../../deps.ts"; +import { createHash, SupportedAlgorithm } from "@std/hash"; +export type { SupportedAlgorithm } from "@std/hash"; export const blockSizes: Record = { "sha3-512": 72, @@ -21,6 +20,8 @@ export const blockSizes: Record = { keccak384: 48, keccak256: 136, keccak224: 144, + blake3: 64, + tiger: 64, }; export const outputSizes: Record = { @@ -42,6 +43,8 @@ export const outputSizes: Record = { keccak384: 48, keccak256: 32, keccak224: 28, + blake3: 32, + tiger: 24, }; /** diff --git a/tests/aes.test.ts b/tests/aes.test.ts index 91358c2..e83448d 100644 --- a/tests/aes.test.ts +++ b/tests/aes.test.ts @@ -1,5 +1,6 @@ +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { Aes } from "../aes.ts"; -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; // https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/AESAVS.pdf diff --git a/tests/block-modes.test.ts b/tests/block-modes.test.ts index 700bd45..069f718 100644 --- a/tests/block-modes.test.ts +++ b/tests/block-modes.test.ts @@ -1,6 +1,7 @@ +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { Aes } from "../aes.ts"; import { Cbc, Cfb, Ctr, Ecb, Ige, Ofb } from "../block-modes.ts"; -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; const key = new Uint8Array(16); const iv = new Uint8Array(16); diff --git a/tests/blowfish.test.ts b/tests/blowfish.test.ts index aec8e52..6860dd9 100644 --- a/tests/blowfish.test.ts +++ b/tests/blowfish.test.ts @@ -1,4 +1,5 @@ -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { Blowfish } from "../blowfish.ts"; Deno.test("[Block Cipher] Blowfish", () => { diff --git a/tests/cast5.test.ts b/tests/cast5.test.ts index 6bf86aa..7e2b981 100644 --- a/tests/cast5.test.ts +++ b/tests/cast5.test.ts @@ -1,5 +1,6 @@ +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { Cast5 } from "../cast5.ts"; -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; // https://tools.ietf.org/html/rfc2144#appendix-B.1 diff --git a/tests/des.test.ts b/tests/des.test.ts index 544b5d2..942875e 100644 --- a/tests/des.test.ts +++ b/tests/des.test.ts @@ -1,4 +1,5 @@ -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { Des } from "../des.ts"; Deno.test("[Block Cipher] DES", () => { diff --git a/tests/hkdf.test.ts b/tests/hkdf.test.ts index 29b8590..998a906 100644 --- a/tests/hkdf.test.ts +++ b/tests/hkdf.test.ts @@ -1,5 +1,6 @@ +import { assertEquals } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { hkdf } from "../hkdf.ts"; -import { assertEquals, decodeHex } from "../dev_deps.ts"; // https://tools.ietf.org/html/rfc5869#appendix-A diff --git a/tests/hmac.test.ts b/tests/hmac.test.ts index e2e62e8..d2db279 100644 --- a/tests/hmac.test.ts +++ b/tests/hmac.test.ts @@ -1,5 +1,6 @@ +import { assertEquals } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { hmac, SupportedAlgorithm } from "../hmac.ts"; -import { assertEquals, decodeHex } from "../dev_deps.ts"; // https://tools.ietf.org/html/rfc4231#section-4 diff --git a/tests/padding.test.ts b/tests/padding.test.ts index d9b00ec..701858e 100644 --- a/tests/padding.test.ts +++ b/tests/padding.test.ts @@ -1,4 +1,4 @@ -import { assertEquals, assertThrows } from "../dev_deps.ts"; +import { assertEquals, assertThrows } from "@std/assert"; import { pad, Padding, unpad } from "../src/utils/padding.ts"; Deno.test("[Padding] PKCS#7", () => { diff --git a/tests/pbkdf2.test.ts b/tests/pbkdf2.test.ts index 5b69bc0..2128319 100644 --- a/tests/pbkdf2.test.ts +++ b/tests/pbkdf2.test.ts @@ -1,5 +1,6 @@ +import { assertEquals } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { pbkdf2 } from "../src/pbkdf2/mod.ts"; -import { assertEquals, decodeHex } from "../dev_deps.ts"; // https://tools.ietf.org/html/rfc6070#section-2 Deno.test("[KDF] PBKDF2 HMAC-SHA1", () => { diff --git a/tests/tdes.test.ts b/tests/tdes.test.ts index 2bb52c7..2a408eb 100644 --- a/tests/tdes.test.ts +++ b/tests/tdes.test.ts @@ -1,4 +1,5 @@ -import { assertEquals, assertThrows, decodeHex } from "../dev_deps.ts"; +import { assertEquals, assertThrows } from "@std/assert"; +import { decodeHex } from "@std/encoding/hex"; import { TripleDes } from "../tdes.ts"; Deno.test("[Block Cipher] 3DES", () => {