Skip to content
This repository was archived by the owner on Jun 5, 2020. It is now read-only.

Commit 2691d32

Browse files
committed
Update crypto module
Lots of refactoring to work around the fact that Closure Compiler doesn't have proper support for mixins. Ensure that @extends meets the requirement that X instanceof Y if X @extends Y. Add copies of the annotations for all mixin methods and aliased functions. Also add missing annotations for pbkdf2. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
1 parent 787ef3d commit 2691d32

File tree

1 file changed

+140
-55
lines changed

1 file changed

+140
-55
lines changed

crypto.js

Lines changed: 140 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ crypto.createHash = function(algorithm) {};
5757

5858
/**
5959
* @param {string} algorithm
60-
* @param {Object} options
60+
* @param {Object=} options
6161
* @constructor
6262
* @extends stream.Transform
6363
*/
@@ -85,7 +85,7 @@ crypto.createHmac = function(algorithm, key) {};
8585
/**
8686
* @param {string} hmac
8787
* @param {string|buffer.Buffer} key
88-
* @param {Object} options
88+
* @param {Object=} options
8989
* @constructor
9090
* @extends stream.Transform
9191
*/
@@ -112,14 +112,14 @@ crypto.createCipher = function(algorithm, password) {};
112112
* @param {string} algorithm
113113
* @param {string|buffer.Buffer} key
114114
* @param {string|buffer.Buffer} iv
115-
* @return {crypto.Cipher}
115+
* @return {crypto.Cipheriv}
116116
*/
117117
crypto.createCipheriv = function(algorithm, key, iv) {};
118118

119119
/**
120120
* @param {string|buffer.Buffer} cipher
121121
* @param {string} password
122-
* @param {Object} options
122+
* @param {Object=} options
123123
* @constructor
124124
* @extends stream.Transform
125125
*/
@@ -135,26 +135,48 @@ crypto.Cipher.prototype.update = function(data, input_encoding, output_encoding)
135135

136136
/**
137137
* @name crypto.Cipher.prototype.final
138-
* @function
139138
* @param {string} output_encoding
140139
* @return {string|buffer.Buffer}
141140
*/
142-
// crypto.Cipher.prototype.final = function(output_encoding) {};
141+
crypto.Cipher.prototype['final'] = function(output_encoding) {};
143142

144143
/**
145144
* @param {boolean=} auto_padding
146145
*/
147146
crypto.Cipher.prototype.setAutoPadding = function(auto_padding) {};
148147

149148
/**
150-
* @param {string|crypto.Cipheriv} cipher
149+
* Note: Cipheriv mixes update, final, and setAutoPadding from Cipher but
150+
* doesn't inherit directly from Cipher.
151+
*
152+
* @param {string} cipher
151153
* @param {string|buffer.Buffer} key
152154
* @param {string|buffer.Buffer} iv
153155
* @constructor
154-
* @extends crypto.Cipher
156+
* @extends stream.Transform
155157
*/
156158
crypto.Cipheriv = function(cipher, key, iv) {};
157159

160+
/**
161+
* @param {string|buffer.Buffer} data
162+
* @param {string=} input_encoding
163+
* @param {string=} output_encoding
164+
* @return {string|buffer.Buffer}
165+
*/
166+
crypto.Cipheriv.prototype.update = function(data, input_encoding, output_encoding) {};
167+
168+
/**
169+
* @name crypto.Cipheriv.prototype.final
170+
* @param {string} output_encoding
171+
* @return {string|buffer.Buffer}
172+
*/
173+
crypto.Cipheriv.prototype['final'] = function(output_encoding) {};
174+
175+
/**
176+
* @param {boolean=} auto_padding
177+
*/
178+
crypto.Cipheriv.prototype.setAutoPadding = function(auto_padding) {};
179+
158180
/**
159181
* @param {string} algorithm
160182
* @param {string|buffer.Buffer} password
@@ -166,14 +188,17 @@ crypto.createDecipher = function(algorithm, password) {};
166188
* @param {string} algorithm
167189
* @param {string|buffer.Buffer} key
168190
* @param {string|buffer.Buffer} iv
169-
* @return {crypto.Decipher}
191+
* @return {crypto.Decipheriv}
170192
*/
171193
crypto.createDecipheriv = function(algorithm, key, iv) {};
172194

173195
/**
174-
* @param {string|buffer.Buffer|crypto.Decipher} cipher
196+
* Note: Decipher mixes update, final, and setAutoPadding from Cipher but
197+
* doesn't inherit directly from Cipher.
198+
*
199+
* @param {string|buffer.Buffer} cipher
175200
* @param {string|buffer.Buffer} password
176-
* @param {Object} options
201+
* @param {Object=} options
177202
* @constructor
178203
* @extends stream.Transform
179204
*/
@@ -189,41 +214,70 @@ crypto.Decipher.prototype.update = function(data, input_encoding, output_encodin
189214

190215
/**
191216
* @name crypto.Decipher.prototype.final
192-
* @function
193217
* @param {string} output_encoding
194218
* @return {string|buffer.Buffer}
195219
*/
196-
// crypto.Decipher.prototype.final = function(output_encoding) {};
220+
crypto.Decipher.prototype['final'] = function(output_encoding) {};
221+
222+
/**
223+
* @param {string} output_encoding
224+
* @return {string|buffer.Buffer}
225+
*/
226+
crypto.Decipher.prototype.finaltol = function(output_encoding) {};
197227

198228
/**
199229
* @param {boolean=} auto_padding
200230
*/
201231
crypto.Decipher.prototype.setAutoPadding = function(auto_padding) {};
202232

203233
/**
234+
* Note: Decipheriv mixes update, final, and setAutoPadding from Cipher but
235+
* doesn't inherit directly from Cipher.
236+
*
204237
* @param {string|buffer.Buffer|crypto.Decipheriv} cipher
205238
* @param {string|buffer.Buffer} key
206239
* @param {string|buffer.Buffer} iv
207-
* @param {Object} options
240+
* @param {Object=} options
208241
* @constructor
209-
* @extends crypto.Cipher
242+
* @extends stream.Transform
210243
*/
211244
crypto.Decipheriv = function(cipher, key, iv, options) {};
212245

213246
/**
214-
* @type {crypto.Cipher.prototype.final}
247+
* @param {string|buffer.Buffer} data
248+
* @param {string=} input_encoding
249+
* @param {string=} output_encoding
250+
* @return {string|buffer.Buffer}
251+
*/
252+
crypto.Decipheriv.prototype.update = function(data, input_encoding, output_encoding) {};
253+
254+
/**
255+
* @name crypto.Decipheriv.prototype.final
256+
* @param {string} output_encoding
257+
* @return {string|buffer.Buffer}
258+
*/
259+
crypto.Decipheriv.prototype['final'] = function(output_encoding) {};
260+
261+
/**
262+
* @param {string} output_encoding
263+
* @return {string|buffer.Buffer}
215264
*/
216-
crypto.Decipheriv.prototype.finaltol;
265+
crypto.Decipheriv.prototype.finaltol = function(output_encoding) {};
266+
267+
/**
268+
* @param {boolean=} auto_padding
269+
*/
270+
crypto.Decipheriv.prototype.setAutoPadding = function(auto_padding) {};
217271

218272
/**
219273
* @param {string} algorithm
220-
* @return {crypto.Signer}
274+
* @return {crypto.Sign}
221275
*/
222276
crypto.createSign = function(algorithm) {};
223277

224278
/**
225279
* @param {string} algorithm
226-
* @param {Object} options
280+
* @param {Object=} options
227281
* @constructor
228282
* @extends stream.Writable
229283
*/
@@ -241,11 +295,6 @@ crypto.Sign.prototype.update = function(data) {};
241295
*/
242296
crypto.Sign.prototype.sign = function(private_key, output_format) {};
243297

244-
/**
245-
* @type {crypto.Sign}
246-
*/
247-
crypto.Signer; // Not sure about API docs / source diff
248-
249298
/**
250299
* @param {string} algorithm
251300
* @return crypto.Verify
@@ -254,17 +303,12 @@ crypto.createVerify = function(algorithm) {};
254303

255304
/**
256305
* @param {string} algorithm
257-
* @param {Object} options
306+
* @param {Object=} options
258307
* @constructor
259308
* @extends stream.Writable
260309
*/
261310
crypto.Verify = function(algorithm, options) {};
262311

263-
/**
264-
* @type {crypto.Sign._write}
265-
*/
266-
crypto.Verify.prototype._write;
267-
268312
/**
269313
* @param {string|buffer.Buffer} data
270314
*/
@@ -287,7 +331,7 @@ crypto.createDiffieHellman = function(prime, encoding) {};
287331

288332
/**
289333
* @param {number} sizeOrKey
290-
* @param {string} encoding
334+
* @param {string=} encoding
291335
* @constructor
292336
*/
293337
crypto.DiffieHellman = function(sizeOrKey, encoding) {};
@@ -345,70 +389,111 @@ crypto.DiffieHellman.prototype.setPublicKey = function(key, encoding) {};
345389
crypto.DiffieHellman.prototype.setPrivateKey = function(key, encoding) {};
346390

347391
/**
392+
* Note: DiffieHellmanGroup mixes DiffieHellman but doesn't inherit directly.
393+
*
348394
* @param {string} name
349395
* @constructor
350396
*/
351397
crypto.DiffieHellmanGroup = function(name) {};
352398

353399
/**
354-
* TODO: Not sure if this works.
400+
* @param {string=} encoding
401+
* @return {string|buffer.Buffer}
402+
*/
403+
crypto.DiffieHellmanGroup.prototype.generateKeys = function(encoding) {};
404+
405+
/**
406+
* @param {string|buffer.Buffer} key
407+
* @param {string=} inEnc
408+
* @param {string=} outEnc
409+
* @return {string|buffer.Buffer}
410+
*/
411+
crypto.DiffieHellmanGroup.prototype.computeSecret = function(key, inEnc, outEnc) {};
412+
413+
/**
414+
* @param {string=} encoding
415+
* @return {string|buffer.Buffer}
355416
*/
356-
crypto.DiffieHellmanGroup.prototype.generateKeys = crypto.DiffieHellman.prototype.generateKeys;
417+
crypto.DiffieHellmanGroup.prototype.getPrime = function(encoding) {};
357418

358419
/**
359-
* TODO: Not sure if this works.
420+
* @param {string=} encoding
421+
* @return {string|buffer.Buffer}
360422
*/
361-
crypto.DiffieHellmanGroup.prototype.computeSecret = crypto.DiffieHellman.prototype.computeSecret;
423+
crypto.DiffieHellmanGroup.prototype.getGenerator = function(encoding) {};
362424

363425
/**
364-
* @type {crypto.DiffieHellman.prototype.getPrime}
426+
* @param {string=} encoding
427+
* @return {string|buffer.Buffer}
365428
*/
366-
crypto.DiffieHellmanGroup.prototype.getPrime = crypto.DiffieHellman.prototype.getPrime;
429+
crypto.DiffieHellmanGroup.prototype.getPublicKey = function(encoding) {};
367430

368431
/**
369-
* @type {crypto.DiffieHellman.prototype.getGenerator}
432+
* @param {string} encoding
433+
* @return {string|buffer.Buffer}
434+
*/
435+
crypto.DiffieHellmanGroup.prototype.getPrivateKey = function(encoding) {}
436+
437+
/**
438+
* @param {string|buffer.Buffer} key
439+
* @param {string=} encoding
440+
* @return {crypto.DiffieHellmanGroup}
370441
*/
371-
crypto.DiffieHellmanGroup.prototype.getGenerator = crypto.DiffieHellman.prototype.getGenerator;
442+
crypto.DiffieHellmanGroup.prototype.setPublicKey = function(key, encoding) {};
372443

373444
/**
374-
* @type {crypto.DiffieHellman.prototype.getPublicKey}
445+
* @param {string|buffer.Buffer} key
446+
* @param {string=} encoding
447+
* @return {crypto.DiffieHellmanGroup}
375448
*/
376-
crypto.DiffieHellmanGroup.prototype.getPublicKey = crypto.DiffieHellman.prototype.getPublicKey;
449+
crypto.DiffieHellmanGroup.prototype.setPrivateKey = function(key, encoding) {};
377450

378451
/**
379-
* @type {crypto.DiffieHellman.prototype.getPrivateKey}
452+
* @param {string} group_name
453+
* @return {crypto.DiffieHellmanGroup}
380454
*/
381-
crypto.DiffieHellmanGroup.prototype.getPrivateKey = crypto.DiffieHellman.prototype.getPrivateKey;
455+
crypto.getDiffieHellman = function(group_name) {};
382456

383457
/**
384-
* @type {crypto.DiffieHellman.prototype.setPublicKey}
458+
* @param {string|buffer.Buffer} password
459+
* @param {string|buffer.Buffer} salt
460+
* @param {number} iterations
461+
* @param {number} keylen
462+
* @param {function(*, string)} callback
385463
*/
386-
crypto.DiffieHellmanGroup.prototype.setPublicKey = crypto.DiffieHellman.prototype.setPublicKey;
464+
crypto.pbkdf2 = function(password, salt, iterations, keylen, callback) {};
387465

388466
/**
389-
* @type {crypto.DiffieHellman.prototype.setPrivateKey}
467+
* @param {string|buffer.Buffer} password
468+
* @param {string|buffer.Buffer} salt
469+
* @param {number} iterations
470+
* @param {number} keylen
390471
*/
391-
crypto.DiffieHellmanGroup.prototype.setPrivateKey = crypto.DiffieHellman.prototype.setPrivateKey;
472+
crypto.pbkdf2Sync = function(password, salt, iterations, keylen) {};
392473

393474
/**
394-
* @type {*}
475+
* @param {number} size
476+
* @param {function(Error, buffer.Buffer)=} callback
395477
*/
396-
crypto.randomBytes;
478+
crypto.randomBytes = function(size, callback) {};
397479

398480
/**
399-
* @type {*}
481+
* @param {number} size
482+
* @param {function(Error, buffer.Buffer)=} callback
400483
*/
401-
crypto.pseudoRandomBytes;
484+
crypto.pseudoRandomBytes = function(size, callback) {};
402485

403486
/**
404-
* @type {crypto.randomBytes}
487+
* @param {number} size
488+
* @param {function(Error, buffer.Buffer)=} callback
405489
*/
406-
crypto.rng = crypto.randomBytes;
490+
crypto.rng = function(size, callback) {};
407491

408492
/**
409-
* @type {crypto.pseudoRandomBytes}
493+
* @param {number} size
494+
* @param {function(Error, buffer.Buffer)=} callback
410495
*/
411-
crypto.prng = crypto.pseudoRandomBytes;
496+
crypto.prng = function(size, callback) {};
412497

413498
/**
414499
* @return {Array.<string>}

0 commit comments

Comments
 (0)