2015-09-07 23:53:43 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-12-19 02:50:04 +01:00
|
|
|
*/
|
|
|
|
;(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var registeredFunctions = {};
|
|
|
|
var Type = {
|
|
|
|
SEND_MESSAGE: 1,
|
|
|
|
INIT_SESSION: 2,
|
|
|
|
};
|
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.replay = {
|
|
|
|
Type: Type,
|
|
|
|
registerFunction: function(func, functionCode) {
|
|
|
|
registeredFunctions[functionCode] = func;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function ReplayableError(options) {
|
|
|
|
options = options || {};
|
|
|
|
this.name = options.name || 'ReplayableError';
|
|
|
|
this.functionCode = options.functionCode;
|
|
|
|
this.args = options.args;
|
|
|
|
}
|
|
|
|
ReplayableError.prototype = new Error();
|
|
|
|
ReplayableError.prototype.constructor = ReplayableError;
|
|
|
|
|
|
|
|
ReplayableError.prototype.replay = function() {
|
2015-02-24 00:12:34 +01:00
|
|
|
return registeredFunctions[this.functionCode].apply(window, this.args);
|
2014-12-19 02:50:04 +01:00
|
|
|
};
|
|
|
|
|
2015-07-20 23:13:18 +02:00
|
|
|
function IncomingIdentityKeyError(number, message, key) {
|
2014-12-19 02:50:04 +01:00
|
|
|
ReplayableError.call(this, {
|
|
|
|
functionCode : Type.INIT_SESSION,
|
|
|
|
args : [number, message]
|
2015-02-24 00:12:34 +01:00
|
|
|
|
2014-12-19 02:50:04 +01:00
|
|
|
});
|
|
|
|
this.name = 'IncomingIdentityKeyError';
|
2015-05-08 02:43:30 +02:00
|
|
|
this.message = "The identity of the sender has changed. This may be malicious, or the sender may have simply reinstalled.";
|
2015-07-20 23:13:18 +02:00
|
|
|
this.identityKey = key;
|
2015-02-24 00:12:34 +01:00
|
|
|
this.number = number.split('.')[0];
|
2014-12-19 02:50:04 +01:00
|
|
|
}
|
|
|
|
IncomingIdentityKeyError.prototype = new ReplayableError();
|
|
|
|
IncomingIdentityKeyError.prototype.constructor = IncomingIdentityKeyError;
|
|
|
|
|
2015-07-21 01:13:17 +02:00
|
|
|
function OutgoingIdentityKeyError(number, message, timestamp, identityKey) {
|
2014-12-19 02:50:04 +01:00
|
|
|
ReplayableError.call(this, {
|
|
|
|
functionCode : Type.SEND_MESSAGE,
|
2015-02-24 00:12:34 +01:00
|
|
|
args : [number, message, timestamp]
|
2014-12-19 02:50:04 +01:00
|
|
|
});
|
|
|
|
this.name = 'OutgoingIdentityKeyError';
|
2015-05-08 02:43:30 +02:00
|
|
|
this.message = "The identity of the destination has changed. This may be malicious, or the destination may have simply reinstalled.";
|
2015-02-24 00:12:34 +01:00
|
|
|
this.number = number.split('.')[0];
|
2015-07-21 01:13:17 +02:00
|
|
|
this.identityKey = identityKey;
|
2014-12-19 02:50:04 +01:00
|
|
|
}
|
|
|
|
OutgoingIdentityKeyError.prototype = new ReplayableError();
|
|
|
|
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
|
|
|
|
|
|
|
|
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
|
|
|
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
|
|
|
window.textsecure.ReplayableError = ReplayableError;
|
|
|
|
|
|
|
|
})();
|