Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crypto/unstable_aes_gcm.ts → crypto/aes_gcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type { Uint8Array_ };
*
* @example Usage
* ```ts
* import { encryptAesGcm, decryptAesGcm } from "@std/crypto/unstable-aes-gcm";
* import { encryptAesGcm, decryptAesGcm } from "@std/crypto/aes-gcm";
* import { assertEquals } from "@std/assert";
*
* const key = await crypto.subtle.generateKey(
Expand Down Expand Up @@ -48,7 +48,7 @@ export interface AesGcmOptions {
*
* @example Usage
* ```ts
* import { encryptAesGcm } from "@std/crypto/unstable-aes-gcm";
* import { encryptAesGcm } from "@std/crypto/aes-gcm";
* import { assertNotEquals } from "@std/assert";
*
* const key = await crypto.subtle.generateKey(
Expand Down Expand Up @@ -88,6 +88,7 @@ export async function encryptAesGcm(
iv: nonce,
tagLength: TAG_LENGTH * 8,
};

if (options?.additionalData !== undefined) {
params.additionalData = options.additionalData;
}
Expand All @@ -109,7 +110,7 @@ export async function encryptAesGcm(
*
* @example Usage
* ```ts
* import { decryptAesGcm, encryptAesGcm } from "@std/crypto/unstable-aes-gcm";
* import { decryptAesGcm, encryptAesGcm } from "@std/crypto/aes-gcm";
* import { assertEquals } from "@std/assert";
*
* const key = await crypto.subtle.generateKey(
Expand Down
20 changes: 19 additions & 1 deletion crypto/unstable_aes_gcm_test.ts → crypto/aes_gcm_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2026 the Deno authors. MIT license.

import { assertEquals, assertNotEquals, assertRejects } from "@std/assert";
import { decryptAesGcm, encryptAesGcm } from "./unstable_aes_gcm.ts";
import { decryptAesGcm, encryptAesGcm } from "./aes_gcm.ts";

const encoder = new TextEncoder();

Expand Down Expand Up @@ -192,3 +192,21 @@ Deno.test("encryptAesGcm()/decryptAesGcm() round-trips DataView inputs", async (
const decrypted = await decryptAesGcm(key, encryptedView);
assertEquals(decrypted, plaintext);
});

Deno.test("encryptAesGcm()/decryptAesGcm() round-trips Uint8Array subarray with non-zero byteOffset", async () => {
const key = await generateKey(256);
const plaintext = encoder.encode("offset test");

const paddedPlaintext = new Uint8Array(16 + plaintext.byteLength);
paddedPlaintext.set(plaintext, 16);
const plaintextSubarray = paddedPlaintext.subarray(16);

const encrypted = await encryptAesGcm(key, plaintextSubarray);

const paddedEncrypted = new Uint8Array(8 + encrypted.byteLength);
paddedEncrypted.set(encrypted, 8);
const encryptedSubarray = paddedEncrypted.subarray(8);

const decrypted = await decryptAesGcm(key, encryptedSubarray);
assertEquals(decrypted, plaintext);
});
2 changes: 1 addition & 1 deletion crypto/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
".": "./mod.ts",
"./crypto": "./crypto.ts",
"./timing-safe-equal": "./timing_safe_equal.ts",
"./unstable-aes-gcm": "./unstable_aes_gcm.ts"
"./aes-gcm": "./aes_gcm.ts"
},
"exclude": [
"_wasm/target"
Expand Down
1 change: 1 addition & 0 deletions crypto/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
* @module
*/

export * from "./aes_gcm.ts";
export * from "./crypto.ts";
export * from "./timing_safe_equal.ts";
Loading