Move identity key storage functions to axolotl store

This commit is contained in:
lilia 2015-04-21 13:33:29 -07:00
parent f38b18ef63
commit 20ebc3f890
6 changed files with 37 additions and 71 deletions

View file

@ -86,17 +86,6 @@
return textsecure.storage.get('registrationId');
},
getIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to get identity key for undefined/null key");
return convertToArrayBuffer(textsecure.storage.devices.getIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0]));
},
putIdentityKey: function(identifier, identityKey) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to put identity key for undefined/null key");
return textsecure.storage.devices.checkSaveIdentityKeyForNumber(textsecure.utils.unencodeNumber(identifier)[0], identityKey);
},
/* Returns a prekeypair object or undefined */
getPreKey: function(keyId) {
var prekey = new PreKey({id: keyId});
@ -199,7 +188,7 @@
return textsecure.storage.devices.getDeviceObject(encodedNumber).then(function(device) {
if (device === undefined) {
return textsecure.storage.devices.getIdentityKeyForNumber(number).then(function(identityKey) {
return textsecure.storage.axolotl.getIdentityKey(number).then(function(identityKey) {
device = { encodedNumber: encodedNumber,
//TODO: Remove this duplication
identityKey: identityKey
@ -214,6 +203,37 @@
throw new Error("Tried to put session for undefined/null key");
return Promise.resolve(textsecure.storage.remove("sessions" + number));
},
getIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to get identity key for undefined/null key");
var number = textsecure.utils.unencodeNumber(identifier)[0];
return Promise.resolve(convertToArrayBuffer(function() {
var map = textsecure.storage.get("devices" + number);
return map === undefined ? undefined : map.identityKey;
}());
},
putIdentityKey: function(identifier, identityKey) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to put identity key for undefined/null key");
var number = textsecure.utils.unencodeNumber(identifier)[0];
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey});
else if (getString(map.identityKey) !== getString(identityKey))
throw new Error("Attempted to overwrite a different identity key");
})());
},
removeIdentityKey: function(number) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
throw new Error("Tried to remove identity for unknown number");
textsecure.storage.remove("devices" + number);
return textsecure.storage.axolotl.removeAllSessions(number);
})());
},
};

View file

@ -38126,33 +38126,6 @@ axolotlInternal.RecipientRecord = function() {
})());
},
getIdentityKeyForNumber: function(number) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
return map === undefined ? undefined : map.identityKey;
})());
},
checkSaveIdentityKeyForNumber: function(number, identityKey) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey});
else if (getString(map.identityKey) !== getString(identityKey))
throw new Error("Attempted to overwrite a different identity key");
})());
},
removeIdentityKeyForNumber: function(number) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
throw new Error("Tried to remove identity for unknown number");
textsecure.storage.remove("devices" + number);
return textsecure.storage.axolotl.removeAllSessions(number);
})());
},
getDeviceObject: function(encodedNumber) {
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {

View file

@ -241,7 +241,7 @@
throw 'No conflicts to resolve';
}
return textsecure.storage.devices.removeIdentityKeyForNumber(number).then(function() {
return textsecure.storage.axolotl.removeIdentityKey(number).then(function() {
this.messageCollection.each(function(message) {
if (message.hasKeyConflict(number)) {
message.resolveConflict(number);

View file

@ -73,8 +73,8 @@
var number = this.model.id;
var view = new Whisper.KeyVerificationView({
model: {
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
their_key: textsecure.storage.axolotl.getIdentityKey(number),
your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber())
}
});
this.$el.hide();

View file

@ -57,8 +57,8 @@
verify: function(number) {
var view = new Whisper.KeyVerificationView({
model: {
their_key: textsecure.storage.devices.getIdentityKeyForNumber(number),
your_key: textsecure.storage.devices.getIdentityKeyForNumber(textsecure.storage.user.getNumber())
their_key: textsecure.storage.axolotl.getIdentityKey(number),
your_key: textsecure.storage.axolotl.getIdentityKey(textsecure.storage.user.getNumber())
}
});
this.$el.hide();

View file

@ -55,33 +55,6 @@
})());
},
getIdentityKeyForNumber: function(number) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
return map === undefined ? undefined : map.identityKey;
})());
},
checkSaveIdentityKeyForNumber: function(number, identityKey) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
textsecure.storage.put("devices" + number, { devices: [], identityKey: identityKey});
else if (getString(map.identityKey) !== getString(identityKey))
throw new Error("Attempted to overwrite a different identity key");
})());
},
removeIdentityKeyForNumber: function(number) {
return Promise.resolve((function() {
var map = textsecure.storage.get("devices" + number);
if (map === undefined)
throw new Error("Tried to remove identity for unknown number");
textsecure.storage.remove("devices" + number);
return textsecure.storage.axolotl.removeAllSessions(number);
})());
},
getDeviceObject: function(encodedNumber) {
var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {