summaryrefslogtreecommitdiff
path: root/tests/unit_node/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_node/crypto')
-rw-r--r--tests/unit_node/crypto/crypto_key_test.ts44
-rw-r--r--tests/unit_node/crypto/crypto_misc_test.ts10
2 files changed, 53 insertions, 1 deletions
diff --git a/tests/unit_node/crypto/crypto_key_test.ts b/tests/unit_node/crypto/crypto_key_test.ts
index 7995ce5d3..5d206acc7 100644
--- a/tests/unit_node/crypto/crypto_key_test.ts
+++ b/tests/unit_node/crypto/crypto_key_test.ts
@@ -656,3 +656,47 @@ z6TExWlQMjt66nV7R8cRAkzmABrG+NW3e8Zpac7Lkuv+zu0S+K7c
assertEquals(publicKey.type, "public");
assertEquals(publicKey.asymmetricKeyType, "rsa");
});
+
+// https://github.com/denoland/deno/issues/26188
+Deno.test("generateKeyPair large pem", function () {
+ const passphrase = "mypassphrase";
+ const cipher = "aes-256-cbc";
+ const modulusLength = 4096;
+
+ generateKeyPairSync("rsa", {
+ modulusLength,
+ publicKeyEncoding: {
+ type: "spki",
+ format: "pem",
+ },
+ privateKeyEncoding: {
+ type: "pkcs8",
+ format: "pem",
+ cipher,
+ passphrase,
+ },
+ });
+});
+
+Deno.test("generateKeyPair promisify", async () => {
+ const passphrase = "mypassphrase";
+ const cipher = "aes-256-cbc";
+ const modulusLength = 4096;
+
+ const { privateKey, publicKey } = await promisify(generateKeyPair)("rsa", {
+ modulusLength,
+ publicKeyEncoding: {
+ type: "spki",
+ format: "pem",
+ },
+ privateKeyEncoding: {
+ type: "pkcs8",
+ format: "pem",
+ cipher,
+ passphrase,
+ },
+ });
+
+ assert(publicKey.startsWith("-----BEGIN PUBLIC KEY-----"));
+ assert(privateKey.startsWith("-----BEGIN PRIVATE KEY-----"));
+});
diff --git a/tests/unit_node/crypto/crypto_misc_test.ts b/tests/unit_node/crypto/crypto_misc_test.ts
index 47a48b1bf..007009339 100644
--- a/tests/unit_node/crypto/crypto_misc_test.ts
+++ b/tests/unit_node/crypto/crypto_misc_test.ts
@@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-import { randomFillSync, randomUUID } from "node:crypto";
+import { randomFillSync, randomUUID, timingSafeEqual } from "node:crypto";
+import { Buffer } from "node:buffer";
import { assert, assertEquals } from "../../unit/test_util.ts";
import { assertNotEquals } from "@std/assert";
@@ -28,3 +29,10 @@ Deno.test("[node/crypto.randomFillSync] array buffer view", () => {
assertEquals(buf.subarray(0, 8), new Uint8Array(8));
assertEquals(buf.subarray(24, 32), new Uint8Array(8));
});
+
+Deno.test("[node/crypto.timingSafeEqual] compares equal Buffer with different byteOffset", () => {
+ const a = Buffer.from([212, 213]);
+ const b = Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 212, 213]).subarray(8);
+
+ assert(timingSafeEqual(a, b));
+});