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

Commit

Permalink
Update crypto module
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevinoid committed Apr 13, 2013
1 parent 787ef3d commit 2691d32
Showing 1 changed file with 140 additions and 55 deletions.
195 changes: 140 additions & 55 deletions crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ crypto.createHash = function(algorithm) {};

/**
* @param {string} algorithm
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Transform
*/
Expand Down Expand Up @@ -85,7 +85,7 @@ crypto.createHmac = function(algorithm, key) {};
/**
* @param {string} hmac
* @param {string|buffer.Buffer} key
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Transform
*/
Expand All @@ -112,14 +112,14 @@ crypto.createCipher = function(algorithm, password) {};
* @param {string} algorithm
* @param {string|buffer.Buffer} key
* @param {string|buffer.Buffer} iv
* @return {crypto.Cipher}
* @return {crypto.Cipheriv}
*/
crypto.createCipheriv = function(algorithm, key, iv) {};

/**
* @param {string|buffer.Buffer} cipher
* @param {string} password
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Transform
*/
Expand All @@ -135,26 +135,48 @@ crypto.Cipher.prototype.update = function(data, input_encoding, output_encoding)

/**
* @name crypto.Cipher.prototype.final
* @function
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
// crypto.Cipher.prototype.final = function(output_encoding) {};
crypto.Cipher.prototype['final'] = function(output_encoding) {};

/**
* @param {boolean=} auto_padding
*/
crypto.Cipher.prototype.setAutoPadding = function(auto_padding) {};

/**
* @param {string|crypto.Cipheriv} cipher
* Note: Cipheriv mixes update, final, and setAutoPadding from Cipher but
* doesn't inherit directly from Cipher.
*
* @param {string} cipher
* @param {string|buffer.Buffer} key
* @param {string|buffer.Buffer} iv
* @constructor
* @extends crypto.Cipher
* @extends stream.Transform
*/
crypto.Cipheriv = function(cipher, key, iv) {};

/**
* @param {string|buffer.Buffer} data
* @param {string=} input_encoding
* @param {string=} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Cipheriv.prototype.update = function(data, input_encoding, output_encoding) {};

/**
* @name crypto.Cipheriv.prototype.final
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Cipheriv.prototype['final'] = function(output_encoding) {};

/**
* @param {boolean=} auto_padding
*/
crypto.Cipheriv.prototype.setAutoPadding = function(auto_padding) {};

/**
* @param {string} algorithm
* @param {string|buffer.Buffer} password
Expand All @@ -166,14 +188,17 @@ crypto.createDecipher = function(algorithm, password) {};
* @param {string} algorithm
* @param {string|buffer.Buffer} key
* @param {string|buffer.Buffer} iv
* @return {crypto.Decipher}
* @return {crypto.Decipheriv}
*/
crypto.createDecipheriv = function(algorithm, key, iv) {};

/**
* @param {string|buffer.Buffer|crypto.Decipher} cipher
* Note: Decipher mixes update, final, and setAutoPadding from Cipher but
* doesn't inherit directly from Cipher.
*
* @param {string|buffer.Buffer} cipher
* @param {string|buffer.Buffer} password
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Transform
*/
Expand All @@ -189,41 +214,70 @@ crypto.Decipher.prototype.update = function(data, input_encoding, output_encodin

/**
* @name crypto.Decipher.prototype.final
* @function
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
// crypto.Decipher.prototype.final = function(output_encoding) {};
crypto.Decipher.prototype['final'] = function(output_encoding) {};

/**
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Decipher.prototype.finaltol = function(output_encoding) {};

/**
* @param {boolean=} auto_padding
*/
crypto.Decipher.prototype.setAutoPadding = function(auto_padding) {};

/**
* Note: Decipheriv mixes update, final, and setAutoPadding from Cipher but
* doesn't inherit directly from Cipher.
*
* @param {string|buffer.Buffer|crypto.Decipheriv} cipher
* @param {string|buffer.Buffer} key
* @param {string|buffer.Buffer} iv
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends crypto.Cipher
* @extends stream.Transform
*/
crypto.Decipheriv = function(cipher, key, iv, options) {};

/**
* @type {crypto.Cipher.prototype.final}
* @param {string|buffer.Buffer} data
* @param {string=} input_encoding
* @param {string=} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Decipheriv.prototype.update = function(data, input_encoding, output_encoding) {};

/**
* @name crypto.Decipheriv.prototype.final
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Decipheriv.prototype['final'] = function(output_encoding) {};

/**
* @param {string} output_encoding
* @return {string|buffer.Buffer}
*/
crypto.Decipheriv.prototype.finaltol;
crypto.Decipheriv.prototype.finaltol = function(output_encoding) {};

/**
* @param {boolean=} auto_padding
*/
crypto.Decipheriv.prototype.setAutoPadding = function(auto_padding) {};

/**
* @param {string} algorithm
* @return {crypto.Signer}
* @return {crypto.Sign}
*/
crypto.createSign = function(algorithm) {};

/**
* @param {string} algorithm
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Writable
*/
Expand All @@ -241,11 +295,6 @@ crypto.Sign.prototype.update = function(data) {};
*/
crypto.Sign.prototype.sign = function(private_key, output_format) {};

/**
* @type {crypto.Sign}
*/
crypto.Signer; // Not sure about API docs / source diff

/**
* @param {string} algorithm
* @return crypto.Verify
Expand All @@ -254,17 +303,12 @@ crypto.createVerify = function(algorithm) {};

/**
* @param {string} algorithm
* @param {Object} options
* @param {Object=} options
* @constructor
* @extends stream.Writable
*/
crypto.Verify = function(algorithm, options) {};

/**
* @type {crypto.Sign._write}
*/
crypto.Verify.prototype._write;

/**
* @param {string|buffer.Buffer} data
*/
Expand All @@ -287,7 +331,7 @@ crypto.createDiffieHellman = function(prime, encoding) {};

/**
* @param {number} sizeOrKey
* @param {string} encoding
* @param {string=} encoding
* @constructor
*/
crypto.DiffieHellman = function(sizeOrKey, encoding) {};
Expand Down Expand Up @@ -345,70 +389,111 @@ crypto.DiffieHellman.prototype.setPublicKey = function(key, encoding) {};
crypto.DiffieHellman.prototype.setPrivateKey = function(key, encoding) {};

/**
* Note: DiffieHellmanGroup mixes DiffieHellman but doesn't inherit directly.
*
* @param {string} name
* @constructor
*/
crypto.DiffieHellmanGroup = function(name) {};

/**
* TODO: Not sure if this works.
* @param {string=} encoding
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.generateKeys = function(encoding) {};

/**
* @param {string|buffer.Buffer} key
* @param {string=} inEnc
* @param {string=} outEnc
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.computeSecret = function(key, inEnc, outEnc) {};

/**
* @param {string=} encoding
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.generateKeys = crypto.DiffieHellman.prototype.generateKeys;
crypto.DiffieHellmanGroup.prototype.getPrime = function(encoding) {};

/**
* TODO: Not sure if this works.
* @param {string=} encoding
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.computeSecret = crypto.DiffieHellman.prototype.computeSecret;
crypto.DiffieHellmanGroup.prototype.getGenerator = function(encoding) {};

/**
* @type {crypto.DiffieHellman.prototype.getPrime}
* @param {string=} encoding
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.getPrime = crypto.DiffieHellman.prototype.getPrime;
crypto.DiffieHellmanGroup.prototype.getPublicKey = function(encoding) {};

/**
* @type {crypto.DiffieHellman.prototype.getGenerator}
* @param {string} encoding
* @return {string|buffer.Buffer}
*/
crypto.DiffieHellmanGroup.prototype.getPrivateKey = function(encoding) {}

/**
* @param {string|buffer.Buffer} key
* @param {string=} encoding
* @return {crypto.DiffieHellmanGroup}
*/
crypto.DiffieHellmanGroup.prototype.getGenerator = crypto.DiffieHellman.prototype.getGenerator;
crypto.DiffieHellmanGroup.prototype.setPublicKey = function(key, encoding) {};

/**
* @type {crypto.DiffieHellman.prototype.getPublicKey}
* @param {string|buffer.Buffer} key
* @param {string=} encoding
* @return {crypto.DiffieHellmanGroup}
*/
crypto.DiffieHellmanGroup.prototype.getPublicKey = crypto.DiffieHellman.prototype.getPublicKey;
crypto.DiffieHellmanGroup.prototype.setPrivateKey = function(key, encoding) {};

/**
* @type {crypto.DiffieHellman.prototype.getPrivateKey}
* @param {string} group_name
* @return {crypto.DiffieHellmanGroup}
*/
crypto.DiffieHellmanGroup.prototype.getPrivateKey = crypto.DiffieHellman.prototype.getPrivateKey;
crypto.getDiffieHellman = function(group_name) {};

/**
* @type {crypto.DiffieHellman.prototype.setPublicKey}
* @param {string|buffer.Buffer} password
* @param {string|buffer.Buffer} salt
* @param {number} iterations
* @param {number} keylen
* @param {function(*, string)} callback
*/
crypto.DiffieHellmanGroup.prototype.setPublicKey = crypto.DiffieHellman.prototype.setPublicKey;
crypto.pbkdf2 = function(password, salt, iterations, keylen, callback) {};

/**
* @type {crypto.DiffieHellman.prototype.setPrivateKey}
* @param {string|buffer.Buffer} password
* @param {string|buffer.Buffer} salt
* @param {number} iterations
* @param {number} keylen
*/
crypto.DiffieHellmanGroup.prototype.setPrivateKey = crypto.DiffieHellman.prototype.setPrivateKey;
crypto.pbkdf2Sync = function(password, salt, iterations, keylen) {};

/**
* @type {*}
* @param {number} size
* @param {function(Error, buffer.Buffer)=} callback
*/
crypto.randomBytes;
crypto.randomBytes = function(size, callback) {};

/**
* @type {*}
* @param {number} size
* @param {function(Error, buffer.Buffer)=} callback
*/
crypto.pseudoRandomBytes;
crypto.pseudoRandomBytes = function(size, callback) {};

/**
* @type {crypto.randomBytes}
* @param {number} size
* @param {function(Error, buffer.Buffer)=} callback
*/
crypto.rng = crypto.randomBytes;
crypto.rng = function(size, callback) {};

/**
* @type {crypto.pseudoRandomBytes}
* @param {number} size
* @param {function(Error, buffer.Buffer)=} callback
*/
crypto.prng = crypto.pseudoRandomBytes;
crypto.prng = function(size, callback) {};

/**
* @return {Array.<string>}
Expand Down

0 comments on commit 2691d32

Please sign in to comment.