feat: ported protobuf decoder
This commit is contained in:
parent
ba4b8cc29e
commit
fb6ece773c
@ -1,27 +0,0 @@
|
|||||||
import JSBI from "jsbi";
|
|
||||||
|
|
||||||
export function interpretAsSignedType(n) {
|
|
||||||
// see https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/wire_format_lite.h#L857-L876
|
|
||||||
// however, this is a simpler equivalent formula
|
|
||||||
const isEven = JSBI.equal(JSBI.bitwiseAnd(n, JSBI.BigInt(1)), JSBI.BigInt(0));
|
|
||||||
if (isEven) {
|
|
||||||
return JSBI.divide(n, JSBI.BigInt(2));
|
|
||||||
} else {
|
|
||||||
return JSBI.multiply(
|
|
||||||
JSBI.BigInt(-1),
|
|
||||||
JSBI.divide(JSBI.add(n, JSBI.BigInt(1)), JSBI.BigInt(2))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function interpretAsTwosComplement(n, bits) {
|
|
||||||
const isTwosComplement = JSBI.equal(
|
|
||||||
JSBI.signedRightShift(n, JSBI.BigInt(bits - 1)),
|
|
||||||
JSBI.BigInt(1)
|
|
||||||
);
|
|
||||||
if (isTwosComplement) {
|
|
||||||
return JSBI.subtract(n, JSBI.leftShift(JSBI.BigInt(1), JSBI.BigInt(bits)));
|
|
||||||
} else {
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
}
|
|
@ -72,7 +72,6 @@ export const TYPES = {
|
|||||||
export function decodeProto(buffer) {
|
export function decodeProto(buffer) {
|
||||||
const reader = new BufferReader(buffer);
|
const reader = new BufferReader(buffer);
|
||||||
const parts = [];
|
const parts = [];
|
||||||
|
|
||||||
reader.trySkipGrpcHeader();
|
reader.trySkipGrpcHeader();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -108,6 +107,7 @@ export function decodeProto(buffer) {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reader.resetToCheckpoint();
|
reader.resetToCheckpoint();
|
||||||
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"use bigint"
|
|
||||||
export function decodeVarint(buffer, offset) {
|
export function decodeVarint(buffer, offset) {
|
||||||
let res = BigInt(0);
|
let res = this.BigInt(0);
|
||||||
let shift = 0;
|
let shift = 0;
|
||||||
let byte = 0;
|
let byte = 0;
|
||||||
|
|
||||||
@ -10,11 +9,12 @@ export function decodeVarint(buffer, offset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte = buffer[offset++];
|
byte = buffer[offset++];
|
||||||
|
console.log(this)
|
||||||
|
|
||||||
const multiplier = exponentiate(BigInt(2), BigInt(shift));
|
const multiplier = this.BigInt(2) ** this.BigInt(shift);
|
||||||
const thisByteValue = multiply(BigInt(byte & 0x7f), multiplier);
|
const thisByteValue = this.BigInt(byte & 0x7f) * multiplier;
|
||||||
shift += 7;
|
shift += 7;
|
||||||
res = add(res, thisByteValue);
|
res = res + thisByteValue;
|
||||||
} while (byte >= 0x80);
|
} while (byte >= 0x80);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -5,7 +5,6 @@ let _props = null;
|
|||||||
AppSettingsPage({
|
AppSettingsPage({
|
||||||
build(props) {
|
build(props) {
|
||||||
_props = props;
|
_props = props;
|
||||||
|
|
||||||
const storage = JSON.parse(
|
const storage = JSON.parse(
|
||||||
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
props.settingsStorage.getItem("TOTPs") ?? "[]"
|
||||||
);
|
);
|
||||||
|
@ -62,11 +62,12 @@ function getByOtpauthScheme(link){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getByGoogleMigrationScheme(link){
|
function getByGoogleMigrationScheme(link){
|
||||||
console.log("Hello")
|
|
||||||
let data = link.split("data=")[1]; //Returns secret
|
let data = link.split("data=")[1]; //Returns base64 encoded data
|
||||||
data = decodeURIComponent(data);
|
data = decodeURIComponent(data);
|
||||||
console.log(data)
|
console.log(data)
|
||||||
let decode = base64decode(data);
|
let decode = base64decode(data);
|
||||||
console.log(decode)
|
console.log(decode)
|
||||||
console.log(decodeProto(decode));
|
let proto = decodeProto(decode);
|
||||||
|
console.log(proto);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user