master key future-proofing.
This commit is contained in:
parent
5115b43435
commit
70225dcb57
@ -2720,6 +2720,13 @@ MasterKey.prototype.fromRaw = function fromRaw(raw) {
|
|||||||
if (this.encrypted) {
|
if (this.encrypted) {
|
||||||
this.iv = p.readVarBytes();
|
this.iv = p.readVarBytes();
|
||||||
this.ciphertext = p.readVarBytes();
|
this.ciphertext = p.readVarBytes();
|
||||||
|
|
||||||
|
// Future-proofing:
|
||||||
|
assert(p.readU8() === 0);
|
||||||
|
assert(p.readU32() === 50000);
|
||||||
|
assert(p.readU32() === 0);
|
||||||
|
assert(p.readU32() === 0);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2767,20 +2774,22 @@ MasterKey.fromKey = function fromKey(key) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MasterKey.prototype.toJSON = function toJSON() {
|
MasterKey.prototype.toJSON = function toJSON() {
|
||||||
var iv, ciphertext, key;
|
|
||||||
|
|
||||||
if (this.encrypted) {
|
if (this.encrypted) {
|
||||||
iv = this.iv.toString('hex');
|
return {
|
||||||
ciphertext = this.ciphertext.toString('hex');
|
encrypted: true,
|
||||||
} else {
|
iv: this.iv.toString('hex'),
|
||||||
key = this.key.toJSON();
|
ciphertext: this.ciphertext.toString('hex'),
|
||||||
|
// Future-proofing:
|
||||||
|
algorithm: 'pbkdf2',
|
||||||
|
N: 50000,
|
||||||
|
r: 0,
|
||||||
|
p: 0
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
encrypted: this.encrypted,
|
encrypted: false,
|
||||||
iv: iv,
|
key: this.key.toJSON()
|
||||||
ciphertext: ciphertext,
|
|
||||||
key: key
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2798,6 +2807,11 @@ MasterKey.prototype.fromJSON = function fromJSON(json) {
|
|||||||
if (json.encrypted) {
|
if (json.encrypted) {
|
||||||
assert(typeof json.iv === 'string');
|
assert(typeof json.iv === 'string');
|
||||||
assert(typeof json.ciphertext === 'string');
|
assert(typeof json.ciphertext === 'string');
|
||||||
|
// Future-proofing:
|
||||||
|
assert(json.algorithm === 'pbkdf2');
|
||||||
|
assert(json.N === 50000);
|
||||||
|
assert(json.r === 0);
|
||||||
|
assert(json.p === 0);
|
||||||
this.iv = new Buffer(json.iv, 'hex');
|
this.iv = new Buffer(json.iv, 'hex');
|
||||||
this.ciphertext = new Buffer(json.ciphertext, 'hex');
|
this.ciphertext = new Buffer(json.ciphertext, 'hex');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user