ioBI
Deno4y ago
29 replies
ioB

Updating digest with web crypto

For some context, I'm updating some code that was importing from
std/hash
(specifically
std/hash/sha256
) to use
std/crypto
since the hash submodule is long gone.

I've run up against a case where I'm not really sure what I should do to move forward. The code looks something like this:
const digest = new Sha256()

for await (const chunk of generate.chunks()) {
  digest.update(chunk)
}

if(some_condition) {
  digest.update(bonus_chunk)
}

return digest.hex()


Is this possible to handle in the web crypto standard? I'm pretty sure I should just be able to aggregate the chunks into one massive uint8array or something but I feel like there is no reason to buffer the whole thing into memory.

Any ideas?
Was this page helpful?