Resolve true if saveIdentity overwrote a key

Reflect whether a saveIdentity operation reflects a replacement of an existing
key or not. The return value can be used by the caller to decide whether they
should clear sessions for the recipient.
This commit is contained in:
lilia 2017-05-26 14:24:17 -07:00
parent 63d2536263
commit ee00f080f4

View File

@ -55,7 +55,16 @@ SignalProtocolStore.prototype = {
saveIdentity: function(identifier, identityKey) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to put identity key for undefined/null key");
return Promise.resolve(this.put('identityKey' + identifier, identityKey));
var existing = this.get('identityKey' + identifier);
this.put('identityKey' + identifier, identityKey)
if (existing && util.toString(identityKey) !== util.toString(existing)) {
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
},
/* Returns a prekeypair object or undefined */