mirror of
https://github.com/balena-io/open-balena.git
synced 2025-03-28 14:38:40 +00:00
make _keyid.js work with older node versions (4.x)
This commit is contained in:
parent
15485bfec7
commit
b7ed3f5c1d
@ -27,19 +27,19 @@ var base32 = (function() {
|
|||||||
|
|
||||||
return function(plain) {
|
return function(plain) {
|
||||||
if (!Buffer.isBuffer(plain)) {
|
if (!Buffer.isBuffer(plain)) {
|
||||||
plain = Buffer.alloc(plain);
|
plain = new Buffer(plain);
|
||||||
}
|
}
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var j = 0;
|
var j = 0;
|
||||||
var shiftIndex = 0;
|
var shiftIndex = 0;
|
||||||
var digit = 0;
|
var digit = 0;
|
||||||
var encoded = Buffer.alloc(quintetCount(plain) * 8);
|
var encoded = new Buffer(quintetCount(plain) * 8);
|
||||||
|
|
||||||
/* byte by byte isn't as pretty as quintet by quintet but tests a bit
|
/* byte by byte isn't as pretty as quintet by quintet but tests a bit
|
||||||
faster. will have to revisit. */
|
faster. will have to revisit. */
|
||||||
while(i < plain.length) {
|
while(i < plain.length) {
|
||||||
var current = plain[i];
|
var current = plain[i];
|
||||||
|
|
||||||
if(shiftIndex > 3) {
|
if(shiftIndex > 3) {
|
||||||
digit = current & (0xff >> shiftIndex);
|
digit = current & (0xff >> shiftIndex);
|
||||||
shiftIndex = (shiftIndex + 5) % 8;
|
shiftIndex = (shiftIndex + 5) % 8;
|
||||||
@ -48,10 +48,10 @@ var base32 = (function() {
|
|||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
digit = (current >> (8 - (shiftIndex + 5))) & 0x1f;
|
digit = (current >> (8 - (shiftIndex + 5))) & 0x1f;
|
||||||
shiftIndex = (shiftIndex + 5) % 8;
|
shiftIndex = (shiftIndex + 5) % 8;
|
||||||
if(shiftIndex == 0) i++;
|
if(shiftIndex == 0) i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded[j] = charTable.charCodeAt(digit);
|
encoded[j] = charTable.charCodeAt(digit);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user