Remove libaxolotl dependency on textsecure/errors.js
Let libaxolotl throw a generic error instead of a replayable error, and add an helper function in libtextsecure's axolotl_wrapper to catch and convert from the generic error to the replayable one. This allows the ReplayableError to remain a libtextsecure-level concept only. Somewhat unrelatedly, but nearby, fix some whitespace and add missing semicolon.
This commit is contained in:
parent
676ad04958
commit
b790f82849
4 changed files with 35 additions and 12 deletions
|
@ -140,11 +140,24 @@
|
||||||
|
|
||||||
if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION &&
|
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION &&
|
||||||
finalMessage.sync !== null)
|
finalMessage.sync !== null)
|
||||||
res[1]();
|
res[1]();
|
||||||
|
|
||||||
return finalMessage;
|
return finalMessage;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
var handlePreKeyWhisperMessage = function(from, message) {
|
||||||
|
try {
|
||||||
|
return axolotl.protocol.handlePreKeyWhisperMessage(from, message);
|
||||||
|
} catch(e) {
|
||||||
|
if (e.message === 'Unknown identity key') {
|
||||||
|
// create an error that the UI will pick up and ask the
|
||||||
|
// user if they want to re-negotiate
|
||||||
|
throw new textsecure.IncomingIdentityKeyError(from, message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.protocol_wrapper = {
|
window.textsecure.protocol_wrapper = {
|
||||||
|
@ -159,7 +172,7 @@
|
||||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
|
return handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
default:
|
default:
|
||||||
|
@ -37187,8 +37200,7 @@ window.axolotl.protocol = function() {
|
||||||
if (open_session !== undefined)
|
if (open_session !== undefined)
|
||||||
closeSession(open_session); // To be returned and saved later
|
closeSession(open_session); // To be returned and saved later
|
||||||
} else {
|
} else {
|
||||||
// ...otherwise create an error that the UI will pick up and ask the user if they want to re-negotiate
|
throw new Error('Unknown identity key');
|
||||||
throw new textsecure.IncomingIdentityKeyError(encodedNumber, getString(message.encode()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
||||||
|
|
|
@ -386,8 +386,7 @@ window.axolotl.protocol = function() {
|
||||||
if (open_session !== undefined)
|
if (open_session !== undefined)
|
||||||
closeSession(open_session); // To be returned and saved later
|
closeSession(open_session); // To be returned and saved later
|
||||||
} else {
|
} else {
|
||||||
// ...otherwise create an error that the UI will pick up and ask the user if they want to re-negotiate
|
throw new Error('Unknown identity key');
|
||||||
throw new textsecure.IncomingIdentityKeyError(encodedNumber, getString(message.encode()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
||||||
|
|
|
@ -63,11 +63,24 @@
|
||||||
|
|
||||||
if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
if ((finalMessage.flags & textsecure.protobuf.PushMessageContent.Flags.END_SESSION)
|
||||||
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION &&
|
== textsecure.protobuf.PushMessageContent.Flags.END_SESSION &&
|
||||||
finalMessage.sync !== null)
|
finalMessage.sync !== null)
|
||||||
res[1]();
|
res[1]();
|
||||||
|
|
||||||
return finalMessage;
|
return finalMessage;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
var handlePreKeyWhisperMessage = function(from, message) {
|
||||||
|
try {
|
||||||
|
return axolotl.protocol.handlePreKeyWhisperMessage(from, message);
|
||||||
|
} catch(e) {
|
||||||
|
if (e.message === 'Unknown identity key') {
|
||||||
|
// create an error that the UI will pick up and ask the
|
||||||
|
// user if they want to re-negotiate
|
||||||
|
throw new textsecure.IncomingIdentityKeyError(from, message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.protocol_wrapper = {
|
window.textsecure.protocol_wrapper = {
|
||||||
|
@ -82,7 +95,7 @@
|
||||||
if (proto.message.readUint8() != ((3 << 4) | 3))
|
if (proto.message.readUint8() != ((3 << 4) | 3))
|
||||||
throw new Error("Bad version byte");
|
throw new Error("Bad version byte");
|
||||||
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
var from = proto.source + "." + (proto.sourceDevice == null ? 0 : proto.sourceDevice);
|
||||||
return axolotl.protocol.handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
|
return handlePreKeyWhisperMessage(from, getString(proto.message)).then(decodeMessageContents);
|
||||||
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
case textsecure.protobuf.IncomingPushMessageSignal.Type.RECEIPT:
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -37001,8 +37001,7 @@ window.axolotl.protocol = function() {
|
||||||
if (open_session !== undefined)
|
if (open_session !== undefined)
|
||||||
closeSession(open_session); // To be returned and saved later
|
closeSession(open_session); // To be returned and saved later
|
||||||
} else {
|
} else {
|
||||||
// ...otherwise create an error that the UI will pick up and ask the user if they want to re-negotiate
|
throw new Error('Unknown identity key');
|
||||||
throw new textsecure.IncomingIdentityKeyError(encodedNumber, getString(message.encode()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
return initSession(false, preKeyPair, signedPreKeyPair, encodedNumber, toArrayBuffer(message.identityKey), toArrayBuffer(message.baseKey), undefined)
|
||||||
|
|
Loading…
Reference in a new issue