Add isTrustedIdentity to SignalProtocolStore

Adds a new required storage method for the protocol library.

// FREEBIE
This commit is contained in:
lilia 2016-05-03 23:58:57 -07:00
parent 0dc5a0488c
commit e659104cbf
2 changed files with 26 additions and 0 deletions

View file

@ -250,6 +250,19 @@
});
},
isTrustedIdentity: function(identifier, publicKey) {
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 new Promise(function(resolve) {
var identityKey = new IdentityKey({id: number});
identityKey.fetch().always(function() {
var oldpublicKey = identityKey.get('publicKey');
resolve(!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey));
});
});
},
loadIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined) {
throw new Error("Tried to get identity key for undefined/null key");

View file

@ -29,6 +29,19 @@ SignalProtocolStore.prototype = {
delete this.store[key];
},
isTrustedIdentity: function(identifier, identityKey) {
if (identifier === null || identifier === undefined) {
throw new error("tried to check identity key for undefined/null key");
}
if (!(identityKey instanceof ArrayBuffer)) {
throw new error("Expected identityKey to be an ArrayBuffer");
}
var trusted = this.get('identityKey' + identifier);
if (trusted === undefined) {
return Promise.resolve(true);
}
return Promise.resolve(identityKey === trusted);
},
loadIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to get identity key for undefined/null key");