Skip to content

Commit

Permalink
Merge pull request #424 from dajiaji/add-is-deno-v1
Browse files Browse the repository at this point in the history
Add isDenoV1.
  • Loading branch information
dajiaji authored Oct 11, 2024
2 parents b173639 + 6dd69b5 commit a9ccc66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/common/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export {
hexToBytes,
i2Osp,
isCryptoKeyPair,
isDenoV1,
isNode,
kemToKeyGenAlgorithm,
loadCrypto,
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { KemId } from "../identifiers.ts";

export const isDenoV1 = (): boolean =>
// deno-lint-ignore no-explicit-any
(globalThis as any).process === undefined;

export function isNode(): boolean {
// deno-lint-ignore no-explicit-any
if ((globalThis as any).process === undefined) {
Expand Down
26 changes: 13 additions & 13 deletions packages/hpke-js/test/conformance.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";

import { isNode } from "@hpke/common";
import { isDenoV1, isNode } from "@hpke/common";

import type { ConformanceTester } from "./conformanceTester.ts";
import type { TestVector } from "./testVector.ts";
Expand Down Expand Up @@ -30,7 +30,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 (!isNode()) {
if (isDenoV1()) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -66,7 +66,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -79,7 +79,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -152,7 +152,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -165,7 +165,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -178,7 +178,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -251,7 +251,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -264,7 +264,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -277,7 +277,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand Down Expand Up @@ -350,7 +350,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -363,7 +363,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand All @@ -376,7 +376,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 (!isNode()) {
if (isDenoV1() || (v.kem_id === 0x0012 && !isNode())) {
continue;
}
await tester.test(v);
Expand Down

0 comments on commit a9ccc66

Please sign in to comment.