protected values comparison

This commit is contained in:
Antelle 2016-01-17 16:12:35 +03:00
parent 0e1dcdb11b
commit b583f249d7
2 changed files with 30 additions and 3 deletions

View File

@ -78,4 +78,26 @@ kdbxweb.ProtectedValue.prototype.includesLower = function(findLower) {
return matches;
};
kdbxweb.ProtectedValue.prototype.equals = function(other) {
if (!other) {
return false;
}
if (!other.isProtected) {
return this.textLength === other.length && this.includes(other);
}
if (other === this) {
return true;
}
var len = this.byteLength;
if (len !== other.byteLength) {
return false;
}
for (var i = 0; i < len; i++) {
if ((this._value[i] ^ this._salt[i]) !== (other._value[i] ^ other._salt[i])) {
return false;
}
}
return true;
};
module.exports = kdbxweb.ProtectedValue;

View File

@ -86,9 +86,14 @@ var FieldView = Backbone.View.extend({
return;
}
this.editing = false;
var oldValText = this.value && this.value.isProtected ? this.value.getText() : this.value;
var newValText = newVal && newVal.isProtected ? newVal.getText() : newVal;
var textEqual = _.isEqual(newValText, oldValText);
var textEqual;
if (this.value && this.value.isProtected) {
textEqual = this.value.equals(newVal);
} else if (newVal && newVal.isProtected) {
textEqual = newVal.equals(this.value);
} else {
textEqual = _.isEqual(this.value, newVal);
}
var protectedEqual = (newVal && newVal.isProtected) === (this.value && this.value.isProtected);
var nameChanged = extra && extra.newField;
var arg;