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: deprecate _toBuf #22501

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,14 @@ With the current crypto API, having `Cipher.setAuthTag()` and
when called. They have never been documented and will be removed in a future
release.

<a id="DEP00XX"></a>
### DEP00XX: crypto._toBuf()

Type: Runtime

The `crypto._toBuf()` function was not designed to be used by modules outside
of Node.js core and will become unavailable in the future.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change "will become unavailable" with "will be removed"?


[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down
16 changes: 8 additions & 8 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const {

const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;

// Lazily loaded
var crypto = null;
// Lazily loaded from internal/crypto/util.
let toBuf = null;

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

Expand Down Expand Up @@ -178,26 +178,26 @@ exports.createSecureContext = function createSecureContext(options, context) {
}

if (options.pfx) {
if (!crypto)
crypto = require('crypto');
if (!toBuf)
toBuf = require('internal/crypto/util').toBuf;

if (Array.isArray(options.pfx)) {
for (i = 0; i < options.pfx.length; i++) {
const pfx = options.pfx[i];
const raw = pfx.buf ? pfx.buf : pfx;
const buf = crypto._toBuf(raw);
const buf = toBuf(raw);
const passphrase = pfx.passphrase || options.passphrase;
if (passphrase) {
c.context.loadPKCS12(buf, crypto._toBuf(passphrase));
c.context.loadPKCS12(buf, toBuf(passphrase));
} else {
c.context.loadPKCS12(buf);
}
}
} else {
const buf = crypto._toBuf(options.pfx);
const buf = toBuf(options.pfx);
const passphrase = options.passphrase;
if (passphrase) {
c.context.loadPKCS12(buf, crypto._toBuf(passphrase));
c.context.loadPKCS12(buf, toBuf(passphrase));
} else {
c.context.loadPKCS12(buf);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function createVerify(algorithm, options) {

module.exports = exports = {
// Methods
_toBuf: toBuf,
_toBuf: deprecate(toBuf, 'crypto._toBuf is deprecated.', 'DEP00XX'),
createCipheriv,
createDecipheriv,
createDiffieHellman,
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

common.expectWarning({
DeprecationWarning: [
['crypto.createCipher is deprecated.', 'DEP0106'],
['crypto._toBuf is deprecated.', 'DEP00XX']
]
});

const assert = require('assert');
const crypto = require('crypto');
const tls = require('tls');
Expand Down Expand Up @@ -294,3 +301,8 @@ testEncoding({
testEncoding({
defaultEncoding: 'latin1'
}, assertionHashLatin1);

{
// Test that the exported _toBuf function is deprecated.
crypto._toBuf(Buffer.alloc(0));
}