Skip to content

Commit 1f9de29

Browse files
committed
Use new sha1 function with node.js > 0.10.5 only
This switches node.js 0.10 back to the old sha1 function due to some bugs in early node.js 0.10 versions. node.js >= 0.10.0 < 0.10.5 throw an error from `hash.setEncoding` node.js 0.10.5 does not honor `hash.setEncoding` for `hash.write` and the string is interpreted as utf8 and corrupted. fixes #746 fixes #752
1 parent 19a8a38 commit 1f9de29

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* fix authentication w/password failure for node.js 0.10.5
10+
* fix authentication w/password TypeError exception for node.js 0.10.0-0.10.4
911

1012
## v2.1.0 (2014-02-20)
1113

lib/protocol/Auth.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
var Buffer = require('buffer').Buffer;
22
var Crypto = require('crypto');
33
var Auth = exports;
4+
var semver = require('semver');
45

56
var sha1;
6-
if (Number(process.version.match(/^v\d+\.(\d+)/)[1]) >= 10){
7+
if (semver.gt(process.version, '0.10.5')){
8+
// support node.js > 0.10.5
9+
// new interface in node.js 0.10, but exclude < 0.10.5 due to core bugs
710
sha1 = function(msg) {
811
var hash = Crypto.createHash('sha1');
912
hash.setEncoding('binary');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"dependencies": {
1919
"require-all": "0.0.3",
2020
"bignumber.js": "1.0.1",
21-
"readable-stream": "~1.1.9"
21+
"readable-stream": "~1.1.9",
22+
"semver": "2.2.1"
2223
},
2324
"devDependencies": {
2425
"utest": "0.0.6",

0 commit comments

Comments
 (0)