[de]serialize sessions storage in device storage

This commit is contained in:
Matt Corallo 2015-01-20 22:29:23 -10:00 committed by lilia
parent 1bef1ce5d3
commit 92d0de6837
2 changed files with 17 additions and 7 deletions

View file

@ -33,11 +33,7 @@
var device = textsecure.storage.devices.getDeviceObject(identifier, true);
if (device === undefined || device.sessions === undefined)
return undefined;
var record = new axolotl.sessions.RecipientRecord();
record.deserialize(device.sessions);
if (getString(device.identityKey) !== getString(record.identityKey))
throw new Error("Got mismatched identity key on sessions load");
return record;
return device.sessions;
},
put: function(identifier, record) {
var device = textsecure.storage.devices.getDeviceObject(identifier);
@ -50,7 +46,7 @@
}
if (getString(device.identityKey) !== getString(record.identityKey))
throw new Error("Tried to put session for device with changed identity key");
device.sessions = record.serialize();
device.sessions = record;
return textsecure.storage.devices.saveDeviceObject(device);
}
}

View file

@ -46,7 +46,18 @@
getDeviceObjectsForNumber: function(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) {
@ -122,6 +133,9 @@
var number = textsecure.utils.unencodeNumber(deviceObject.encodedNumber)[0];
var map = textsecure.storage.getEncrypted("devices" + number);
if (deviceObject.sessions !== undefined)
deviceObject.sessions = deviceObject.sessions.serialize()
if (map === undefined)
map = { devices: [deviceObject], identityKey: deviceObject.identityKey };
else if (map.identityKey != getString(deviceObject.identityKey))