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

Function encapsulate

lib/internal/crypto/kem.js:33–70  ·  view source on GitHub ↗
(key, callback)

Source from the content-addressed store, hash-verified

31} = require('internal/crypto/util');
32
33function encapsulate(key, callback) {
34 if (!KEMEncapsulateJob)
35 throw new ERR_CRYPTO_KEM_NOT_SUPPORTED();
36
37 if (callback !== undefined)
38 validateFunction(callback, 'callback');
39
40 const {
41 data: keyData,
42 format: keyFormat,
43 type: keyType,
44 passphrase: keyPassphrase,
45 namedCurve: keyNamedCurve,
46 } = preparePublicOrPrivateKey(key);
47
48 const job = new KEMEncapsulateJob(
49 callback ? kCryptoJobAsync : kCryptoJobSync,
50 keyData,
51 keyFormat,
52 keyType,
53 keyPassphrase,
54 keyNamedCurve);
55
56 if (!callback) {
57 const { 0: err, 1: result } = job.run();
58 if (err !== undefined)
59 throw err;
60 const { 0: sharedKey, 1: ciphertext } = result;
61 return { sharedKey, ciphertext };
62 }
63
64 job.ondone = (error, result) => {
65 if (error) return FunctionPrototypeCall(callback, job, error);
66 const { 0: sharedKey, 1: ciphertext } = result;
67 FunctionPrototypeCall(callback, job, null, { sharedKey, ciphertext });
68 };
69 job.run();
70}
71
72function decapsulate(key, ciphertext, callback) {
73 if (!KEMDecapsulateJob)

Callers

nothing calls this directly

Calls 2

runMethod · 0.45

Tested by

no test coverage detected