From 92d0de6837c8c7b688d1d36a14f666c8fda58207 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 20 Jan 2015 22:29:23 -1000 Subject: [PATCH] [de]serialize sessions storage in device storage --- libtextsecure/axolotl_wrapper.js | 8 ++------ libtextsecure/storage/devices.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libtextsecure/axolotl_wrapper.js b/libtextsecure/axolotl_wrapper.js index 3c404891..bfe4a2e8 100644 --- a/libtextsecure/axolotl_wrapper.js +++ b/libtextsecure/axolotl_wrapper.js @@ -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); } } diff --git a/libtextsecure/storage/devices.js b/libtextsecure/storage/devices.js index e21d2f36..239e04af 100644 --- a/libtextsecure/storage/devices.js +++ b/libtextsecure/storage/devices.js @@ -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))