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: move process.binding('crypto') to internal #22426

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;
// Lazily loaded
var crypto = null;

const { SecureContext: NativeSecureContext } = process.binding('crypto');

const { internalBinding } = require('internal/bootstrap/loaders');
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
function SecureContext(secureProtocol, secureOptions, context) {
if (!(this instanceof SecureContext)) {
return new SecureContext(secureProtocol, secureOptions, context);
Expand Down
5 changes: 2 additions & 3 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ const tls_wrap = process.binding('tls_wrap');
const { TCP, constants: TCPConstants } = process.binding('tcp_wrap');
const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap');
const { owner_symbol } = require('internal/async_hooks').symbols;
const {
SecureContext: NativeSecureContext
} = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const { SecureContext: NativeSecureContext } = internalBinding('crypto');
const {
ERR_INVALID_ARG_TYPE,
ERR_MULTIPLE_CALLBACK,
Expand Down
6 changes: 2 additions & 4 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
} = require('internal/util');
assertCrypto();

const { internalBinding } = require('internal/bootstrap/loaders');
const {
ERR_CRYPTO_FIPS_FORCED,
ERR_CRYPTO_FIPS_UNAVAILABLE
Expand All @@ -39,10 +40,7 @@ const {
fipsMode,
fipsForced
} = process.binding('config');
const {
getFipsCrypto,
setFipsCrypto,
} = process.binding('crypto');
const { getFipsCrypto, setFipsCrypto } = internalBinding('crypto');
const {
randomBytes,
randomFill,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@
'http_parser',
'v8',
'stream_wrap',
'signal_wrap']);
'signal_wrap',
'crypto']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
internalBinding(name) :
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/certificate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';

const { internalBinding } = require('internal/bootstrap/loaders');
const {
certExportChallenge,
certExportPublicKey,
certVerifySpkac
} = process.binding('crypto');
} = internalBinding('crypto');

const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
const { isArrayBufferView } = require('internal/util/types');
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const {

const { isArrayBufferView } = require('internal/util/types');

const { internalBinding } = require('internal/bootstrap/loaders');
const {
CipherBase,
privateDecrypt: _privateDecrypt,
privateEncrypt: _privateEncrypt,
publicDecrypt: _publicDecrypt,
publicEncrypt: _publicEncrypt
} = process.binding('crypto');
} = internalBinding('crypto');

const assert = require('assert');
const LazyTransform = require('internal/streams/lazy_transform');
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/pbkdf2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const { AsyncWrap, Providers } = process.binding('async_wrap');
const { Buffer } = require('buffer');
const { INT_MAX, pbkdf2: _pbkdf2 } = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const { INT_MAX, pbkdf2: _pbkdf2 } = internalBinding('crypto');
const { validateInt32 } = require('internal/validators');
const {
ERR_CRYPTO_INVALID_DIGEST,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const { AsyncWrap, Providers } = process.binding('async_wrap');
const { Buffer, kMaxLength } = require('buffer');
const { randomBytes: _randomBytes } = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const { randomBytes: _randomBytes } = internalBinding('crypto');
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/scrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const { AsyncWrap, Providers } = process.binding('async_wrap');
const { Buffer } = require('buffer');
const { INT_MAX, scrypt: _scrypt } = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const { INT_MAX, scrypt: _scrypt } = internalBinding('crypto');
const { validateInt32 } = require('internal/validators');
const {
ERR_CRYPTO_SCRYPT_INVALID_PARAMETER,
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/crypto/sig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const {
ERR_INVALID_OPT_VALUE
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const {
Sign: _Sign,
Verify: _Verify
} = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const { Sign: _Sign, Verify: _Verify } = internalBinding('crypto');
const {
RSA_PSS_SALTLEN_AUTO,
RSA_PKCS1_PADDING
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const { internalBinding } = require('internal/bootstrap/loaders');
const {
getCiphers: _getCiphers,
getCurves: _getCurves,
getHashes: _getHashes,
setEngine: _setEngine,
timingSafeEqual: _timingSafeEqual
} = process.binding('crypto');
} = internalBinding('crypto');

const {
ENGINE_METHOD_ALL
Expand Down
3 changes: 2 additions & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const { isUint8Array } = require('internal/util/types');

const net = require('net');
const url = require('url');
const binding = process.binding('crypto');
const { internalBinding } = require('internal/bootstrap/loaders');
const binding = internalBinding('crypto');
const { Buffer } = require('buffer');
const EventEmitter = require('events');
const { URL } = require('internal/url');
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5256,4 +5256,4 @@ void Initialize(Local<Object> target,
} // namespace crypto
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(crypto, node::crypto::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)
4 changes: 3 additions & 1 deletion test/parallel/test-crypto-scrypt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (!common.hasCrypto)
Expand All @@ -6,7 +7,8 @@ if (!common.hasCrypto)
const assert = require('assert');
const crypto = require('crypto');

if (typeof process.binding('crypto').scrypt !== 'function')
const { internalBinding } = require('internal/test/binding');
if (typeof internalBinding('crypto').scrypt !== 'function')
common.skip('no scrypt support');

const good = [
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-clientcertengine-unsupported.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');

if (!common.hasCrypto)
common.skip('missing crypto');

// Monkey-patch SecureContext
const binding = process.binding('crypto');
const { internalBinding } = require('internal/test/binding');
const binding = internalBinding('crypto');
const NativeSecureContext = binding.SecureContext;

binding.SecureContext = function() {
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
testInitialized(this, 'AsyncWrap');
}));

if (typeof process.binding('crypto').scrypt === 'function') {
if (typeof internalBinding('crypto').scrypt === 'function') {
crypto.scrypt('password', 'salt', 8, common.mustCall(function() {
testInitialized(this, 'AsyncWrap');
}));
Expand Down