2018-09-02 15:00:01 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 17:04:46 +00:00
|
|
|
const {
|
2020-08-25 17:05:51 +00:00
|
|
|
FunctionPrototypeCall,
|
2019-11-22 17:04:46 +00:00
|
|
|
ObjectDefineProperty,
|
2021-02-12 14:54:06 +00:00
|
|
|
SafeArrayIterator,
|
2019-11-22 17:04:46 +00:00
|
|
|
} = primordials;
|
2019-04-09 07:55:53 +00:00
|
|
|
|
2018-09-02 15:00:01 +00:00
|
|
|
const {
|
2020-08-25 17:05:51 +00:00
|
|
|
DhKeyPairGenJob,
|
|
|
|
DsaKeyPairGenJob,
|
|
|
|
EcKeyPairGenJob,
|
|
|
|
NidKeyPairGenJob,
|
|
|
|
RsaKeyPairGenJob,
|
|
|
|
SecretKeyGenJob,
|
|
|
|
kCryptoJobAsync,
|
|
|
|
kCryptoJobSync,
|
|
|
|
kKeyVariantRSA_PSS,
|
2021-04-01 20:06:39 +00:00
|
|
|
kKeyVariantRSA_SSA_PKCS1_v1_5,
|
2019-03-09 23:51:56 +00:00
|
|
|
EVP_PKEY_ED25519,
|
|
|
|
EVP_PKEY_ED448,
|
2019-03-19 11:09:01 +00:00
|
|
|
EVP_PKEY_X25519,
|
|
|
|
EVP_PKEY_X448,
|
2018-09-02 15:00:01 +00:00
|
|
|
OPENSSL_EC_NAMED_CURVE,
|
2020-08-25 17:05:51 +00:00
|
|
|
OPENSSL_EC_EXPLICIT_CURVE,
|
2018-09-02 15:00:01 +00:00
|
|
|
} = internalBinding('crypto');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
2018-09-20 17:53:44 +00:00
|
|
|
const {
|
2020-08-25 17:05:51 +00:00
|
|
|
PublicKeyObject,
|
|
|
|
PrivateKeyObject,
|
|
|
|
SecretKeyObject,
|
2018-09-20 17:53:44 +00:00
|
|
|
parsePublicKeyEncoding,
|
|
|
|
parsePrivateKeyEncoding,
|
|
|
|
} = require('internal/crypto/keys');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
kAesKeyLengths,
|
|
|
|
} = require('internal/crypto/util');
|
|
|
|
|
2022-05-21 09:51:28 +00:00
|
|
|
const {
|
|
|
|
customPromisifyArgs,
|
|
|
|
kEmptyObject,
|
|
|
|
} = require('internal/util');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
2020-08-08 16:01:59 +00:00
|
|
|
const {
|
2022-01-24 16:09:16 +00:00
|
|
|
validateFunction,
|
2022-04-04 10:38:35 +00:00
|
|
|
validateBuffer,
|
2020-08-08 16:01:59 +00:00
|
|
|
validateString,
|
2020-08-25 17:05:51 +00:00
|
|
|
validateInteger,
|
2020-08-08 16:01:59 +00:00
|
|
|
validateObject,
|
2020-08-25 17:05:51 +00:00
|
|
|
validateOneOf,
|
2022-04-04 10:38:35 +00:00
|
|
|
validateInt32,
|
|
|
|
validateUint32,
|
2020-08-08 16:01:59 +00:00
|
|
|
} = require('internal/validators');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
2018-09-02 15:00:01 +00:00
|
|
|
const {
|
2020-08-25 17:05:51 +00:00
|
|
|
codes: {
|
|
|
|
ERR_INCOMPATIBLE_OPTION_PAIR,
|
|
|
|
ERR_INVALID_ARG_VALUE,
|
|
|
|
ERR_MISSING_OPTION,
|
2023-02-28 11:14:11 +00:00
|
|
|
},
|
2020-08-25 17:05:51 +00:00
|
|
|
} = require('internal/errors');
|
2018-09-02 15:00:01 +00:00
|
|
|
|
2018-09-20 17:53:44 +00:00
|
|
|
const { isArrayBufferView } = require('internal/util/types');
|
|
|
|
|
2022-09-03 12:36:20 +00:00
|
|
|
function isJwk(obj) {
|
|
|
|
return obj != null && obj.kty !== undefined;
|
|
|
|
}
|
|
|
|
|
2018-09-20 17:53:44 +00:00
|
|
|
function wrapKey(key, ctor) {
|
2021-07-09 04:07:32 +00:00
|
|
|
if (typeof key === 'string' ||
|
|
|
|
isArrayBufferView(key) ||
|
|
|
|
isJwk(key))
|
2018-09-20 17:53:44 +00:00
|
|
|
return key;
|
|
|
|
return new ctor(key);
|
|
|
|
}
|
|
|
|
|
2018-09-02 15:00:01 +00:00
|
|
|
function generateKeyPair(type, options, callback) {
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
callback = options;
|
|
|
|
options = undefined;
|
|
|
|
}
|
2022-01-24 16:09:16 +00:00
|
|
|
validateFunction(callback, 'callback');
|
2018-09-02 15:00:01 +00:00
|
|
|
|
2020-10-29 05:22:41 +00:00
|
|
|
const job = createJob(kCryptoJobAsync, type, options);
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
job.ondone = (error, result) => {
|
|
|
|
if (error) return FunctionPrototypeCall(callback, job, error);
|
2018-09-20 17:53:44 +00:00
|
|
|
// If no encoding was chosen, return key objects instead.
|
2021-02-12 14:54:06 +00:00
|
|
|
let { 0: pubkey, 1: privkey } = result;
|
2018-09-20 17:53:44 +00:00
|
|
|
pubkey = wrapKey(pubkey, PublicKeyObject);
|
|
|
|
privkey = wrapKey(privkey, PrivateKeyObject);
|
2020-08-25 17:05:51 +00:00
|
|
|
FunctionPrototypeCall(callback, job, null, pubkey, privkey);
|
2018-09-02 15:00:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-25 17:05:51 +00:00
|
|
|
job.run();
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:04:46 +00:00
|
|
|
ObjectDefineProperty(generateKeyPair, customPromisifyArgs, {
|
2022-06-03 08:23:58 +00:00
|
|
|
__proto__: null,
|
2018-09-10 20:36:14 +00:00
|
|
|
value: ['publicKey', 'privateKey'],
|
2023-02-28 11:14:11 +00:00
|
|
|
enumerable: false,
|
2018-09-10 20:36:14 +00:00
|
|
|
});
|
|
|
|
|
2018-09-02 15:00:01 +00:00
|
|
|
function generateKeyPairSync(type, options) {
|
2020-10-29 05:22:41 +00:00
|
|
|
return handleError(createJob(kCryptoJobSync, type, options).run());
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 06:09:17 +00:00
|
|
|
function handleError(ret) {
|
2021-01-08 00:27:29 +00:00
|
|
|
if (ret == null)
|
2018-09-02 15:00:01 +00:00
|
|
|
return; // async
|
|
|
|
|
2021-02-12 14:54:06 +00:00
|
|
|
const { 0: err, 1: keys } = ret;
|
2018-09-02 15:00:01 +00:00
|
|
|
if (err !== undefined)
|
|
|
|
throw err;
|
|
|
|
|
2021-02-12 14:54:06 +00:00
|
|
|
const { 0: publicKey, 1: privateKey } = keys;
|
2021-01-08 00:27:29 +00:00
|
|
|
|
2019-01-03 17:59:34 +00:00
|
|
|
// If no encoding was chosen, return key objects instead.
|
|
|
|
return {
|
|
|
|
publicKey: wrapKey(publicKey, PublicKeyObject),
|
2023-02-28 11:14:11 +00:00
|
|
|
privateKey: wrapKey(privateKey, PrivateKeyObject),
|
2019-01-03 17:59:34 +00:00
|
|
|
};
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2022-05-21 09:51:28 +00:00
|
|
|
function parseKeyEncoding(keyType, options = kEmptyObject) {
|
2018-09-02 15:00:01 +00:00
|
|
|
const { publicKeyEncoding, privateKeyEncoding } = options;
|
|
|
|
|
2018-09-20 17:53:44 +00:00
|
|
|
let publicFormat, publicType;
|
|
|
|
if (publicKeyEncoding == null) {
|
|
|
|
publicFormat = publicType = undefined;
|
|
|
|
} else if (typeof publicKeyEncoding === 'object') {
|
|
|
|
({
|
|
|
|
format: publicFormat,
|
2023-02-28 11:14:11 +00:00
|
|
|
type: publicType,
|
2018-09-20 17:53:44 +00:00
|
|
|
} = parsePublicKeyEncoding(publicKeyEncoding, keyType,
|
|
|
|
'publicKeyEncoding'));
|
2018-09-02 15:00:01 +00:00
|
|
|
} else {
|
2020-08-08 16:01:59 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('options.publicKeyEncoding',
|
|
|
|
publicKeyEncoding);
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 17:53:44 +00:00
|
|
|
let privateFormat, privateType, cipher, passphrase;
|
|
|
|
if (privateKeyEncoding == null) {
|
|
|
|
privateFormat = privateType = undefined;
|
|
|
|
} else if (typeof privateKeyEncoding === 'object') {
|
|
|
|
({
|
|
|
|
format: privateFormat,
|
|
|
|
type: privateType,
|
|
|
|
cipher,
|
2023-02-28 11:14:11 +00:00
|
|
|
passphrase,
|
2018-09-20 17:53:44 +00:00
|
|
|
} = parsePrivateKeyEncoding(privateKeyEncoding, keyType,
|
|
|
|
'privateKeyEncoding'));
|
2018-09-02 15:00:01 +00:00
|
|
|
} else {
|
2020-08-08 16:01:59 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('options.privateKeyEncoding',
|
|
|
|
privateKeyEncoding);
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:05:51 +00:00
|
|
|
return [
|
|
|
|
publicFormat,
|
|
|
|
publicType,
|
|
|
|
privateFormat,
|
|
|
|
privateType,
|
|
|
|
cipher,
|
2021-02-06 13:36:58 +00:00
|
|
|
passphrase,
|
2020-08-25 17:05:51 +00:00
|
|
|
];
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 05:22:41 +00:00
|
|
|
function createJob(mode, type, options) {
|
2018-12-11 15:24:22 +00:00
|
|
|
validateString(type, 'type');
|
2018-09-02 15:00:01 +00:00
|
|
|
|
2021-02-12 14:54:06 +00:00
|
|
|
const encoding = new SafeArrayIterator(parseKeyEncoding(type, options));
|
2018-09-02 15:00:01 +00:00
|
|
|
|
2020-08-08 16:01:59 +00:00
|
|
|
if (options !== undefined)
|
|
|
|
validateObject(options, 'options');
|
2019-03-09 23:51:56 +00:00
|
|
|
|
2018-09-02 15:00:01 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'rsa':
|
2019-03-16 22:51:26 +00:00
|
|
|
case 'rsa-pss':
|
2020-08-25 17:05:51 +00:00
|
|
|
{
|
|
|
|
validateObject(options, 'options');
|
|
|
|
const { modulusLength } = options;
|
2022-04-04 10:38:35 +00:00
|
|
|
validateUint32(modulusLength, 'options.modulusLength');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
let { publicExponent } = options;
|
|
|
|
if (publicExponent == null) {
|
|
|
|
publicExponent = 0x10001;
|
2022-04-04 10:38:35 +00:00
|
|
|
} else {
|
|
|
|
validateUint32(publicExponent, 'options.publicExponent');
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
if (type === 'rsa') {
|
|
|
|
return new RsaKeyPairGenJob(
|
|
|
|
mode,
|
2021-04-01 20:06:39 +00:00
|
|
|
kKeyVariantRSA_SSA_PKCS1_v1_5, // Used also for RSA-OAEP
|
2020-08-25 17:05:51 +00:00
|
|
|
modulusLength,
|
|
|
|
publicExponent,
|
|
|
|
...encoding);
|
|
|
|
}
|
|
|
|
|
2021-08-29 08:09:48 +00:00
|
|
|
const {
|
2023-02-28 11:14:11 +00:00
|
|
|
hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength,
|
2021-08-29 08:09:48 +00:00
|
|
|
} = options;
|
2022-03-03 18:18:56 +00:00
|
|
|
|
2022-04-04 10:38:35 +00:00
|
|
|
if (saltLength !== undefined)
|
|
|
|
validateInt32(saltLength, 'options.saltLength', 0);
|
|
|
|
if (hashAlgorithm !== undefined)
|
|
|
|
validateString(hashAlgorithm, 'options.hashAlgorithm');
|
|
|
|
if (mgf1HashAlgorithm !== undefined)
|
|
|
|
validateString(mgf1HashAlgorithm, 'options.mgf1HashAlgorithm');
|
2021-08-29 08:09:48 +00:00
|
|
|
if (hash !== undefined) {
|
2022-11-30 21:14:33 +00:00
|
|
|
process.emitWarning(
|
2021-08-29 08:09:48 +00:00
|
|
|
'"options.hash" is deprecated, ' +
|
|
|
|
'use "options.hashAlgorithm" instead.',
|
|
|
|
'DeprecationWarning',
|
|
|
|
'DEP0154');
|
2022-04-04 10:38:35 +00:00
|
|
|
validateString(hash, 'options.hash');
|
|
|
|
if (hashAlgorithm && hash !== hashAlgorithm) {
|
2021-08-29 08:09:48 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('options.hash', hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mgf1Hash !== undefined) {
|
2022-11-30 21:14:33 +00:00
|
|
|
process.emitWarning(
|
2021-08-29 08:09:48 +00:00
|
|
|
'"options.mgf1Hash" is deprecated, ' +
|
|
|
|
'use "options.mgf1HashAlgorithm" instead.',
|
|
|
|
'DeprecationWarning',
|
|
|
|
'DEP0154');
|
2022-04-04 10:38:35 +00:00
|
|
|
validateString(mgf1Hash, 'options.mgf1Hash');
|
|
|
|
if (mgf1HashAlgorithm && mgf1Hash !== mgf1HashAlgorithm) {
|
2021-08-29 08:09:48 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE('options.mgf1Hash', mgf1Hash);
|
|
|
|
}
|
|
|
|
}
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
return new RsaKeyPairGenJob(
|
|
|
|
mode,
|
|
|
|
kKeyVariantRSA_PSS,
|
|
|
|
modulusLength,
|
|
|
|
publicExponent,
|
2021-08-29 08:09:48 +00:00
|
|
|
hashAlgorithm || hash,
|
|
|
|
mgf1HashAlgorithm || mgf1Hash,
|
2020-08-25 17:05:51 +00:00
|
|
|
saltLength,
|
|
|
|
...encoding);
|
|
|
|
}
|
2018-09-02 15:00:01 +00:00
|
|
|
case 'dsa':
|
2020-08-25 17:05:51 +00:00
|
|
|
{
|
|
|
|
validateObject(options, 'options');
|
|
|
|
const { modulusLength } = options;
|
2022-04-04 10:38:35 +00:00
|
|
|
validateUint32(modulusLength, 'options.modulusLength');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
let { divisorLength } = options;
|
|
|
|
if (divisorLength == null) {
|
|
|
|
divisorLength = -1;
|
2022-04-04 10:38:35 +00:00
|
|
|
} else
|
|
|
|
validateInt32(divisorLength, 'options.divisorLength', 0);
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
return new DsaKeyPairGenJob(
|
|
|
|
mode,
|
|
|
|
modulusLength,
|
|
|
|
divisorLength,
|
|
|
|
...encoding);
|
|
|
|
}
|
2018-09-02 15:00:01 +00:00
|
|
|
case 'ec':
|
2020-08-25 17:05:51 +00:00
|
|
|
{
|
|
|
|
validateObject(options, 'options');
|
|
|
|
const { namedCurve } = options;
|
2022-04-04 10:38:35 +00:00
|
|
|
validateString(namedCurve, 'options.namedCurve');
|
2020-08-25 17:05:51 +00:00
|
|
|
let { paramEncoding } = options;
|
|
|
|
if (paramEncoding == null || paramEncoding === 'named')
|
|
|
|
paramEncoding = OPENSSL_EC_NAMED_CURVE;
|
|
|
|
else if (paramEncoding === 'explicit')
|
|
|
|
paramEncoding = OPENSSL_EC_EXPLICIT_CURVE;
|
|
|
|
else
|
|
|
|
throw new ERR_INVALID_ARG_VALUE('options.paramEncoding', paramEncoding);
|
|
|
|
|
|
|
|
return new EcKeyPairGenJob(
|
|
|
|
mode,
|
|
|
|
namedCurve,
|
|
|
|
paramEncoding,
|
|
|
|
...encoding);
|
|
|
|
}
|
2019-03-09 23:51:56 +00:00
|
|
|
case 'ed25519':
|
|
|
|
case 'ed448':
|
2019-03-19 11:09:01 +00:00
|
|
|
case 'x25519':
|
|
|
|
case 'x448':
|
2020-08-25 17:05:51 +00:00
|
|
|
{
|
|
|
|
let id;
|
|
|
|
switch (type) {
|
|
|
|
case 'ed25519':
|
|
|
|
id = EVP_PKEY_ED25519;
|
|
|
|
break;
|
|
|
|
case 'ed448':
|
|
|
|
id = EVP_PKEY_ED448;
|
|
|
|
break;
|
|
|
|
case 'x25519':
|
|
|
|
id = EVP_PKEY_X25519;
|
|
|
|
break;
|
|
|
|
case 'x448':
|
|
|
|
id = EVP_PKEY_X448;
|
|
|
|
break;
|
2019-03-09 23:51:56 +00:00
|
|
|
}
|
2020-08-25 17:05:51 +00:00
|
|
|
return new NidKeyPairGenJob(mode, id, ...encoding);
|
|
|
|
}
|
2019-12-31 01:12:36 +00:00
|
|
|
case 'dh':
|
2020-08-25 17:05:51 +00:00
|
|
|
{
|
|
|
|
validateObject(options, 'options');
|
|
|
|
const { group, primeLength, prime, generator } = options;
|
|
|
|
if (group != null) {
|
|
|
|
if (prime != null)
|
|
|
|
throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'prime');
|
|
|
|
if (primeLength != null)
|
|
|
|
throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'primeLength');
|
|
|
|
if (generator != null)
|
|
|
|
throw new ERR_INCOMPATIBLE_OPTION_PAIR('group', 'generator');
|
2022-04-04 10:38:35 +00:00
|
|
|
|
|
|
|
validateString(group, 'options.group');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
return new DhKeyPairGenJob(mode, group, ...encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prime != null) {
|
|
|
|
if (primeLength != null)
|
|
|
|
throw new ERR_INCOMPATIBLE_OPTION_PAIR('prime', 'primeLength');
|
2022-04-04 10:38:35 +00:00
|
|
|
|
|
|
|
validateBuffer(prime, 'options.prime');
|
2020-08-25 17:05:51 +00:00
|
|
|
} else if (primeLength != null) {
|
2022-04-04 10:38:35 +00:00
|
|
|
validateInt32(primeLength, 'options.primeLength', 0);
|
2020-08-25 17:05:51 +00:00
|
|
|
} else {
|
|
|
|
throw new ERR_MISSING_OPTION(
|
|
|
|
'At least one of the group, prime, or primeLength options');
|
2019-12-31 01:12:36 +00:00
|
|
|
}
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
if (generator != null) {
|
2022-04-04 10:38:35 +00:00
|
|
|
validateInt32(generator, 'options.generator', 0);
|
2020-08-25 17:05:51 +00:00
|
|
|
}
|
|
|
|
return new DhKeyPairGenJob(
|
|
|
|
mode,
|
|
|
|
prime != null ? prime : primeLength,
|
|
|
|
generator == null ? 2 : generator,
|
|
|
|
...encoding);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Fall through
|
|
|
|
}
|
|
|
|
throw new ERR_INVALID_ARG_VALUE('type', type, 'must be a supported key type');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Symmetric Key Generation
|
|
|
|
|
|
|
|
function generateKeyJob(mode, keyType, options) {
|
|
|
|
validateString(keyType, 'type');
|
|
|
|
validateObject(options, 'options');
|
|
|
|
const { length } = options;
|
|
|
|
switch (keyType) {
|
|
|
|
case 'hmac':
|
2022-05-04 19:31:23 +00:00
|
|
|
validateInteger(length, 'options.length', 8, 2 ** 31 - 1);
|
2020-08-25 17:05:51 +00:00
|
|
|
break;
|
|
|
|
case 'aes':
|
|
|
|
validateOneOf(length, 'options.length', kAesKeyLengths);
|
2019-12-31 01:12:36 +00:00
|
|
|
break;
|
2018-09-02 15:00:01 +00:00
|
|
|
default:
|
2020-08-25 17:05:51 +00:00
|
|
|
throw new ERR_INVALID_ARG_VALUE(
|
|
|
|
'type',
|
|
|
|
keyType,
|
|
|
|
'must be a supported key type');
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:05:51 +00:00
|
|
|
return new SecretKeyGenJob(mode, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleGenerateKeyError(ret) {
|
|
|
|
if (ret === undefined)
|
|
|
|
return; // async
|
|
|
|
|
2021-02-12 14:54:06 +00:00
|
|
|
const { 0: err, 1: key } = ret;
|
2020-08-25 17:05:51 +00:00
|
|
|
if (err !== undefined)
|
|
|
|
throw err;
|
|
|
|
|
|
|
|
return wrapKey(key, SecretKeyObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateKey(type, options, callback) {
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
callback = options;
|
|
|
|
options = undefined;
|
2019-03-09 23:51:56 +00:00
|
|
|
}
|
2018-09-02 15:00:01 +00:00
|
|
|
|
2022-01-24 16:09:16 +00:00
|
|
|
validateFunction(callback, 'callback');
|
2020-08-25 17:05:51 +00:00
|
|
|
|
|
|
|
const job = generateKeyJob(kCryptoJobAsync, type, options);
|
|
|
|
|
|
|
|
job.ondone = (error, key) => {
|
|
|
|
if (error) return FunctionPrototypeCall(callback, job, error);
|
|
|
|
FunctionPrototypeCall(callback, job, null, wrapKey(key, SecretKeyObject));
|
|
|
|
};
|
|
|
|
|
|
|
|
handleGenerateKeyError(job.run());
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateKeySync(type, options) {
|
|
|
|
return handleGenerateKeyError(
|
|
|
|
generateKeyJob(kCryptoJobSync, type, options).run());
|
2018-09-02 15:00:01 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 17:05:51 +00:00
|
|
|
module.exports = {
|
|
|
|
generateKeyPair,
|
|
|
|
generateKeyPairSync,
|
|
|
|
generateKey,
|
|
|
|
generateKeySync,
|
|
|
|
};
|