MCPcopy Index your code
hub / github.com/nodejs/node / asyncDigest

Function asyncDigest

lib/internal/crypto/hash.js:212–289  ·  view source on GitHub ↗
(algorithm, data)

Source from the content-addressed store, hash-verified

210// Implementation for WebCrypto subtle.digest()
211
212function asyncDigest(algorithm, data) {
213 validateMaxBufferLength(data, 'data');
214
215 switch (algorithm.name) {
216 case 'SHA-1':
217 // Fall through
218 case 'SHA-256':
219 // Fall through
220 case 'SHA-384':
221 // Fall through
222 case 'SHA-512':
223 // Fall through
224 case 'SHA3-256':
225 // Fall through
226 case 'SHA3-384':
227 // Fall through
228 case 'SHA3-512':
229 return jobPromise(() => new HashJob(
230 kCryptoJobWebCrypto,
231 normalizeHashName(algorithm.name),
232 data));
233 case 'cSHAKE128':
234 // Fall through
235 case 'cSHAKE256': {
236 const outputLength = algorithm.outputLength;
237 if (algorithm.functionName?.byteLength ||
238 algorithm.customization?.byteLength) {
239 if (CShakeJob === undefined) {
240 throw lazyDOMException(
241 'Non-empty CShakeParams functionName or customization is not supported',
242 'NotSupportedError');
243 }
244
245 return jobPromise(() => new CShakeJob(
246 kCryptoJobWebCrypto,
247 algorithm.name,
248 data,
249 algorithm.functionName,
250 algorithm.customization,
251 outputLength));
252 }
253
254 const bits = jobPromise(() => new HashJob(
255 kCryptoJobWebCrypto,
256 normalizeHashName(algorithm.name),
257 data,
258 numBitsToBytes(outputLength) * 8));
259 if (outputLength % 8 === 0)
260 return bits;
261 return jobPromiseThen(bits, (bits) =>
262 TypedArrayPrototypeGetBuffer(truncateToBitLength(outputLength, bits)));
263 }
264 case 'TurboSHAKE128':
265 // Fall through
266 case 'TurboSHAKE256':
267 return jobPromise(() => new TurboShakeJob(
268 kCryptoJobWebCrypto,
269 algorithm.name,

Callers

nothing calls this directly

Calls 9

validateMaxBufferLengthFunction · 0.85
jobPromiseFunction · 0.85
normalizeHashNameFunction · 0.85
lazyDOMExceptionFunction · 0.85
numBitsToBytesFunction · 0.85
jobPromiseThenFunction · 0.85
truncateToBitLengthFunction · 0.85
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…