v1.3 Fix of Google Authenticator migration support #9
@ -1,23 +1,23 @@
|
|||||||
export function decodeVarint(buffer, offset) {
|
export function decodeVarint(buffer, offset) {
|
||||||
let res = 0;
|
let res = 0;
|
||||||
let shift = 0;
|
let shift = 0;
|
||||||
let byte = 0;
|
let byte = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (offset >= buffer.length) {
|
if (offset >= buffer.length) {
|
||||||
throw new RangeError("Index out of bound decoding varint");
|
throw new RangeError("Index out of bound decoding varint");
|
||||||
}
|
}
|
||||||
|
|
||||||
byte = buffer[offset++];
|
byte = buffer[offset++];
|
||||||
|
|
||||||
const multiplier = 2 ** shift;
|
const multiplier = 2 ** shift;
|
||||||
const thisByteValue = (byte & 0x7f) * multiplier;
|
const thisByteValue = (byte & 0x7f) * multiplier;
|
||||||
shift += 7;
|
shift += 7;
|
||||||
res = res + thisByteValue;
|
res = res + thisByteValue;
|
||||||
} while (byte >= 0x80);
|
} while (byte >= 0x80);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: res,
|
value: res,
|
||||||
length: shift / 7
|
length: shift / 7
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user