MCPcopy
hub / github.com/mongodb/node-mongodb-native / HMAC

Function HMAC

src/cmap/auth/scram.ts:275–292  ·  view source on GitHub ↗
(
  method: CryptoMethod,
  key: Uint8Array,
  text: Uint8Array | string
)

Source from the content-addressed store, hash-verified

273}
274
275async function HMAC(
276 method: CryptoMethod,
277 key: Uint8Array,
278 text: Uint8Array | string
279): Promise<Uint8Array> {
280 const keyBuffer = ByteUtils.toLocalBufferType(key);
281 const cryptoKey = await crypto.subtle.importKey(
282 'raw',
283 keyBuffer,
284 { name: 'HMAC', hash: { name: method === 'sha256' ? 'SHA-256' : 'SHA-1' } },
285 false,
286 ['sign', 'verify']
287 );
288 const textData: Uint8Array = typeof text === 'string' ? new TextEncoder().encode(text) : text;
289 const textBuffer = ByteUtils.toLocalBufferType(textData);
290 const signature = await crypto.subtle.sign('HMAC', cryptoKey, textBuffer);
291 return new Uint8Array(signature);
292}
293
294interface HICache {
295 [key: string]: Uint8Array;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected