diff options
author | cjihrig <cjihrig@gmail.com> | 2015-01-28 20:05:53 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2015-01-31 23:47:29 -0500 |
commit | 6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40 (patch) | |
tree | 29a3b1ce92cfad3ae5d41a4ba7451846beace950 /lib/crypto.js | |
parent | bce7a2608eb198eee6ecd7991062efd6daeeb440 (diff) | |
download | android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.tar.gz android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.tar.bz2 android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.zip |
lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).
Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/crypto.js')
-rw-r--r-- | lib/crypto.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/crypto.js b/lib/crypto.js index f8efffda48..42564c79e4 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -25,7 +25,7 @@ const DH_GENERATOR = 2; // to break them unnecessarily. function toBuf(str, encoding) { encoding = encoding || 'binary'; - if (util.isString(str)) { + if (typeof str === 'string') { if (encoding === 'buffer') encoding = 'binary'; str = new Buffer(str, encoding); @@ -92,7 +92,7 @@ Hash.prototype._flush = function(callback) { Hash.prototype.update = function(data, encoding) { encoding = encoding || exports.DEFAULT_ENCODING; - if (encoding === 'buffer' && util.isString(data)) + if (encoding === 'buffer' && typeof data === 'string') encoding = 'binary'; this._handle.update(data, encoding); return this; @@ -369,7 +369,7 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) { if (!(this instanceof DiffieHellman)) return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding); - if (!util.isBuffer(sizeOrKey) && + if (!(sizeOrKey instanceof Buffer) && typeof sizeOrKey !== 'number' && typeof sizeOrKey !== 'string') throw new TypeError('First argument should be number, string or Buffer'); @@ -513,7 +513,7 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) { function ECDH(curve) { - if (!util.isString(curve)) + if (typeof curve !== 'string') throw new TypeError('curve should be a string'); this._handle = new binding.ECDH(curve); @@ -566,12 +566,12 @@ exports.pbkdf2 = function(password, keylen, digest, callback) { - if (util.isFunction(digest)) { + if (typeof digest === 'function') { callback = digest; digest = undefined; } - if (!util.isFunction(callback)) + if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2'); return pbkdf2(password, salt, iterations, keylen, digest, callback); @@ -632,10 +632,10 @@ Certificate.prototype.exportChallenge = function(object, encoding) { exports.setEngine = function setEngine(id, flags) { - if (!util.isString(id)) + if (typeof id !== 'string') throw new TypeError('id should be a string'); - if (flags && !util.isNumber(flags)) + if (flags && typeof flags !== 'number') throw new TypeError('flags should be a number, if present'); flags = flags >>> 0; |