Skip to content

Commit aaad106

Browse files
committed
Adding node 0.4 backward compat for id gen
1 parent f850ddc commit aaad106

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/manager.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,14 @@ Manager.prototype.generateId = function () {
709709
var rand = new Buffer(15); // multiple of 3 for base64
710710
this.sequenceNumber = (this.sequenceNumber + 1) | 0;
711711
rand.writeInt32BE(this.sequenceNumber, 11);
712-
crypto.randomBytes(12).copy(rand);
712+
if (crypto.randomBytes) {
713+
crypto.randomBytes(12).copy(rand);
714+
} else {
715+
// not secure for node 0.4
716+
[0, 4, 8].forEach(function(i) {
717+
rand.writeInt32BE(Math.random() * Math.pow(2, 32) | 0, i);
718+
});
719+
}
713720
return rand.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
714721
};
715722

0 commit comments

Comments
 (0)