Skip to content

Commit 688dca6

Browse files
committed
Merge pull request #735 from jas-/crypto-fix
crypto.createHash fix for node.js < 11
2 parents 0c44758 + fe4c2f5 commit 688dca6

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/protocol/Auth.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ var Buffer = require('buffer').Buffer;
22
var Crypto = require('crypto');
33
var Auth = exports;
44

5-
function sha1(msg) {
6-
var hash = Crypto.createHash('sha1');
7-
hash.update(msg);
8-
// hash.digest() does not output buffers yet
9-
return hash.digest('binary');
10-
};
5+
var sha1;
6+
if (Number(process.version.match(/^v\d+\.(\d+)/)[1]) >= 10){
7+
sha1 = function(msg) {
8+
var hash = Crypto.createHash('sha1');
9+
hash.setEncoding('binary');
10+
hash.write(msg);
11+
hash.end();
12+
return hash.read();
13+
}
14+
} else {
15+
sha1 = function(msg) {
16+
var hash = Crypto.createHash('sha1');
17+
hash.update(msg);
18+
// hash.digest() does not output buffers yet
19+
return hash.digest('binary');
20+
}
21+
}
1122
Auth.sha1 = sha1;
1223

1324
function xor(a, b) {

0 commit comments

Comments
 (0)