Skip to content

Commit da90664

Browse files
committed
lib: remove obsolete Cipher export
Cipher was removed from the public API a while ago but we were still defining it and exporting `require('crypto').Cipher` as `undefined`. Silly us. PR-URL: #57266 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent 559d481 commit da90664

File tree

5 files changed

+41
-71
lines changed

5 files changed

+41
-71
lines changed

doc/api/crypto.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ console.log(cert.verifySpkac(Buffer.from(spkac)));
303303
// Prints: true or false
304304
```
305305

306-
## Class: `Cipher`
306+
## Class: `Cipheriv`
307307

308308
<!-- YAML
309309
added: v0.1.94
310310
-->
311311

312312
* Extends: {stream.Transform}
313313

314-
Instances of the `Cipher` class are used to encrypt data. The class can be
314+
Instances of the `Cipheriv` class are used to encrypt data. The class can be
315315
used in one of two ways:
316316

317317
* As a [stream][] that is both readable and writable, where plain unencrypted
@@ -320,10 +320,10 @@ used in one of two ways:
320320
the encrypted data.
321321

322322
The [`crypto.createCipheriv()`][] method is
323-
used to create `Cipher` instances. `Cipher` objects are not to be created
323+
used to create `Cipheriv` instances. `Cipheriv` objects are not to be created
324324
directly using the `new` keyword.
325325

326-
Example: Using `Cipher` objects as streams:
326+
Example: Using `Cipheriv` objects as streams:
327327

328328
```mjs
329329
const {
@@ -391,7 +391,7 @@ scrypt(password, 'salt', 24, (err, key) => {
391391
});
392392
```
393393

394-
Example: Using `Cipher` and piped streams:
394+
Example: Using `Cipheriv` and piped streams:
395395

396396
```mjs
397397
import {
@@ -538,7 +538,7 @@ added: v0.1.94
538538
If `outputEncoding` is specified, a string is
539539
returned. If an `outputEncoding` is not provided, a [`Buffer`][] is returned.
540540

541-
Once the `cipher.final()` method has been called, the `Cipher` object can no
541+
Once the `cipher.final()` method has been called, the `Cipheriv` object can no
542542
longer be used to encrypt data. Attempts to call `cipher.final()` more than
543543
once will result in an error being thrown.
544544

@@ -570,7 +570,7 @@ added: v1.0.0
570570
* `options` {Object} [`stream.transform` options][]
571571
* `plaintextLength` {number}
572572
* `encoding` {string} The string encoding to use when `buffer` is a string.
573-
* Returns: {Cipher} The same `Cipher` instance for method chaining.
573+
* Returns: {Cipheriv} The same `Cipheriv` instance for method chaining.
574574

575575
When using an authenticated encryption mode (`GCM`, `CCM`, `OCB`, and
576576
`chacha20-poly1305` are
@@ -590,9 +590,9 @@ added: v0.7.1
590590
-->
591591

592592
* `autoPadding` {boolean} **Default:** `true`
593-
* Returns: {Cipher} The same `Cipher` instance for method chaining.
593+
* Returns: {Cipheriv} The same `Cipheriv` instance for method chaining.
594594

595-
When using block encryption algorithms, the `Cipher` class will automatically
595+
When using block encryption algorithms, the `Cipheriv` class will automatically
596596
add padding to the input data to the appropriate block size. To disable the
597597
default padding call `cipher.setAutoPadding(false)`.
598598

@@ -635,15 +635,15 @@ The `cipher.update()` method can be called multiple times with new data until
635635
[`cipher.final()`][] is called. Calling `cipher.update()` after
636636
[`cipher.final()`][] will result in an error being thrown.
637637

638-
## Class: `Decipher`
638+
## Class: `Decipheriv`
639639

640640
<!-- YAML
641641
added: v0.1.94
642642
-->
643643

644644
* Extends: {stream.Transform}
645645

646-
Instances of the `Decipher` class are used to decrypt data. The class can be
646+
Instances of the `Decipheriv` class are used to decrypt data. The class can be
647647
used in one of two ways:
648648

649649
* As a [stream][] that is both readable and writable, where plain encrypted
@@ -652,10 +652,10 @@ used in one of two ways:
652652
produce the unencrypted data.
653653

654654
The [`crypto.createDecipheriv()`][] method is
655-
used to create `Decipher` instances. `Decipher` objects are not to be created
655+
used to create `Decipheriv` instances. `Decipheriv` objects are not to be created
656656
directly using the `new` keyword.
657657

658-
Example: Using `Decipher` objects as streams:
658+
Example: Using `Decipheriv` objects as streams:
659659

660660
```mjs
661661
import { Buffer } from 'node:buffer';
@@ -731,7 +731,7 @@ decipher.write(encrypted, 'hex');
731731
decipher.end();
732732
```
733733

734-
Example: Using `Decipher` and piped streams:
734+
Example: Using `Decipheriv` and piped streams:
735735

736736
```mjs
737737
import {
@@ -848,7 +848,7 @@ added: v0.1.94
848848
If `outputEncoding` is specified, a string is
849849
returned. If an `outputEncoding` is not provided, a [`Buffer`][] is returned.
850850

851-
Once the `decipher.final()` method has been called, the `Decipher` object can
851+
Once the `decipher.final()` method has been called, the `Decipheriv` object can
852852
no longer be used to decrypt data. Attempts to call `decipher.final()` more
853853
than once will result in an error being thrown.
854854

@@ -870,7 +870,7 @@ changes:
870870
* `options` {Object} [`stream.transform` options][]
871871
* `plaintextLength` {number}
872872
* `encoding` {string} String encoding to use when `buffer` is a string.
873-
* Returns: {Decipher} The same Decipher for method chaining.
873+
* Returns: {Decipheriv} The same Decipher for method chaining.
874874

875875
When using an authenticated encryption mode (`GCM`, `CCM`, `OCB`, and
876876
`chacha20-poly1305` are
@@ -912,7 +912,7 @@ changes:
912912

913913
* `buffer` {string|Buffer|ArrayBuffer|TypedArray|DataView}
914914
* `encoding` {string} String encoding to use when `buffer` is a string.
915-
* Returns: {Decipher} The same Decipher for method chaining.
915+
* Returns: {Decipheriv} The same Decipher for method chaining.
916916

917917
When using an authenticated encryption mode (`GCM`, `CCM`, `OCB`, and
918918
`chacha20-poly1305` are
@@ -938,7 +938,7 @@ added: v0.7.1
938938
-->
939939

940940
* `autoPadding` {boolean} **Default:** `true`
941-
* Returns: {Decipher} The same Decipher for method chaining.
941+
* Returns: {Decipheriv} The same Decipher for method chaining.
942942

943943
When data has been encrypted without standard block padding, calling
944944
`decipher.setAutoPadding(false)` will disable automatic padding to prevent
@@ -3036,9 +3036,9 @@ changes:
30363036
* `key` {string|ArrayBuffer|Buffer|TypedArray|DataView|KeyObject|CryptoKey}
30373037
* `iv` {string|ArrayBuffer|Buffer|TypedArray|DataView|null}
30383038
* `options` {Object} [`stream.transform` options][]
3039-
* Returns: {Cipher}
3039+
* Returns: {Cipheriv}
30403040

3041-
Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
3041+
Creates and returns a `Cipheriv` object, with the given `algorithm`, `key` and
30423042
initialization vector (`iv`).
30433043

30443044
The `options` argument controls stream behavior and is optional except when a
@@ -3106,9 +3106,9 @@ changes:
31063106
* `key` {string|ArrayBuffer|Buffer|TypedArray|DataView|KeyObject|CryptoKey}
31073107
* `iv` {string|ArrayBuffer|Buffer|TypedArray|DataView|null}
31083108
* `options` {Object} [`stream.transform` options][]
3109-
* Returns: {Decipher}
3109+
* Returns: {Decipheriv}
31103110

3111-
Creates and returns a `Decipher` object that uses the given `algorithm`, `key`
3111+
Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key`
31123112
and initialization vector (`iv`).
31133113

31143114
The `options` argument controls stream behavior and is optional except when a

doc/api/deprecations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ initialization vectors.
22762276
It is recommended to derive a key using
22772277
[`crypto.pbkdf2()`][] or [`crypto.scrypt()`][] with random salts and to use
22782278
[`crypto.createCipheriv()`][] and [`crypto.createDecipheriv()`][] to obtain the
2279-
[`Cipher`][] and [`Decipher`][] objects respectively.
2279+
[`Cipheriv`][] and [`Decipheriv`][] objects respectively.
22802280

22812281
### DEP0107: `tls.convertNPNProtocols()`
22822282

@@ -3854,8 +3854,8 @@ deprecated, as their values are guaranteed to be identical to that of `process.f
38543854
[`Buffer.from(array)`]: buffer.md#static-method-bufferfromarray
38553855
[`Buffer.from(buffer)`]: buffer.md#static-method-bufferfrombuffer
38563856
[`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj
3857-
[`Cipher`]: crypto.md#class-cipher
3858-
[`Decipher`]: crypto.md#class-decipher
3857+
[`Cipheriv`]: crypto.md#class-cipheriv
3858+
[`Decipheriv`]: crypto.md#class-decipheriv
38593859
[`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand
38603860
[`ReadStream.open()`]: fs.md#class-fsreadstream
38613861
[`Server.getConnections()`]: net.md#servergetconnectionscallback

lib/crypto.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ const {
8888
diffieHellman,
8989
} = require('internal/crypto/diffiehellman');
9090
const {
91-
Cipher,
9291
Cipheriv,
93-
Decipher,
9492
Decipheriv,
9593
privateDecrypt,
9694
privateEncrypt,
@@ -224,9 +222,7 @@ module.exports = {
224222

225223
// Classes
226224
Certificate,
227-
Cipher,
228225
Cipheriv,
229-
Decipher,
230226
Decipheriv,
231227
DiffieHellman,
232228
DiffieHellmanGroup,

lib/internal/crypto/cipher.js

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,12 @@ function createCipherWithIV(cipher, key, options, decipher, iv) {
138138
// the Cipher class is defined using the legacy function syntax rather than
139139
// ES6 classes.
140140

141-
function Cipher(cipher, password, options) {
142-
if (!(this instanceof Cipher))
143-
return new Cipher(cipher, password, options);
144-
}
145-
146-
ObjectSetPrototypeOf(Cipher.prototype, LazyTransform.prototype);
147-
ObjectSetPrototypeOf(Cipher, LazyTransform);
148-
149-
Cipher.prototype._transform = function _transform(chunk, encoding, callback) {
141+
function _transform(chunk, encoding, callback) {
150142
this.push(this[kHandle].update(chunk, encoding));
151143
callback();
152144
};
153145

154-
Cipher.prototype._flush = function _flush(callback) {
146+
function _flush(callback) {
155147
try {
156148
this.push(this[kHandle].final());
157149
} catch (e) {
@@ -161,7 +153,7 @@ Cipher.prototype._flush = function _flush(callback) {
161153
callback();
162154
};
163155

164-
Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) {
156+
function update(data, inputEncoding, outputEncoding) {
165157
if (typeof data === 'string') {
166158
validateEncoding(data, inputEncoding);
167159
} else if (!isArrayBufferView(data)) {
@@ -179,8 +171,7 @@ Cipher.prototype.update = function update(data, inputEncoding, outputEncoding) {
179171
return ret;
180172
};
181173

182-
183-
Cipher.prototype.final = function final(outputEncoding) {
174+
function final(outputEncoding) {
184175
const ret = this[kHandle].final();
185176

186177
if (outputEncoding && outputEncoding !== 'buffer') {
@@ -191,29 +182,27 @@ Cipher.prototype.final = function final(outputEncoding) {
191182
return ret;
192183
};
193184

194-
195-
Cipher.prototype.setAutoPadding = function setAutoPadding(ap) {
185+
function setAutoPadding(ap) {
196186
if (!this[kHandle].setAutoPadding(!!ap))
197187
throw new ERR_CRYPTO_INVALID_STATE('setAutoPadding');
198188
return this;
199189
};
200190

201-
Cipher.prototype.getAuthTag = function getAuthTag() {
191+
function getAuthTag() {
202192
const ret = this[kHandle].getAuthTag();
203193
if (ret === undefined)
204194
throw new ERR_CRYPTO_INVALID_STATE('getAuthTag');
205195
return ret;
206196
};
207197

208-
209198
function setAuthTag(tagbuf, encoding) {
210199
tagbuf = getArrayBufferOrView(tagbuf, 'buffer', encoding);
211200
if (!this[kHandle].setAuthTag(tagbuf))
212201
throw new ERR_CRYPTO_INVALID_STATE('setAuthTag');
213202
return this;
214203
}
215204

216-
Cipher.prototype.setAAD = function setAAD(aadbuf, options) {
205+
function setAAD(aadbuf, options) {
217206
const encoding = getStringOption(options, 'encoding');
218207
const plaintextLength = getUIntOption(options, 'plaintextLength');
219208
aadbuf = getArrayBufferOrView(aadbuf, 'aadbuf', encoding);
@@ -235,42 +224,27 @@ function Cipheriv(cipher, key, iv, options) {
235224
}
236225

237226
function addCipherPrototypeFunctions(constructor) {
238-
constructor.prototype._transform = Cipher.prototype._transform;
239-
constructor.prototype._flush = Cipher.prototype._flush;
240-
constructor.prototype.update = Cipher.prototype.update;
241-
constructor.prototype.final = Cipher.prototype.final;
242-
constructor.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
227+
constructor.prototype._transform = _transform;
228+
constructor.prototype._flush = _flush;
229+
constructor.prototype.update = update;
230+
constructor.prototype.final = final;
231+
constructor.prototype.setAutoPadding = setAutoPadding;
243232
if (constructor === Cipheriv) {
244-
constructor.prototype.getAuthTag = Cipher.prototype.getAuthTag;
233+
constructor.prototype.getAuthTag = getAuthTag;
245234
} else {
246235
constructor.prototype.setAuthTag = setAuthTag;
247236
}
248-
constructor.prototype.setAAD = Cipher.prototype.setAAD;
237+
constructor.prototype.setAAD = setAAD;
249238
}
250239

251240
ObjectSetPrototypeOf(Cipheriv.prototype, LazyTransform.prototype);
252241
ObjectSetPrototypeOf(Cipheriv, LazyTransform);
253242
addCipherPrototypeFunctions(Cipheriv);
254243

255-
// The Decipher class is part of the legacy Node.js crypto API. It exposes
256-
// a stream-based encryption/decryption model. For backwards compatibility
257-
// the Decipher class is defined using the legacy function syntax rather than
258-
// ES6 classes.
259-
260-
function Decipher(cipher, password, options) {
261-
if (!(this instanceof Decipher))
262-
return new Decipher(cipher, password, options);
263-
}
264-
265-
ObjectSetPrototypeOf(Decipher.prototype, LazyTransform.prototype);
266-
ObjectSetPrototypeOf(Decipher, LazyTransform);
267-
addCipherPrototypeFunctions(Decipher);
268-
269244
// The Decipheriv class is part of the legacy Node.js crypto API. It exposes
270245
// a stream-based encryption/decryption model. For backwards compatibility
271246
// the Decipheriv class is defined using the legacy function syntax rather than
272247
// ES6 classes.
273-
274248
function Decipheriv(cipher, key, iv, options) {
275249
if (!(this instanceof Decipheriv))
276250
return new Decipheriv(cipher, key, iv, options);

tools/doc/type-parser.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const customTypesMap = {
7575

7676
'cluster.Worker': 'cluster.html#class-worker',
7777

78-
'Cipher': 'crypto.html#class-cipher',
79-
'Decipher': 'crypto.html#class-decipher',
78+
'Cipheriv': 'crypto.html#class-cipheriv',
79+
'Decipheriv': 'crypto.html#class-decipheriv',
8080
'DiffieHellman': 'crypto.html#class-diffiehellman',
8181
'DiffieHellmanGroup': 'crypto.html#class-diffiehellmangroup',
8282
'ECDH': 'crypto.html#class-ecdh',

0 commit comments

Comments
 (0)