feat: save hash type with hash in backup

This commit is contained in:
thecodrr
2020-10-28 13:25:10 +05:00
parent 74c2946874
commit c2a8eb7451

View File

@@ -31,6 +31,7 @@ export default class Backup {
const db = Object.fromEntries(await this._db.context.readMulti(keys)); const db = Object.fromEntries(await this._db.context.readMulti(keys));
db.h = md5.hex(JSON.stringify(db)); db.h = md5.hex(JSON.stringify(db));
db.ht = "md5";
if (encrypt) { if (encrypt) {
const key = await this._db.user.key(); const key = await this._db.user.key();
@@ -89,7 +90,16 @@ export default class Backup {
_verify(db) { _verify(db) {
const hash = db.h; const hash = db.h;
const hash_type = db.ht;
delete db.h; delete db.h;
delete db.ht;
switch (hash_type) {
case "md5": {
return hash == md5.hex(JSON.stringify(db)); return hash == md5.hex(JSON.stringify(db));
} }
default: {
return false;
}
}
}
} }