Re-run concat

pull/749/head
Matt Corallo 10 years ago committed by lilia
parent 1e318a8293
commit 44a094c324

@ -96,12 +96,34 @@
return textsecure.storage.removeEncrypted(key); return textsecure.storage.removeEncrypted(key);
}, },
identityKeys: {
get: function(identifier) {
return textsecure.storage.devices.getIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0]);
},
put: function(identifier, identityKey) {
return textsecure.storage.devices.checkSaveIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0], identityKey);
},
},
sessions: { sessions: {
get: function(identifier) { get: function(identifier) {
return textsecure.storage.devices.getDeviceObject(identifier); var device = textsecure.storage.devices.getDeviceObject(identifier, true);
if (device === undefined || device.sessions === undefined)
return undefined;
return device.sessions;
}, },
put: function(object) { put: function(identifier, record) {
return textsecure.storage.devices.saveDeviceObject(object); var device = textsecure.storage.devices.getDeviceObject(identifier);
if (device === undefined) {
device = { encodedNumber: identifier,
//TODO: Remove this duplication
identityKey: record.identityKey
};
}
if (getString(device.identityKey) !== getString(record.identityKey))
throw new Error("Tried to put session for device with changed identity key");
device.sessions = record;
return textsecure.storage.devices.saveDeviceObject(device);
} }
} }
}, },
@ -23827,25 +23849,22 @@ window.axolotl.protocol = function() {
} }
crypto_storage.saveSession = function(encodedNumber, session, registrationId) { crypto_storage.saveSession = function(encodedNumber, session, registrationId) {
var device = axolotl.api.storage.sessions.get(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
if (device === undefined) if (record === undefined) {
device = { sessions: {}, encodedNumber: encodedNumber }; if (registrationId === undefined)
throw new Error("Tried to save a session for an existing device that didn't exist");
if (registrationId !== undefined) else
device.registrationId = registrationId; record = new axolotl.sessions.RecipientRecord(session.indexInfo.remoteIdentityKey, registrationId);
}
crypto_storage.saveSessionAndDevice(device, session); var sessions = record._sessions;
}
crypto_storage.saveSessionAndDevice = function(device, session) { if (record.identityKey === null)
if (device.sessions === undefined) record.identityKey = session.indexInfo.remoteIdentityKey;
device.sessions = {}; if (getString(record.identityKey) !== getString(session.indexInfo.remoteIdentityKey))
var sessions = device.sessions; throw new Error("Identity key changed at session save time");
var doDeleteSession = false; var doDeleteSession = false;
if (session.indexInfo.closed == -1 || device.identityKey === undefined)
device.identityKey = session.indexInfo.remoteIdentityKey;
if (session.indexInfo.closed != -1) { if (session.indexInfo.closed != -1) {
doDeleteSession = (session.indexInfo.closed < (new Date().getTime() - MESSAGE_LOST_THRESHOLD_MS)); doDeleteSession = (session.indexInfo.closed < (new Date().getTime() - MESSAGE_LOST_THRESHOLD_MS));
@ -23872,19 +23891,27 @@ window.axolotl.protocol = function() {
for (var key in sessions) for (var key in sessions)
if (sessions[key].indexInfo.closed == -1) if (sessions[key].indexInfo.closed == -1)
openSessionRemaining = true; openSessionRemaining = true;
if (!openSessionRemaining) if (!openSessionRemaining) // Used as a flag to get new pre keys for the next session
try { record.registrationId = null;
delete device['registrationId']; else if (record.registrationId === null && registrationId !== undefined)
} catch(_) {} record.registrationId = registrationId;
else if (record.registrationId === null)
axolotl.api.storage.sessions.put(device); throw new Error("Had open sessions on a record that had no registrationId set");
var identityKey = axolotl.api.storage.identityKeys.get(encodedNumber);
if (identityKey === undefined)
axolotl.api.storage.identityKeys.put(encodedNumber, record.identityKey);
else if (getString(identityKey) !== getString(record.identityKey))
throw new Error("Tried to change identity key at save time");
axolotl.api.storage.sessions.put(encodedNumber, record);
} }
var getSessions = function(encodedNumber) { var getSessions = function(encodedNumber) {
var device = axolotl.api.storage.sessions.get(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
if (device === undefined || device.sessions === undefined) if (record === undefined)
return undefined; return undefined;
return device.sessions; return record._sessions;
} }
crypto_storage.getOpenSession = function(encodedNumber) { crypto_storage.getOpenSession = function(encodedNumber) {
@ -23922,17 +23949,21 @@ window.axolotl.protocol = function() {
} }
crypto_storage.getSessionOrIdentityKeyByBaseKey = function(encodedNumber, baseKey) { crypto_storage.getSessionOrIdentityKeyByBaseKey = function(encodedNumber, baseKey) {
var sessions = getSessions(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
var device = axolotl.api.storage.sessions.get(encodedNumber); if (record === undefined) {
if (device === undefined) var identityKey = axolotl.api.storage.identityKeys.get(encodedNumber);
return undefined; if (identityKey === undefined)
return undefined;
return { indexInfo: { remoteIdentityKey: identityKey } };
}
var sessions = record._sessions;
var preferredSession = device.sessions && device.sessions[getString(baseKey)]; var preferredSession = record._sessions[getString(baseKey)];
if (preferredSession !== undefined) if (preferredSession !== undefined)
return preferredSession; return preferredSession;
if (device.identityKey !== undefined) if (record.identityKey !== undefined)
return { indexInfo: { remoteIdentityKey: device.identityKey } }; return { indexInfo: { remoteIdentityKey: record.identityKey } };
throw new Error("Datastore inconsistency: device was stored without identity key"); throw new Error("Datastore inconsistency: device was stored without identity key");
} }
@ -24298,6 +24329,7 @@ window.axolotl.protocol = function() {
// return Promise(encoded [PreKey]WhisperMessage) // return Promise(encoded [PreKey]WhisperMessage)
self.encryptMessageFor = function(deviceObject, pushMessageContent) { self.encryptMessageFor = function(deviceObject, pushMessageContent) {
var session = crypto_storage.getOpenSession(deviceObject.encodedNumber); var session = crypto_storage.getOpenSession(deviceObject.encodedNumber);
var hadSession = session !== undefined;
var doEncryptPushMessageContent = function() { var doEncryptPushMessageContent = function() {
var msg = new axolotl.protobuf.WhisperMessage(); var msg = new axolotl.protobuf.WhisperMessage();
@ -24332,17 +24364,9 @@ window.axolotl.protocol = function() {
result.set(new Uint8Array(encodedMsg), 1); result.set(new Uint8Array(encodedMsg), 1);
result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1); result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1);
try {
delete deviceObject['signedKey'];
delete deviceObject['signedKeyId'];
delete deviceObject['signedKeySignature'];
delete deviceObject['preKey'];
delete deviceObject['preKeyId'];
} catch(_) {}
removeOldChains(session); removeOldChains(session);
crypto_storage.saveSessionAndDevice(deviceObject, session); crypto_storage.saveSession(deviceObject.encodedNumber, session, !hadSession ? deviceObject.registrationId : undefined);
return result; return result;
}); });
}); });
@ -24517,6 +24541,60 @@ window.axolotl.protocol = function() {
}; };
})(); })();
/* vim: ts=4:sw=4
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
;(function() {
'use strict';
window.axolotl = window.axolotl || {};
var RecipientRecord = function(identityKey, registrationId) {
this._sessions = {};
this.identityKey = identityKey !== undefined ? getString(identityKey) : null;
this.registrationId = registrationId;
if (this.registrationId === undefined || typeof this.registrationId !== "number")
this.registrationId = null;
};
RecipientRecord.prototype.serialize = function() {
return textsecure.utils.jsonThing({sessions: this._sessions, registrationId: this.registrationId, identityKey: this.identityKey});
}
RecipientRecord.prototype.deserialize = function(serialized) {
var data = JSON.parse(serialized);
this._sessions = data.sessions;
if (this._sessions === undefined || this._sessions === null || typeof this._sessions !== "object" || Array.isArray(this._sessions))
throw new Error("Error deserializing RecipientRecord");
this.identityKey = data.identityKey;
this.registrationId = data.registrationId;
if (this.identityKey === undefined || this.registrationId === undefined)
throw new Error("Error deserializing RecipientRecord");
}
RecipientRecord.prototype.haveOpenSession = function() {
return this.registrationId !== null;
}
window.axolotl.sessions = {
RecipientRecord: RecipientRecord,
};
})();
/* vim: ts=4:sw=4:expandtab /* vim: ts=4:sw=4:expandtab
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -24729,21 +24807,67 @@ window.axolotl.protocol = function() {
return internalSaveDeviceObject(deviceObject, true); return internalSaveDeviceObject(deviceObject, true);
}, },
removeTempKeysFromDevice: function(encodedNumber) {
var deviceObject = textsecure.storage.devices.getDeviceObject(encodedNumber);
try {
delete deviceObject['signedKey'];
delete deviceObject['signedKeyId'];
delete deviceObject['signedKeySignature'];
delete deviceObject['preKey'];
delete deviceObject['preKeyId'];
delete deviceObject['registrationId'];
} catch(_) {}
return internalSaveDeviceObject(deviceObject, false);
},
getDeviceObjectsForNumber: function(number) { getDeviceObjectsForNumber: function(number) {
var map = textsecure.storage.getEncrypted("devices" + number); var map = textsecure.storage.getEncrypted("devices" + number);
return map === undefined ? [] : map.devices; if (map === undefined)
return [];
for (key in map.devices) {
if (map.devices[key].sessions !== undefined) {
var record = new axolotl.sessions.RecipientRecord();
record.deserialize(map.devices[key].sessions);
if (getString(map.identityKey) !== getString(record.identityKey))
throw new Error("Got mismatched identity key on device object load");
map.devices[key].sessions = record;
}
}
return map.devices;
},
getIdentityKeyForNumber: function(number) {
var map = textsecure.storage.getEncrypted("devices" + number);
return map === undefined ? undefined : map.identityKey;
},
checkSaveIdentityKeyForNumber: function(number, identityKey) {
var map = textsecure.storage.getEncrypted("devices" + number);
if (map === undefined)
textsecure.storage.putEncrypted("devices" + number, { devices: [], identityKey: identityKey});
else if (getString(map.identityKey) !== getString(identityKey))
throw new Error("Attempted to overwrite a different identity key");
}, },
getDeviceObject: function(encodedNumber) { getDeviceObject: function(encodedNumber, returnIdentityKey) {
var number = textsecure.utils.unencodeNumber(encodedNumber); var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number[0]); var devices = textsecure.storage.devices.getDeviceObjectsForNumber(number);
if (devices === undefined) if (devices.length == 0) {
if (returnIdentityKey) {
var identityKey = textsecure.storage.devices.getIdentityKeyForNumber(number);
if (identityKey !== undefined)
return {identityKey: identityKey};
}
return undefined; return undefined;
}
for (var i in devices) for (var i in devices)
if (devices[i].encodedNumber == encodedNumber) if (devices[i].encodedNumber == encodedNumber)
return devices[i]; return devices[i];
if (returnIdentityKey)
return {identityKey: devices[0].identityKey};
return undefined; return undefined;
}, },
@ -24768,16 +24892,26 @@ window.axolotl.protocol = function() {
if (devicesRemoved != deviceIdsToRemove.length) if (devicesRemoved != deviceIdsToRemove.length)
throw new Error("Tried to remove unknown device"); throw new Error("Tried to remove unknown device");
if (newDevices.length === 0)
textsecure.storage.removeEncrypted("devices" + number);
else {
map.devices = newDevices;
textsecure.storage.putEncrypted("devices" + number, map);
}
} }
}; };
var internalSaveDeviceObject = function(deviceObject, onlyKeys) { var internalSaveDeviceObject = function(deviceObject, onlyKeys) {
if (deviceObject.identityKey === undefined || deviceObject.encodedNumber === undefined || deviceObject.registrationId === undefined) if (deviceObject.identityKey === undefined || deviceObject.encodedNumber === undefined)
throw new Error("Tried to store invalid deviceObject"); throw new Error("Tried to store invalid deviceObject");
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0]; var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
var map = textsecure.storage.getEncrypted("devices" + number); var map = textsecure.storage.getEncrypted("devices" + number);
if (deviceObject.sessions !== undefined)
deviceObject.sessions = deviceObject.sessions.serialize()
if (map === undefined) if (map === undefined)
map = { devices: [deviceObject], identityKey: deviceObject.identityKey }; map = { devices: [deviceObject], identityKey: deviceObject.identityKey };
else if (map.identityKey != getString(deviceObject.identityKey)) else if (map.identityKey != getString(deviceObject.identityKey))
@ -24793,6 +24927,7 @@ window.axolotl.protocol = function() {
map.devices[i].preKeyId = deviceObject.preKeyId; map.devices[i].preKeyId = deviceObject.preKeyId;
map.devices[i].signedKey = deviceObject.signedKey; map.devices[i].signedKey = deviceObject.signedKey;
map.devices[i].signedKeyId = deviceObject.signedKeyId; map.devices[i].signedKeyId = deviceObject.signedKeyId;
map.devices[i].signedKeySignature = deviceObject.signedKeySignature;
map.devices[i].registrationId = deviceObject.registrationId; map.devices[i].registrationId = deviceObject.registrationId;
} }
updated = true; updated = true;
@ -25930,6 +26065,7 @@ window.textsecure.messaging = function() {
var self = {}; var self = {};
//TODO: Dont hit disk for any of the key-fetching!
function getKeysForNumber(number, updateDevices) { function getKeysForNumber(number, updateDevices) {
var handleResult = function(response) { var handleResult = function(response) {
for (var i in response.devices) { for (var i in response.devices) {
@ -25978,10 +26114,13 @@ window.textsecure.messaging = function() {
} }
return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) { return axolotl.protocol.encryptMessageFor(deviceObjectList[i], message).then(function(encryptedMsg) {
textsecure.storage.devices.removeTempKeysFromDevice(deviceObjectList[i].encodedNumber);
var registrationId = deviceObjectList[i].registrationId || deviceObjectList[i].sessions.registrationId;
jsonData[i] = { jsonData[i] = {
type: encryptedMsg.type, type: encryptedMsg.type,
destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1], destinationDeviceId: textsecure.utils.unencodeNumber(deviceObjectList[i].encodedNumber)[1],
destinationRegistrationId: deviceObjectList[i].registrationId, destinationRegistrationId: registrationId,
body: encryptedMsg.body, body: encryptedMsg.body,
timestamp: timestamp timestamp: timestamp
}; };
@ -26004,7 +26143,8 @@ window.textsecure.messaging = function() {
var doUpdate = false; var doUpdate = false;
for (var i in devicesForNumber) { for (var i in devicesForNumber) {
if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, devicesForNumber[i].registrationId)) var registrationId = devicesForNumber[i].registrationId || devicesForNumber[i].sessions.registrationId;
if (textsecure.storage.groups.needUpdateByDeviceRegistrationId(groupId, number, devicesForNumber[i].encodedNumber, registrationId))
doUpdate = true; doUpdate = true;
} }
if (!doUpdate) if (!doUpdate)
@ -26036,6 +26176,7 @@ window.textsecure.messaging = function() {
var tryMessageAgain = function(number, encodedMessage, message_id) { var tryMessageAgain = function(number, encodedMessage, message_id) {
var message = new Whisper.MessageCollection().add({id: message_id}); var message = new Whisper.MessageCollection().add({id: message_id});
message.fetch().then(function() { message.fetch().then(function() {
//TODO: Encapsuate with the rest of textsecure.storage.devices
textsecure.storage.removeEncrypted("devices" + number); textsecure.storage.removeEncrypted("devices" + number);
var proto = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary'); var proto = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary');
sendMessageProto(message.get('sent_at'), [number], proto, function(res) { sendMessageProto(message.get('sent_at'), [number], proto, function(res) {
@ -26120,7 +26261,7 @@ window.textsecure.messaging = function() {
var promises = []; var promises = [];
for (var j in devicesForNumber) for (var j in devicesForNumber)
if (devicesForNumber[j].registrationId === undefined) if (devicesForNumber[j].sessions === undefined || !devicesForNumber[j].sessions.haveOpenSession())
promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]); promises[promises.length] = getKeysForNumber(number, [parseInt(textsecure.utils.unencodeNumber(devicesForNumber[j].encodedNumber)[1])]);
Promise.all(promises).then(function() { Promise.all(promises).then(function() {

@ -23644,25 +23644,22 @@ window.axolotl.protocol = function() {
} }
crypto_storage.saveSession = function(encodedNumber, session, registrationId) { crypto_storage.saveSession = function(encodedNumber, session, registrationId) {
var device = axolotl.api.storage.sessions.get(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
if (device === undefined) if (record === undefined) {
device = { sessions: {}, encodedNumber: encodedNumber }; if (registrationId === undefined)
throw new Error("Tried to save a session for an existing device that didn't exist");
if (registrationId !== undefined) else
device.registrationId = registrationId; record = new axolotl.sessions.RecipientRecord(session.indexInfo.remoteIdentityKey, registrationId);
}
crypto_storage.saveSessionAndDevice(device, session); var sessions = record._sessions;
}
crypto_storage.saveSessionAndDevice = function(device, session) { if (record.identityKey === null)
if (device.sessions === undefined) record.identityKey = session.indexInfo.remoteIdentityKey;
device.sessions = {}; if (getString(record.identityKey) !== getString(session.indexInfo.remoteIdentityKey))
var sessions = device.sessions; throw new Error("Identity key changed at session save time");
var doDeleteSession = false; var doDeleteSession = false;
if (session.indexInfo.closed == -1 || device.identityKey === undefined)
device.identityKey = session.indexInfo.remoteIdentityKey;
if (session.indexInfo.closed != -1) { if (session.indexInfo.closed != -1) {
doDeleteSession = (session.indexInfo.closed < (new Date().getTime() - MESSAGE_LOST_THRESHOLD_MS)); doDeleteSession = (session.indexInfo.closed < (new Date().getTime() - MESSAGE_LOST_THRESHOLD_MS));
@ -23689,19 +23686,27 @@ window.axolotl.protocol = function() {
for (var key in sessions) for (var key in sessions)
if (sessions[key].indexInfo.closed == -1) if (sessions[key].indexInfo.closed == -1)
openSessionRemaining = true; openSessionRemaining = true;
if (!openSessionRemaining) if (!openSessionRemaining) // Used as a flag to get new pre keys for the next session
try { record.registrationId = null;
delete device['registrationId']; else if (record.registrationId === null && registrationId !== undefined)
} catch(_) {} record.registrationId = registrationId;
else if (record.registrationId === null)
axolotl.api.storage.sessions.put(device); throw new Error("Had open sessions on a record that had no registrationId set");
var identityKey = axolotl.api.storage.identityKeys.get(encodedNumber);
if (identityKey === undefined)
axolotl.api.storage.identityKeys.put(encodedNumber, record.identityKey);
else if (getString(identityKey) !== getString(record.identityKey))
throw new Error("Tried to change identity key at save time");
axolotl.api.storage.sessions.put(encodedNumber, record);
} }
var getSessions = function(encodedNumber) { var getSessions = function(encodedNumber) {
var device = axolotl.api.storage.sessions.get(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
if (device === undefined || device.sessions === undefined) if (record === undefined)
return undefined; return undefined;
return device.sessions; return record._sessions;
} }
crypto_storage.getOpenSession = function(encodedNumber) { crypto_storage.getOpenSession = function(encodedNumber) {
@ -23739,17 +23744,21 @@ window.axolotl.protocol = function() {
} }
crypto_storage.getSessionOrIdentityKeyByBaseKey = function(encodedNumber, baseKey) { crypto_storage.getSessionOrIdentityKeyByBaseKey = function(encodedNumber, baseKey) {
var sessions = getSessions(encodedNumber); var record = axolotl.api.storage.sessions.get(encodedNumber);
var device = axolotl.api.storage.sessions.get(encodedNumber); if (record === undefined) {
if (device === undefined) var identityKey = axolotl.api.storage.identityKeys.get(encodedNumber);
return undefined; if (identityKey === undefined)
return undefined;
return { indexInfo: { remoteIdentityKey: identityKey } };
}
var sessions = record._sessions;
var preferredSession = device.sessions && device.sessions[getString(baseKey)]; var preferredSession = record._sessions[getString(baseKey)];
if (preferredSession !== undefined) if (preferredSession !== undefined)
return preferredSession; return preferredSession;
if (device.identityKey !== undefined) if (record.identityKey !== undefined)
return { indexInfo: { remoteIdentityKey: device.identityKey } }; return { indexInfo: { remoteIdentityKey: record.identityKey } };
throw new Error("Datastore inconsistency: device was stored without identity key"); throw new Error("Datastore inconsistency: device was stored without identity key");
} }
@ -24115,6 +24124,7 @@ window.axolotl.protocol = function() {
// return Promise(encoded [PreKey]WhisperMessage) // return Promise(encoded [PreKey]WhisperMessage)
self.encryptMessageFor = function(deviceObject, pushMessageContent) { self.encryptMessageFor = function(deviceObject, pushMessageContent) {
var session = crypto_storage.getOpenSession(deviceObject.encodedNumber); var session = crypto_storage.getOpenSession(deviceObject.encodedNumber);
var hadSession = session !== undefined;
var doEncryptPushMessageContent = function() { var doEncryptPushMessageContent = function() {
var msg = new axolotl.protobuf.WhisperMessage(); var msg = new axolotl.protobuf.WhisperMessage();
@ -24149,17 +24159,9 @@ window.axolotl.protocol = function() {
result.set(new Uint8Array(encodedMsg), 1); result.set(new Uint8Array(encodedMsg), 1);
result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1); result.set(new Uint8Array(mac, 0, 8), encodedMsg.byteLength + 1);
try {
delete deviceObject['signedKey'];
delete deviceObject['signedKeyId'];
delete deviceObject['signedKeySignature'];
delete deviceObject['preKey'];
delete deviceObject['preKeyId'];
} catch(_) {}
removeOldChains(session); removeOldChains(session);
crypto_storage.saveSessionAndDevice(deviceObject, session); crypto_storage.saveSession(deviceObject.encodedNumber, session, !hadSession ? deviceObject.registrationId : undefined);
return result; return result;
}); });
}); });
@ -24333,3 +24335,57 @@ window.axolotl.protocol = function() {
DeviceControl : deviceMessages.DeviceControl, DeviceControl : deviceMessages.DeviceControl,
}; };
})(); })();
/* vim: ts=4:sw=4
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
;(function() {
'use strict';
window.axolotl = window.axolotl || {};
var RecipientRecord = function(identityKey, registrationId) {
this._sessions = {};
this.identityKey = identityKey !== undefined ? getString(identityKey) : null;
this.registrationId = registrationId;
if (this.registrationId === undefined || typeof this.registrationId !== "number")
this.registrationId = null;
};
RecipientRecord.prototype.serialize = function() {
return textsecure.utils.jsonThing({sessions: this._sessions, registrationId: this.registrationId, identityKey: this.identityKey});
}
RecipientRecord.prototype.deserialize = function(serialized) {
var data = JSON.parse(serialized);
this._sessions = data.sessions;
if (this._sessions === undefined || this._sessions === null || typeof this._sessions !== "object" || Array.isArray(this._sessions))
throw new Error("Error deserializing RecipientRecord");
this.identityKey = data.identityKey;
this.registrationId = data.registrationId;
if (this.identityKey === undefined || this.registrationId === undefined)
throw new Error("Error deserializing RecipientRecord");
}
RecipientRecord.prototype.haveOpenSession = function() {
return this.registrationId !== null;
}
window.axolotl.sessions = {
RecipientRecord: RecipientRecord,
};
})();

Loading…
Cancel
Save