Skip to content

Commit aa9892c

Browse files
authored
Merge pull request #340 from dajiaji/use-is-node
Use !isNode instead of isDeno for dnt.
2 parents d8df40c + 226be84 commit aa9892c

10 files changed

+43
-51
lines changed

x/core/src/utils/misc.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
declare const Deno: undefined;
22

3-
/**
4-
* Checks whether the execution env is Deno or not.
5-
*/
6-
export const isDeno = () => typeof Deno !== "undefined";
7-
83
/**
94
* Checks whetehr the type of input is CryptoKeyPair or not.
105
*/

x/core/test/cipherSuite.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ import {
1818
KdfId,
1919
KemId,
2020
} from "../mod.ts";
21-
// import { Chacha20Poly1305 } from "../../src/aeads/chacha20Poly1305.ts";
22-
// import { DhkemX25519HkdfSha256 } from "../../src/kems/dhkemX25519.ts";
23-
// import { DhkemX448HkdfSha512 } from "../../src/kems/dhkemX448.ts";
24-
import { isDeno } from "../src/utils/misc.ts";
25-
import { hexToBytes } from "./utils.ts";
21+
22+
import { hexToBytes, isNode } from "./utils.ts";
2623

2724
describe("constructor", () => {
2825
describe("with DhkemP384HkdfSha384/HkdfSha384/Aes128Gcm", () => {
@@ -519,7 +516,7 @@ describe("deriveKeyPair", () => {
519516

520517
describe("with official test-vector for DhkemP256HkdfSha256.", () => {
521518
it("should derive a proper key pair.", async () => {
522-
if (isDeno()) {
519+
if (!isNode()) {
523520
return;
524521
}
525522
const ikmR = hexToBytes(

x/core/test/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { KemId } from "../src/identifiers.ts";
22

3-
// deno-lint-ignore no-explicit-any
4-
export const isDeno = () => (globalThis as any).Deno?.version?.deno !== null;
53
// deno-lint-ignore no-explicit-any
64
export const isNode = () => (globalThis as any).process?.versions?.node != null;
5+
// export const isDeno = () => (globalThis as any).Deno?.version?.deno !== null;
6+
77
export function concat(a: Uint8Array, b: Uint8Array): Uint8Array {
88
const ret = new Uint8Array(a.length + b.length);
99
ret.set(a, 0);

x/hpke-js/test/cipherSuite.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "@hpke/core";
1111

1212
import { CipherSuite } from "../src/cipherSuite.ts";
13-
import { hexToBytes, isDeno } from "../../core/test/utils.ts";
13+
import { hexToBytes, isNode } from "../../core/test/utils.ts";
1414

1515
describe("constructor", () => {
1616
// RFC9180 A.1.
@@ -479,7 +479,7 @@ describe("deriveKeyPair", () => {
479479

480480
describe("with official test-vector for DhkemP256HkdfSha256.", () => {
481481
it("should derive a proper key pair.", async () => {
482-
if (isDeno()) {
482+
if (!isNode()) {
483483
return;
484484
}
485485
const ikmR = hexToBytes(

x/hpke-js/test/cipherSuiteBackwardCompat.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CipherSuite } from "../src/cipherSuite.ts";
1414
import {
1515
concat,
1616
hexToBytes,
17-
isDeno,
17+
isNode,
1818
loadCrypto,
1919
} from "../../core/test/utils.ts";
2020

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

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

@@ -379,7 +379,7 @@ describe("CipherSuite(backward-compat)", () => {
379379
});
380380

381381
it("should work normally with importKey('jwk')", async () => {
382-
if (isDeno()) {
382+
if (!isNode()) {
383383
return;
384384
}
385385

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

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

14651465
describe("A README example of Oblivious HTTP (HKDF-SHA512)", () => {
14661466
it("should work normally", async () => {
1467-
if (isDeno()) {
1467+
if (!isNode()) {
14681468
return;
14691469
}
14701470
const te = new TextEncoder();

x/hpke-js/test/cipherSuiteNative.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { DhkemX448HkdfSha512 } from "@hpke/dhkem-x448";
2525
import {
2626
concat,
2727
hexToBytes,
28-
isDeno,
28+
isNode,
2929
loadCrypto,
3030
} from "../../core/test/utils.ts";
3131

@@ -546,7 +546,7 @@ describe("deriveKeyPair", () => {
546546

547547
describe("with official test-vector for DhkemP256HkdfSha256.", () => {
548548
it("should derive a proper key pair.", async () => {
549-
if (isDeno()) {
549+
if (!isNode()) {
550550
return;
551551
}
552552
const ikmR = hexToBytes(

x/hpke-js/test/conformance.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ConformanceTester } from "./conformanceTester.ts";
44
import type { TestVector } from "./testVector.ts";
55

66
import { createConformanceTester } from "./conformanceTester.ts";
7-
import { isDeno, testVectorPath } from "../../core/test/utils.ts";
7+
import { isNode, testVectorPath } from "../../core/test/utils.ts";
88

99
describe("RFC9180 conformance", () => {
1010
let testVectors: TestVector[];
@@ -26,7 +26,7 @@ describe("RFC9180 conformance", () => {
2626
it("should match demonstrated values", async () => {
2727
for (const v of testVectors) {
2828
if (v.mode === 0 && v.kem_id === 0x0010 && v.aead_id <= 0x0002) {
29-
if (isDeno()) {
29+
if (!isNode()) {
3030
continue;
3131
}
3232
await tester.test(v);
@@ -49,7 +49,7 @@ describe("RFC9180 conformance", () => {
4949
it("should match demonstrated values", async () => {
5050
for (const v of testVectors) {
5151
if (v.mode === 0 && v.kem_id === 0x0012 && v.aead_id <= 0x0002) {
52-
if (isDeno()) {
52+
if (!isNode()) {
5353
continue;
5454
}
5555
await tester.test(v);
@@ -62,7 +62,7 @@ describe("RFC9180 conformance", () => {
6262
it("should match demonstrated values", async () => {
6363
for (const v of testVectors) {
6464
if (v.mode === 0 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
65-
if (isDeno()) {
65+
if (!isNode()) {
6666
continue;
6767
}
6868
await tester.test(v);
@@ -75,7 +75,7 @@ describe("RFC9180 conformance", () => {
7575
it("should match demonstrated values", async () => {
7676
for (const v of testVectors) {
7777
if (v.mode === 0 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
78-
if (isDeno()) {
78+
if (!isNode()) {
7979
continue;
8080
}
8181
await tester.test(v);
@@ -148,7 +148,7 @@ describe("RFC9180 conformance", () => {
148148
it("should match demonstrated values", async () => {
149149
for (const v of testVectors) {
150150
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
151-
if (isDeno()) {
151+
if (!isNode()) {
152152
continue;
153153
}
154154
await tester.test(v);
@@ -161,7 +161,7 @@ describe("RFC9180 conformance", () => {
161161
it("should match demonstrated values", async () => {
162162
for (const v of testVectors) {
163163
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
164-
if (isDeno()) {
164+
if (!isNode()) {
165165
continue;
166166
}
167167
await tester.test(v);
@@ -174,7 +174,7 @@ describe("RFC9180 conformance", () => {
174174
it("should match demonstrated values", async () => {
175175
for (const v of testVectors) {
176176
if (v.mode === 1 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
177-
if (isDeno()) {
177+
if (!isNode()) {
178178
continue;
179179
}
180180
await tester.test(v);
@@ -247,7 +247,7 @@ describe("RFC9180 conformance", () => {
247247
it("should match demonstrated values", async () => {
248248
for (const v of testVectors) {
249249
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
250-
if (isDeno()) {
250+
if (!isNode()) {
251251
continue;
252252
}
253253
await tester.test(v);
@@ -260,7 +260,7 @@ describe("RFC9180 conformance", () => {
260260
it("should match demonstrated values", async () => {
261261
for (const v of testVectors) {
262262
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
263-
if (isDeno()) {
263+
if (!isNode()) {
264264
continue;
265265
}
266266
await tester.test(v);
@@ -273,7 +273,7 @@ describe("RFC9180 conformance", () => {
273273
it("should match demonstrated values", async () => {
274274
for (const v of testVectors) {
275275
if (v.mode === 2 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
276-
if (isDeno()) {
276+
if (!isNode()) {
277277
continue;
278278
}
279279
await tester.test(v);
@@ -346,7 +346,7 @@ describe("RFC9180 conformance", () => {
346346
it("should match demonstrated values", async () => {
347347
for (const v of testVectors) {
348348
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id <= 0x0002) {
349-
if (isDeno()) {
349+
if (!isNode()) {
350350
continue;
351351
}
352352
await tester.test(v);
@@ -359,7 +359,7 @@ describe("RFC9180 conformance", () => {
359359
it("should match demonstrated values", async () => {
360360
for (const v of testVectors) {
361361
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id === 0x0003) {
362-
if (isDeno()) {
362+
if (!isNode()) {
363363
continue;
364364
}
365365
await tester.test(v);
@@ -372,7 +372,7 @@ describe("RFC9180 conformance", () => {
372372
it("should match demonstrated values", async () => {
373373
for (const v of testVectors) {
374374
if (v.mode === 3 && v.kem_id < 0x0020 && v.aead_id === 0xFFFF) {
375-
if (isDeno()) {
375+
if (!isNode()) {
376376
continue;
377377
}
378378
await tester.test(v);

x/hpke-js/test/dhkemPrimitives.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HkdfSha256, X25519 } from "@hpke/dhkem-x25519";
66
import { HkdfSha512, X448 } from "@hpke/dhkem-x448";
77

88
import { HkdfSha384 } from "../src/kdfs/hkdfSha384.ts";
9-
import { isDeno } from "../../core/test/utils.ts";
9+
import { isNode } from "../../core/test/utils.ts";
1010

1111
describe("derivePublicKey", () => {
1212
describe("with valid parameters", () => {
@@ -45,7 +45,7 @@ describe("derivePublicKey", () => {
4545
});
4646

4747
it("should return a proper public key with Ec(DhkemP521HkdfSha512)", async () => {
48-
if (isDeno()) {
48+
if (!isNode()) {
4949
return;
5050
}
5151
const kdf = new HkdfSha512();
@@ -114,7 +114,7 @@ describe("derivePublicKey", () => {
114114
});
115115

116116
it("should throw DeserializeError on Ec(DhkemP256HkdfSha256) with a P-521 private key", async () => {
117-
if (isDeno()) {
117+
if (!isNode()) {
118118
return;
119119
}
120120
const kdf = new HkdfSha256();
@@ -193,7 +193,7 @@ describe("derivePublicKey", () => {
193193
});
194194

195195
it("should throw DeserializeError on X25519 with a P-521 private key", async () => {
196-
if (isDeno()) {
196+
if (!isNode()) {
197197
return;
198198
}
199199
const kdf = new HkdfSha256();
@@ -248,7 +248,7 @@ describe("derivePublicKey", () => {
248248
});
249249

250250
it("should throw DeserializeError on X448 with a P-521 private key", async () => {
251-
if (isDeno()) {
251+
if (!isNode()) {
252252
return;
253253
}
254254
const kdf = new HkdfSha512();

x/hpke-js/test/keyValidationEc.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ConformanceTester } from "./conformanceTester.ts";
44
import type { WycheproofTestVector } from "./testVector.ts";
55

66
import { createConformanceTester } from "./conformanceTester.ts";
7-
import { isDeno, testVectorPath } from "../../core/test/utils.ts";
7+
import { isNode, testVectorPath } from "../../core/test/utils.ts";
88

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

2323
describe("P-256", () => {
2424
it("should validate properly", async () => {
25-
if (isDeno()) {
25+
if (!isNode()) {
2626
return;
2727
}
2828

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

4848
describe("P-384", () => {
4949
it("should validate properly", async () => {
50-
if (isDeno()) {
50+
if (!isNode()) {
5151
return;
5252
}
5353

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

7373
describe("P-521", () => {
7474
it("should validate properly", async () => {
75-
if (isDeno()) {
75+
if (!isNode()) {
7676
return;
7777
}
7878

x/hpke-js/test/sample.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DhkemP384HkdfSha384 } from "../src/kems/dhkemP384.ts";
1111
import { DhkemP521HkdfSha512 } from "../src/kems/dhkemP521.ts";
1212
import { HkdfSha384 } from "../src/kdfs/hkdfSha384.ts";
1313

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

1616
describe("README examples", () => {
1717
describe("Base mode with DhkemP256HkdfSha256/HkdfSha256/Aes128Gcm", () => {
@@ -250,7 +250,7 @@ describe("README examples", () => {
250250

251251
describe("Base mode with DhkemP521HkdfSha512/HkdfSha512/Aes128Gcm", () => {
252252
it("should work normally with ids", async () => {
253-
if (isDeno()) {
253+
if (!isNode()) {
254254
return;
255255
}
256256

@@ -285,7 +285,7 @@ describe("README examples", () => {
285285
});
286286

287287
it("should work normally with instances", async () => {
288-
if (isDeno()) {
288+
if (!isNode()) {
289289
return;
290290
}
291291

@@ -320,7 +320,7 @@ describe("README examples", () => {
320320
});
321321

322322
it("should work normally with importKey('jwk')", async () => {
323-
if (isDeno()) {
323+
if (!isNode()) {
324324
return;
325325
}
326326

@@ -1035,7 +1035,7 @@ describe("README examples", () => {
10351035

10361036
describe("Oblivious HTTP with DhkemP384HkdfSha384/HkdfSha384/Aes256Gcm", () => {
10371037
it("should work normally", async () => {
1038-
if (isDeno()) {
1038+
if (!isNode()) {
10391039
return;
10401040
}
10411041
const te = new TextEncoder();
@@ -1122,7 +1122,7 @@ describe("README examples", () => {
11221122

11231123
describe("Oblivious HTTP with DhkemP521HkdfSha512/HkdfSha512/Aes256Gcm", () => {
11241124
it("should work normally", async () => {
1125-
if (isDeno()) {
1125+
if (!isNode()) {
11261126
return;
11271127
}
11281128
const te = new TextEncoder();

0 commit comments

Comments
 (0)