fix: Hopefully fix all tests being flaky
It seems that the varint encoding function would not work for some integers as input. This should in theory fix this issue. Since the SPK IDs are randomly between 0 and 2**32 - 1, it makes sense that the tests fail only sometimes.
This commit is contained in:
@@ -177,15 +177,17 @@ class OmemoSessionManager {
|
||||
// Pick the correct SPK
|
||||
final device = await getDevice();
|
||||
OmemoKeyPair? spk;
|
||||
if (kex.spkId == device.spkId) {
|
||||
spk = device.spk;
|
||||
} else if (kex.spkId == device.oldSpkId) {
|
||||
spk = device.oldSpk;
|
||||
} else {
|
||||
|
||||
await _lock.synchronized(() async {
|
||||
if (kex.spkId == _device.spkId) {
|
||||
spk = _device.spk;
|
||||
} else if (kex.spkId == _device.oldSpkId) {
|
||||
spk = _device.oldSpk;
|
||||
}
|
||||
});
|
||||
if (spk == null) {
|
||||
throw UnknownSignedPrekeyException();
|
||||
}
|
||||
|
||||
assert(spk != null, 'The used SPK must be found');
|
||||
|
||||
final kexResult = await x3dhFromInitialMessage(
|
||||
X3DHMessage(
|
||||
@@ -198,7 +200,7 @@ class OmemoSessionManager {
|
||||
device.ik,
|
||||
);
|
||||
final ratchet = await OmemoDoubleRatchet.acceptNewSession(
|
||||
spk,
|
||||
spk!,
|
||||
OmemoPublicKey.fromBytes(kex.ik!, KeyPairType.ed25519),
|
||||
kexResult.sk,
|
||||
kexResult.ad,
|
||||
|
||||
@@ -46,21 +46,18 @@ List<int> encodeVarint(int i) {
|
||||
assert(i >= 0, "Two's complement is not implemented");
|
||||
final ret = List<int>.empty(growable: true);
|
||||
|
||||
var j = 0;
|
||||
while (true) {
|
||||
// Thanks to https://github.com/hathibelagal-dev/LEB128 for the trick with toRadixString!
|
||||
final numSevenBlocks = (i.toRadixString(2).length / 7).ceil();
|
||||
for (var j = 0; j < numSevenBlocks; j++) {
|
||||
// The 7 LSB of the byte we're creating
|
||||
final x = (i & (lsb7Mask << j * 7)) >> j * 7;
|
||||
// The next bits
|
||||
final next = i & (lsb7Mask << (j + 1) * 7);
|
||||
|
||||
if (next == 0) {
|
||||
if (j == numSevenBlocks - 1) {
|
||||
// If we were to shift further, we only get zero, so we're at the end
|
||||
ret.add(x);
|
||||
break;
|
||||
} else {
|
||||
// We still have at least one bit more to go, so set the MSB to 1
|
||||
ret.add(x + msb);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user