Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: make createXYZ inlineable #16067

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,69 @@ const {
} = require('internal/crypto/util');
const Certificate = require('internal/crypto/certificate');

// These helper functions are needed because the constructors can
// use new, in which case V8 cannot inline the recursive constructor call
function createHash(algorithm, options) {
return new Hash(algorithm, options);
}

function createCipher(cipher, password, options) {
return new Cipher(cipher, password, options);
}

function createCipheriv(cipher, key, iv, options) {
return new Cipheriv(cipher, key, iv, options);
}

function createDecipher(cipher, password, options) {
return new Decipher(cipher, password, options);
}

function createDecipheriv(cipher, key, iv, options) {
return new Decipheriv(cipher, key, iv, options);
}

function createDiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding);
}

function createDiffieHellmanGroup(name) {
return new DiffieHellmanGroup(name);
}

function createECDH(curve) {
return new ECDH(curve);
}

function createHmac(hmac, key, options) {
return new Hmac(hmac, key, options);
}

function createSign(algorithm, options) {
return new Sign(algorithm, options);
}

function createVerify(algorithm, options) {
return new Verify(algorithm, options);
}

module.exports = exports = {
// Methods
_toBuf: toBuf,
createCipher: Cipher,
createCipheriv: Cipheriv,
createDecipher: Decipher,
createDecipheriv: Decipheriv,
createDiffieHellman: DiffieHellman,
createDiffieHellmanGroup: DiffieHellmanGroup,
createECDH: ECDH,
createHash: Hash,
createHmac: Hmac,
createSign: Sign,
createVerify: Verify,
createCipher,
createCipheriv,
createDecipher,
createDecipheriv,
createDiffieHellman,
createDiffieHellmanGroup,
createECDH,
createHash,
createHmac,
createSign,
createVerify,
getCiphers,
getCurves,
getDiffieHellman: DiffieHellmanGroup,
getDiffieHellman: createDiffieHellmanGroup,
getHashes,
pbkdf2,
pbkdf2Sync,
Expand Down