Skip to content

Commit

Permalink
Use !isNode instead of isDeno for dnt.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajiaji committed Aug 24, 2024
1 parent d8df40c commit 226be84
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 51 deletions.
5 changes: 0 additions & 5 deletions x/core/src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
declare const Deno: undefined;

/**
* Checks whether the execution env is Deno or not.
*/
export const isDeno = () => typeof Deno !== "undefined";

/**
* Checks whetehr the type of input is CryptoKeyPair or not.
*/
Expand Down
9 changes: 3 additions & 6 deletions x/core/test/cipherSuite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import {
KdfId,
KemId,
} from "../mod.ts";
// import { Chacha20Poly1305 } from "../../src/aeads/chacha20Poly1305.ts";
// import { DhkemX25519HkdfSha256 } from "../../src/kems/dhkemX25519.ts";
// import { DhkemX448HkdfSha512 } from "../../src/kems/dhkemX448.ts";
import { isDeno } from "../src/utils/misc.ts";
import { hexToBytes } from "./utils.ts";

import { hexToBytes, isNode } from "./utils.ts";

describe("constructor", () => {
describe("with DhkemP384HkdfSha384/HkdfSha384/Aes128Gcm", () => {
Expand Down Expand Up @@ -519,7 +516,7 @@ describe("deriveKeyPair", () => {

describe("with official test-vector for DhkemP256HkdfSha256.", () => {
it("should derive a proper key pair.", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const ikmR = hexToBytes(
Expand Down
4 changes: 2 additions & 2 deletions x/core/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { KemId } from "../src/identifiers.ts";

// deno-lint-ignore no-explicit-any
export const isDeno = () => (globalThis as any).Deno?.version?.deno !== null;
// deno-lint-ignore no-explicit-any
export const isNode = () => (globalThis as any).process?.versions?.node != null;
// export const isDeno = () => (globalThis as any).Deno?.version?.deno !== null;

export function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
const ret = new Uint8Array(a.length + b.length);
ret.set(a, 0);
Expand Down
4 changes: 2 additions & 2 deletions x/hpke-js/test/cipherSuite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "@hpke/core";

import { CipherSuite } from "../src/cipherSuite.ts";
import { hexToBytes, isDeno } from "../../core/test/utils.ts";
import { hexToBytes, isNode } from "../../core/test/utils.ts";

describe("constructor", () => {
// RFC9180 A.1.
Expand Down Expand Up @@ -479,7 +479,7 @@ describe("deriveKeyPair", () => {

describe("with official test-vector for DhkemP256HkdfSha256.", () => {
it("should derive a proper key pair.", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const ikmR = hexToBytes(
Expand Down
10 changes: 5 additions & 5 deletions x/hpke-js/test/cipherSuiteBackwardCompat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CipherSuite } from "../src/cipherSuite.ts";
import {
concat,
hexToBytes,
isDeno,
isNode,
loadCrypto,
} from "../../core/test/utils.ts";

Expand Down Expand Up @@ -344,7 +344,7 @@ describe("CipherSuite(backward-compat)", () => {

describe("A README example of Base mode (Kem.DhkemP521HkdfSha512/Kdf.HkdfSha512)", () => {
it("should work normally with generateKeyPair", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down Expand Up @@ -379,7 +379,7 @@ describe("CipherSuite(backward-compat)", () => {
});

it("should work normally with importKey('jwk')", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down Expand Up @@ -1375,7 +1375,7 @@ describe("CipherSuite(backward-compat)", () => {

describe("A README example of Oblivious HTTP (HKDF-SHA384)", () => {
it("should work normally", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const te = new TextEncoder();
Expand Down Expand Up @@ -1464,7 +1464,7 @@ describe("CipherSuite(backward-compat)", () => {

describe("A README example of Oblivious HTTP (HKDF-SHA512)", () => {
it("should work normally", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const te = new TextEncoder();
Expand Down
4 changes: 2 additions & 2 deletions x/hpke-js/test/cipherSuiteNative.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DhkemX448HkdfSha512 } from "@hpke/dhkem-x448";
import {
concat,
hexToBytes,
isDeno,
isNode,
loadCrypto,
} from "../../core/test/utils.ts";

Expand Down Expand Up @@ -546,7 +546,7 @@ describe("deriveKeyPair", () => {

describe("with official test-vector for DhkemP256HkdfSha256.", () => {
it("should derive a proper key pair.", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const ikmR = hexToBytes(
Expand Down
28 changes: 14 additions & 14 deletions x/hpke-js/test/conformance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ConformanceTester } from "./conformanceTester.ts";
import type { TestVector } from "./testVector.ts";

import { createConformanceTester } from "./conformanceTester.ts";
import { isDeno, testVectorPath } from "../../core/test/utils.ts";
import { isNode, testVectorPath } from "../../core/test/utils.ts";

describe("RFC9180 conformance", () => {
let testVectors: TestVector[];
Expand All @@ -26,7 +26,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id === 0x0010 && v.aead_id <= 0x0002) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -49,7 +49,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id === 0x0012 && v.aead_id <= 0x0002) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -62,7 +62,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -75,7 +75,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 0 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -148,7 +148,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -161,7 +161,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -174,7 +174,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -247,7 +247,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -260,7 +260,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -273,7 +273,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -346,7 +346,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -359,7 +359,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand All @@ -372,7 +372,7 @@ describe("RFC9180 conformance", () => {
it("should match demonstrated values", async () => {
for (const v of testVectors) {
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
if (isDeno()) {
if (!isNode()) {
continue;
}
await tester.test(v);
Expand Down
10 changes: 5 additions & 5 deletions x/hpke-js/test/dhkemPrimitives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HkdfSha256, X25519 } from "@hpke/dhkem-x25519";
import { HkdfSha512, X448 } from "@hpke/dhkem-x448";

import { HkdfSha384 } from "../src/kdfs/hkdfSha384.ts";
import { isDeno } from "../../core/test/utils.ts";
import { isNode } from "../../core/test/utils.ts";

describe("derivePublicKey", () => {
describe("with valid parameters", () => {
Expand Down Expand Up @@ -45,7 +45,7 @@ describe("derivePublicKey", () => {
});

it("should return a proper public key with Ec(DhkemP521HkdfSha512)", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const kdf = new HkdfSha512();
Expand Down Expand Up @@ -114,7 +114,7 @@ describe("derivePublicKey", () => {
});

it("should throw DeserializeError on Ec(DhkemP256HkdfSha256) with a P-521 private key", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const kdf = new HkdfSha256();
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("derivePublicKey", () => {
});

it("should throw DeserializeError on X25519 with a P-521 private key", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const kdf = new HkdfSha256();
Expand Down Expand Up @@ -248,7 +248,7 @@ describe("derivePublicKey", () => {
});

it("should throw DeserializeError on X448 with a P-521 private key", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const kdf = new HkdfSha512();
Expand Down
8 changes: 4 additions & 4 deletions x/hpke-js/test/keyValidationEc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ConformanceTester } from "./conformanceTester.ts";
import type { WycheproofTestVector } from "./testVector.ts";

import { createConformanceTester } from "./conformanceTester.ts";
import { isDeno, testVectorPath } from "../../core/test/utils.ts";
import { isNode, testVectorPath } from "../../core/test/utils.ts";

describe("EC key validation", () => {
let totalCount: number;
Expand All @@ -22,7 +22,7 @@ describe("EC key validation", () => {

describe("P-256", () => {
it("should validate properly", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand All @@ -47,7 +47,7 @@ describe("EC key validation", () => {

describe("P-384", () => {
it("should validate properly", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand All @@ -72,7 +72,7 @@ describe("EC key validation", () => {

describe("P-521", () => {
it("should validate properly", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down
12 changes: 6 additions & 6 deletions x/hpke-js/test/sample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DhkemP384HkdfSha384 } from "../src/kems/dhkemP384.ts";
import { DhkemP521HkdfSha512 } from "../src/kems/dhkemP521.ts";
import { HkdfSha384 } from "../src/kdfs/hkdfSha384.ts";

import { concat, isDeno, loadCrypto } from "../../core/test/utils.ts";
import { concat, isNode, loadCrypto } from "../../core/test/utils.ts";

describe("README examples", () => {
describe("Base mode with DhkemP256HkdfSha256/HkdfSha256/Aes128Gcm", () => {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe("README examples", () => {

describe("Base mode with DhkemP521HkdfSha512/HkdfSha512/Aes128Gcm", () => {
it("should work normally with ids", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down Expand Up @@ -285,7 +285,7 @@ describe("README examples", () => {
});

it("should work normally with instances", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down Expand Up @@ -320,7 +320,7 @@ describe("README examples", () => {
});

it("should work normally with importKey('jwk')", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}

Expand Down Expand Up @@ -1035,7 +1035,7 @@ describe("README examples", () => {

describe("Oblivious HTTP with DhkemP384HkdfSha384/HkdfSha384/Aes256Gcm", () => {
it("should work normally", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const te = new TextEncoder();
Expand Down Expand Up @@ -1122,7 +1122,7 @@ describe("README examples", () => {

describe("Oblivious HTTP with DhkemP521HkdfSha512/HkdfSha512/Aes256Gcm", () => {
it("should work normally", async () => {
if (isDeno()) {
if (!isNode()) {
return;
}
const te = new TextEncoder();
Expand Down

0 comments on commit 226be84

Please sign in to comment.