diff --git a/lib/internal/crypto/cipher.js b/lib/internal/crypto/cipher.js index 75d4af717f27dd..d1c45bfdce0e0d 100644 --- a/lib/internal/crypto/cipher.js +++ b/lib/internal/crypto/cipher.js @@ -33,7 +33,7 @@ const { StringDecoder } = require('string_decoder'); const { inherits } = require('util'); const { normalizeEncoding } = require('internal/util'); -function rsaPublic(method, defaultPadding) { +function rsaFunctionFor(method, defaultPadding) { return function(options, buffer) { const key = options.key || options; const padding = options.padding || defaultPadding; @@ -42,19 +42,10 @@ function rsaPublic(method, defaultPadding) { }; } -function rsaPrivate(method, defaultPadding) { - return function(options, buffer) { - const key = options.key || options; - const passphrase = options.passphrase || null; - const padding = options.padding || defaultPadding; - return method(toBuf(key), buffer, padding, passphrase); - }; -} - -const publicEncrypt = rsaPublic(_publicEncrypt, RSA_PKCS1_OAEP_PADDING); -const publicDecrypt = rsaPublic(_publicDecrypt, RSA_PKCS1_PADDING); -const privateEncrypt = rsaPrivate(_privateEncrypt, RSA_PKCS1_PADDING); -const privateDecrypt = rsaPrivate(_privateDecrypt, RSA_PKCS1_OAEP_PADDING); +const publicEncrypt = rsaFunctionFor(_publicEncrypt, RSA_PKCS1_OAEP_PADDING); +const publicDecrypt = rsaFunctionFor(_publicDecrypt, RSA_PKCS1_PADDING); +const privateEncrypt = rsaFunctionFor(_privateEncrypt, RSA_PKCS1_PADDING); +const privateDecrypt = rsaFunctionFor(_privateDecrypt, RSA_PKCS1_OAEP_PADDING); function getDecoder(decoder, encoding) { encoding = normalizeEncoding(encoding);