summaryrefslogtreecommitdiff
path: root/lib/crypto.js
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-03-02 14:43:39 +0300
committerFedor Indutny <fedor@indutny.com>2016-03-02 21:25:04 +0300
commitb010c8716498dca398e61c388859fea92296feb3 (patch)
tree7939c49278bcb05bdc34134a4bf4d1824355978a /lib/crypto.js
parent0eda5f503a2fae915ae152bd221b523762a0ef97 (diff)
downloadnode-new-b010c8716498dca398e61c388859fea92296feb3.tar.gz
crypto, string_bytes: treat `buffer` str as `utf8`
Do not treat crypto inputs as `binary` strings, convert them to Buffers using `new Buffer(..., 'utf8')`, or using newly updated StringBytes APIs. PR-URL: https://github.com/nodejs/node/pull/5522 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/crypto.js')
-rw-r--r--lib/crypto.js9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/crypto.js b/lib/crypto.js
index cf92eff1ee..81eee114be 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -30,11 +30,10 @@ const DH_GENERATOR = 2;
// any explicit encoding in older versions of node, and we don't want
// to break them unnecessarily.
function toBuf(str, encoding) {
- encoding = encoding || 'binary';
if (typeof str === 'string') {
- if (encoding === 'buffer')
- encoding = 'binary';
- str = new Buffer(str, encoding);
+ if (encoding === 'buffer' || !encoding)
+ encoding = 'utf8';
+ return new Buffer(str, encoding);
}
return str;
}
@@ -67,8 +66,6 @@ Hash.prototype._flush = function(callback) {
Hash.prototype.update = function(data, encoding) {
encoding = encoding || exports.DEFAULT_ENCODING;
- if (encoding === 'buffer' && typeof data === 'string')
- encoding = 'binary';
this._handle.update(data, encoding);
return this;
};