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
4 changes: 4 additions & 0 deletions crypto/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ const stdCrypto: StdCrypto = ((x) => x)({
subtle: {
...webCrypto.subtle,

/**
* Polyfills stream support until the Web Crypto API does so:
* @see {@link https://github.com/wintercg/proposal-webcrypto-streams}
*/
async digest(
algorithm: DigestAlgorithm,
data: BufferSource | AsyncIterable<BufferSource> | Iterable<BufferSource>,
Expand Down
27 changes: 27 additions & 0 deletions crypto/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ Deno.test(
expectedDigest,
);

assertEquals(
toHexString(
await stdCrypto.subtle.digest(
"SHA-384",
new ReadableStream({
start(controller) {
controller.enqueue(inputBytes);
controller.close();
},
}),
),
),
expectedDigest,
);

assertEquals(
toHexString(
await stdCrypto.subtle.digest(
Expand Down Expand Up @@ -126,6 +141,18 @@ Deno.test("[crypto/digest] Should return an ArrayBuffer", async () => {
})(),
)) instanceof ArrayBuffer,
);

assert(
(await stdCrypto.subtle.digest(
"BLAKE3",
new ReadableStream({
start(controller) {
controller.enqueue(inputBytes);
controller.close();
},
}),
)) instanceof ArrayBuffer,
);
});

Deno.test("[crypto/digest] Should not ignore length option", async () => {
Expand Down