Skip to content

Commit 0340dd8

Browse files
vsemozhetbytMylesBorins
authored andcommittedSep 25, 2018
doc: add and unify return statements in crypto.md
Conform return statements to the style guide and tool parsers. Also bring back a description fragment that seems to be erroneously deleted in 1e07acd Backport-PR-URL: #22870 PR-URL: #19853 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent b0d6067 commit 0340dd8

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed
 

‎doc/api/crypto.md

+63-45
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const cert2 = crypto.Certificate();
6868
added: v0.11.8
6969
-->
7070
- `spkac` {string | Buffer | TypedArray | DataView}
71-
- Returns {Buffer} The challenge component of the `spkac` data structure, which
72-
includes a public key and a challenge.
71+
- Returns: {Buffer} The challenge component of the `spkac` data structure, which
72+
includes a public key and a challenge.
7373

7474
```js
7575
const cert = require('crypto').Certificate();
@@ -84,8 +84,8 @@ console.log(challenge.toString('utf8'));
8484
added: v0.11.8
8585
-->
8686
- `spkac` {string | Buffer | TypedArray | DataView}
87-
- Returns {Buffer} The public key component of the `spkac` data structure,
88-
which includes a public key and a challenge.
87+
- Returns: {Buffer} The public key component of the `spkac` data structure,
88+
which includes a public key and a challenge.
8989

9090
```js
9191
const cert = require('crypto').Certificate();
@@ -100,8 +100,8 @@ console.log(publicKey);
100100
added: v0.11.8
101101
-->
102102
- `spkac` {Buffer | TypedArray | DataView}
103-
- Returns {boolean} `true` if the given `spkac` data structure is valid, `false`
104-
otherwise.
103+
- Returns: {boolean} `true` if the given `spkac` data structure is valid,
104+
`false` otherwise.
105105

106106
```js
107107
const cert = require('crypto').Certificate();
@@ -178,10 +178,10 @@ console.log(encrypted);
178178
added: v0.1.94
179179
-->
180180
- `outputEncoding` {string}
181-
182-
Returns any remaining enciphered contents. If `outputEncoding`
183-
parameter is one of `'latin1'`, `'base64'` or `'hex'`, a string is returned.
184-
If an `outputEncoding` is not provided, a [`Buffer`][] is returned.
181+
- Returns: {Buffer | string} Any remaining enciphered contents.
182+
If `outputEncoding` parameter is one of `'latin1'`, `'base64'` or `'hex'`,
183+
a string is returned. If an `outputEncoding` is not provided, a [`Buffer`][]
184+
is returned.
185185

186186
Once the `cipher.final()` method has been called, the `Cipher` object can no
187187
longer be used to encrypt data. Attempts to call `cipher.final()` more than
@@ -204,10 +204,10 @@ The `cipher.setAAD()` method must be called before [`cipher.update()`][].
204204
<!-- YAML
205205
added: v1.0.0
206206
-->
207-
208-
When using an authenticated encryption mode (only `GCM` is currently
209-
supported), the `cipher.getAuthTag()` method returns a [`Buffer`][] containing
210-
the _authentication tag_ that has been computed from the given data.
207+
- Returns: {Buffer} When using an authenticated encryption mode (only `GCM` is
208+
currently supported), the `cipher.getAuthTag()` method returns a [`Buffer`][]
209+
containing the _authentication tag_ that has been computed from the given
210+
data.
211211

212212
The `cipher.getAuthTag()` method should only be called after encryption has
213213
been completed using the [`cipher.final()`][] method.
@@ -217,7 +217,7 @@ been completed using the [`cipher.final()`][] method.
217217
added: v0.7.1
218218
-->
219219
- `autoPadding` {boolean} **Default:** `true`
220-
- Returns the {Cipher} for method chaining.
220+
- Returns: {Cipher} for method chaining.
221221

222222
When using block encryption algorithms, the `Cipher` class will automatically
223223
add padding to the input data to the appropriate block size. To disable the
@@ -242,6 +242,7 @@ changes:
242242
- `data` {string | Buffer | TypedArray | DataView}
243243
- `inputEncoding` {string}
244244
- `outputEncoding` {string}
245+
- Returns: {Buffer | string}
245246

246247
Updates the cipher with `data`. If the `inputEncoding` argument is given,
247248
its value must be one of `'utf8'`, `'ascii'`, or `'latin1'` and the `data`
@@ -331,10 +332,10 @@ console.log(decrypted);
331332
added: v0.1.94
332333
-->
333334
- `outputEncoding` {string}
334-
335-
Returns any remaining deciphered contents. If `outputEncoding`
336-
parameter is one of `'latin1'`, `'ascii'` or `'utf8'`, a string is returned.
337-
If an `outputEncoding` is not provided, a [`Buffer`][] is returned.
335+
- Returns: {Buffer | string} Any remaining deciphered contents.
336+
If `outputEncoding` parameter is one of `'latin1'`, `'ascii'` or `'utf8'`,
337+
a string is returned. If an `outputEncoding` is not provided, a [`Buffer`][]
338+
is returned.
338339

339340
Once the `decipher.final()` method has been called, the `Decipher` object can
340341
no longer be used to decrypt data. Attempts to call `decipher.final()` more
@@ -349,7 +350,7 @@ changes:
349350
description: This method now returns a reference to `decipher`.
350351
-->
351352
- `buffer` {Buffer | TypedArray | DataView}
352-
- Returns the {Cipher} for method chaining.
353+
- Returns: {Cipher} for method chaining.
353354

354355
When using an authenticated encryption mode (only `GCM` is currently
355356
supported), the `decipher.setAAD()` method sets the value used for the
@@ -366,7 +367,7 @@ changes:
366367
description: This method now returns a reference to `decipher`.
367368
-->
368369
- `buffer` {Buffer | TypedArray | DataView}
369-
- Returns the {Cipher} for method chaining.
370+
- Returns: {Cipher} for method chaining.
370371

371372
When using an authenticated encryption mode (only `GCM` is currently
372373
supported), the `decipher.setAuthTag()` method is used to pass in the
@@ -390,7 +391,7 @@ The `decipher.setAuthTag()` method must be called before
390391
added: v0.7.1
391392
-->
392393
- `autoPadding` {boolean} **Default:** `true`
393-
- Returns the {Cipher} for method chaining.
394+
- Returns: {Cipher} for method chaining.
394395

395396
When data has been encrypted without standard block padding, calling
396397
`decipher.setAutoPadding(false)` will disable automatic padding to prevent
@@ -413,6 +414,7 @@ changes:
413414
- `data` {string | Buffer | TypedArray | DataView}
414415
- `inputEncoding` {string}
415416
- `outputEncoding` {string}
417+
- Returns: {Buffer | string}
416418

417419
Updates the decipher with `data`. If the `inputEncoding` argument is given,
418420
its value must be one of `'latin1'`, `'base64'`, or `'hex'` and the `data`
@@ -467,6 +469,7 @@ added: v0.5.0
467469
- `otherPublicKey` {string | Buffer | TypedArray | DataView}
468470
- `inputEncoding` {string}
469471
- `outputEncoding` {string}
472+
- Returns: {Buffer | string}
470473

471474
Computes the shared secret using `otherPublicKey` as the other
472475
party's public key and returns the computed shared secret. The supplied
@@ -484,6 +487,7 @@ If `outputEncoding` is given a string is returned; otherwise, a
484487
added: v0.5.0
485488
-->
486489
- `encoding` {string}
490+
- Returns: {Buffer | string}
487491

488492
Generates private and public Diffie-Hellman key values, and returns
489493
the public key in the specified `encoding`. This key should be
@@ -496,6 +500,7 @@ or `'base64'`. If `encoding` is provided a string is returned; otherwise a
496500
added: v0.5.0
497501
-->
498502
- `encoding` {string}
503+
- Returns: {Buffer | string}
499504

500505
Returns the Diffie-Hellman generator in the specified `encoding`, which can
501506
be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a string is
@@ -506,6 +511,7 @@ returned; otherwise a [`Buffer`][] is returned.
506511
added: v0.5.0
507512
-->
508513
- `encoding` {string}
514+
- Returns: {Buffer | string}
509515

510516
Returns the Diffie-Hellman prime in the specified `encoding`, which can
511517
be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a string is
@@ -516,6 +522,7 @@ returned; otherwise a [`Buffer`][] is returned.
516522
added: v0.5.0
517523
-->
518524
- `encoding` {string}
525+
- Returns: {Buffer | string}
519526

520527
Returns the Diffie-Hellman private key in the specified `encoding`,
521528
which can be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a
@@ -526,6 +533,7 @@ string is returned; otherwise a [`Buffer`][] is returned.
526533
added: v0.5.0
527534
-->
528535
- `encoding` {string}
536+
- Returns: {Buffer | string}
529537

530538
Returns the Diffie-Hellman public key in the specified `encoding`, which
531539
can be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a
@@ -613,6 +621,7 @@ changes:
613621
- `otherPublicKey` {string | Buffer | TypedArray | DataView}
614622
- `inputEncoding` {string}
615623
- `outputEncoding` {string}
624+
- Returns: {Buffer | string}
616625

617626
Computes the shared secret using `otherPublicKey` as the other
618627
party's public key and returns the computed shared secret. The supplied
@@ -631,6 +640,7 @@ added: v0.11.14
631640
-->
632641
- `encoding` {string}
633642
- `format` {string} **Default:** `uncompressed`
643+
- Returns: {Buffer | string}
634644

635645
Generates private and public EC Diffie-Hellman key values, and returns
636646
the public key in the specified `format` and `encoding`. This key should be
@@ -649,20 +659,18 @@ is returned.
649659
added: v0.11.14
650660
-->
651661
- `encoding` {string}
652-
653-
Returns the EC Diffie-Hellman private key in the specified `encoding`,
654-
which can be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided
655-
a string is returned; otherwise a [`Buffer`][] is returned.
662+
- Returns: {Buffer | string} The EC Diffie-Hellman private key in the specified
663+
`encoding`, which can be `'latin1'`, `'hex'`, or `'base64'`. If `encoding`
664+
is provided a string is returned; otherwise a [`Buffer`][] is returned.
656665

657666
### ecdh.getPublicKey([encoding][, format])
658667
<!-- YAML
659668
added: v0.11.14
660669
-->
661670
- `encoding` {string}
662671
- `format` {string} **Default:** `uncompressed`
663-
664-
Returns the EC Diffie-Hellman public key in the specified `encoding` and
665-
`format`.
672+
- Returns: {Buffer | string} The EC Diffie-Hellman public key in the specified
673+
`encoding` and `format`.
666674

667675
The `format` argument specifies point encoding and can be `'compressed'` or
668676
`'uncompressed'`. If `format` is not specified the point will be returned in
@@ -798,6 +806,7 @@ console.log(hash.digest('hex'));
798806
added: v0.1.92
799807
-->
800808
- `encoding` {string}
809+
- Returns: {Buffer | string}
801810

802811
Calculates the digest of all of the data passed to be hashed (using the
803812
[`hash.update()`][] method). The `encoding` can be `'hex'`, `'latin1'` or
@@ -889,6 +898,7 @@ console.log(hmac.digest('hex'));
889898
added: v0.1.94
890899
-->
891900
- `encoding` {string}
901+
- Returns: {Buffer | string}
892902

893903
Calculates the HMAC digest of all of the data passed using [`hmac.update()`][].
894904
The `encoding` can be `'hex'`, `'latin1'` or `'base64'`. If `encoding` is
@@ -992,6 +1002,7 @@ changes:
9921002
- `key` {string}
9931003
- `passphrase` {string}
9941004
- `outputFormat` {string}
1005+
- Returns: {Buffer | string}
9951006

9961007
Calculates the signature on all the data passed through using either
9971008
[`sign.update()`][] or [`sign.write()`][stream-writable-write].
@@ -1115,6 +1126,8 @@ changes:
11151126
- `object` {string | Object}
11161127
- `signature` {string | Buffer | TypedArray | DataView}
11171128
- `signatureFormat` {string}
1129+
- Returns: {boolean} `true` or `false` depending on the validity of the
1130+
signature for the data and public key.
11181131

11191132
Verifies the provided data using the given `object` and `signature`.
11201133
The `object` argument can be either a string containing a PEM encoded object,
@@ -1140,9 +1153,6 @@ If a `signatureFormat` is specified, the `signature` is expected to be a
11401153
string; otherwise `signature` is expected to be a [`Buffer`][],
11411154
`TypedArray`, or `DataView`.
11421155

1143-
Returns `true` or `false` depending on the validity of the signature for
1144-
the data and public key.
1145-
11461156
The `verify` object can not be used again after `verify.verify()` has been
11471157
called. Multiple calls to `verify.verify()` will result in an error being
11481158
thrown.
@@ -1153,10 +1163,9 @@ thrown.
11531163
<!-- YAML
11541164
added: v6.3.0
11551165
-->
1156-
1157-
Returns an object containing commonly used constants for crypto and security
1158-
related operations. The specific constants currently defined are described in
1159-
[Crypto Constants][].
1166+
- Returns: {Object} An object containing commonly used constants for crypto and
1167+
security related operations. The specific constants currently defined are
1168+
described in [Crypto Constants][].
11601169

11611170
### crypto.DEFAULT_ENCODING
11621171
<!-- YAML
@@ -1188,6 +1197,7 @@ added: v0.1.94
11881197
- `algorithm` {string}
11891198
- `password` {string | Buffer | TypedArray | DataView}
11901199
- `options` {Object} [`stream.transform` options][]
1200+
- Returns: {Cipher}
11911201

11921202
Creates and returns a `Cipher` object that uses the given `algorithm` and
11931203
`password`. Optional `options` argument controls stream behavior.
@@ -1229,6 +1239,7 @@ changes:
12291239
- `key` {string | Buffer | TypedArray | DataView}
12301240
- `iv` {string | Buffer | TypedArray | DataView}
12311241
- `options` {Object} [`stream.transform` options][]
1242+
- Returns: {Cipher}
12321243

12331244
Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
12341245
initialization vector (`iv`). Optional `options` argument controls stream behavior.
@@ -1267,6 +1278,7 @@ added: v0.1.94
12671278
- `algorithm` {string}
12681279
- `password` {string | Buffer | TypedArray | DataView}
12691280
- `options` {Object} [`stream.transform` options][]
1281+
- Returns: {Decipher}
12701282

12711283
Creates and returns a `Decipher` object that uses the given `algorithm` and
12721284
`password` (key). Optional `options` argument controls stream behavior.
@@ -1296,6 +1308,7 @@ changes:
12961308
- `key` {string | Buffer | TypedArray | DataView}
12971309
- `iv` {string | Buffer | TypedArray | DataView}
12981310
- `options` {Object} [`stream.transform` options][]
1311+
- Returns: {Decipher}
12991312

13001313
Creates and returns a `Decipher` object that uses the given `algorithm`, `key`
13011314
and initialization vector (`iv`). Optional `options` argument controls stream
@@ -1376,6 +1389,7 @@ added: v0.1.92
13761389
-->
13771390
- `algorithm` {string}
13781391
- `options` {Object} [`stream.transform` options][]
1392+
- Returns: {Hash}
13791393

13801394
Creates and returns a `Hash` object that can be used to generate hash digests
13811395
using the given `algorithm`. Optional `options` argument controls stream
@@ -1413,6 +1427,7 @@ added: v0.1.94
14131427
- `algorithm` {string}
14141428
- `key` {string | Buffer | TypedArray | DataView}
14151429
- `options` {Object} [`stream.transform` options][]
1430+
- Returns: {Hmac}
14161431

14171432
Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
14181433
Optional `options` argument controls stream behavior.
@@ -1450,6 +1465,7 @@ added: v0.1.92
14501465
-->
14511466
- `algorithm` {string}
14521467
- `options` {Object} [`stream.Writable` options][]
1468+
- Returns: {Sign}
14531469

14541470
Creates and returns a `Sign` object that uses the given `algorithm`.
14551471
Use [`crypto.getHashes()`][] to obtain an array of names of the available
@@ -1462,6 +1478,7 @@ added: v0.1.92
14621478
-->
14631479
- `algorithm` {string}
14641480
- `options` {Object} [`stream.Writable` options][]
1481+
- Returns: {Verify}
14651482

14661483
Creates and returns a `Verify` object that uses the given algorithm.
14671484
Use [`crypto.getHashes()`][] to obtain an array of names of the available
@@ -1472,8 +1489,8 @@ signing algorithms. Optional `options` argument controls the
14721489
<!-- YAML
14731490
added: v0.9.3
14741491
-->
1475-
1476-
Returns an array with the names of the supported cipher algorithms.
1492+
- Returns: {string[]} An array with the names of the supported cipher
1493+
algorithms.
14771494

14781495
Example:
14791496

@@ -1486,8 +1503,7 @@ console.log(ciphers); // ['aes-128-cbc', 'aes-128-ccm', ...]
14861503
<!-- YAML
14871504
added: v2.3.0
14881505
-->
1489-
1490-
Returns an array with the names of the supported elliptic curves.
1506+
- Returns: {string[]} An array with the names of the supported elliptic curves.
14911507

14921508
Example:
14931509

@@ -1501,6 +1517,7 @@ console.log(curves); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
15011517
added: v0.7.5
15021518
-->
15031519
- `groupName` {string}
1520+
- Returns: {Object}
15041521

15051522
Creates a predefined `DiffieHellman` key exchange object. The
15061523
supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in
@@ -1534,9 +1551,8 @@ console.log(aliceSecret === bobSecret);
15341551
<!-- YAML
15351552
added: v0.9.3
15361553
-->
1537-
1538-
Returns an array of the names of the supported hash algorithms,
1539-
such as `RSA-SHA256`.
1554+
- Returns: {string[]} An array of the names of the supported hash algorithms,
1555+
such as `'RSA-SHA256'`.
15401556

15411557
Example:
15421558

@@ -1622,6 +1638,7 @@ changes:
16221638
- `iterations` {number}
16231639
- `keylen` {number}
16241640
- `digest` {string}
1641+
- Returns: {Buffer}
16251642

16261643
Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2)
16271644
implementation. A selected HMAC digest algorithm specified by `digest` is
@@ -1737,6 +1754,7 @@ added: v0.5.8
17371754
- `callback` {Function}
17381755
- `err` {Error}
17391756
- `buf` {Buffer}
1757+
- Returns: {Buffer} if the `callback` function is not provided.
17401758

17411759
Generates cryptographically strong pseudo-random data. The `size` argument
17421760
is a number indicating the number of bytes to generate.
@@ -1789,11 +1807,10 @@ added: v7.10.0
17891807
* `buffer` {Buffer|Uint8Array} Must be supplied.
17901808
* `offset` {number} **Default:** `0`
17911809
* `size` {number} **Default:** `buffer.length - offset`
1810+
* Returns: {Buffer}
17921811

17931812
Synchronous version of [`crypto.randomFill()`][].
17941813

1795-
Returns `buffer`
1796-
17971814
```js
17981815
const buf = Buffer.alloc(10);
17991816
console.log(crypto.randomFillSync(buf).toString('hex'));
@@ -1885,6 +1902,7 @@ added: v6.6.0
18851902
-->
18861903
- `a` {Buffer | TypedArray | DataView}
18871904
- `b` {Buffer | TypedArray | DataView}
1905+
- Returns: {boolean}
18881906

18891907
This function is based on a constant-time algorithm.
18901908
Returns true if `a` is equal to `b`, without leaking timing information that

‎tools/doc/type-parser.js

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const customTypesMap = {
4040

4141
'cluster.Worker': 'cluster.html#cluster_class_worker',
4242

43+
'Cipher': 'crypto.html#crypto_class_cipher',
44+
'Decipher': 'crypto.html#crypto_class_decipher',
45+
'Hash': 'crypto.html#crypto_class_hash',
46+
'Hmac': 'crypto.html#crypto_class_hmac',
47+
'Sign': 'crypto.html#crypto_class_sign',
48+
'Verify': 'crypto.html#crypto_class_verify',
4349
'crypto.constants': 'crypto.html#crypto_crypto_constants_1',
4450

4551
'dgram.Socket': 'dgram.html#dgram_class_dgram_socket',

0 commit comments

Comments
 (0)
Please sign in to comment.