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) {
|
||||
this.iv = 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;
|
||||
}
|
||||
|
||||
@ -2767,20 +2774,22 @@ MasterKey.fromKey = function fromKey(key) {
|
||||
*/
|
||||
|
||||
MasterKey.prototype.toJSON = function toJSON() {
|
||||
var iv, ciphertext, key;
|
||||
|
||||
if (this.encrypted) {
|
||||
iv = this.iv.toString('hex');
|
||||
ciphertext = this.ciphertext.toString('hex');
|
||||
} else {
|
||||
key = this.key.toJSON();
|
||||
return {
|
||||
encrypted: true,
|
||||
iv: this.iv.toString('hex'),
|
||||
ciphertext: this.ciphertext.toString('hex'),
|
||||
// Future-proofing:
|
||||
algorithm: 'pbkdf2',
|
||||
N: 50000,
|
||||
r: 0,
|
||||
p: 0
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
encrypted: this.encrypted,
|
||||
iv: iv,
|
||||
ciphertext: ciphertext,
|
||||
key: key
|
||||
encrypted: false,
|
||||
key: this.key.toJSON()
|
||||
};
|
||||
};
|
||||
|
||||
@ -2798,6 +2807,11 @@ MasterKey.prototype.fromJSON = function fromJSON(json) {
|
||||
if (json.encrypted) {
|
||||
assert(typeof json.iv === '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.ciphertext = new Buffer(json.ciphertext, 'hex');
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user