bitwarden-estensione-browser/libs/common/src/models/domain/password.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Jsonify } from "type-fest";
import { PasswordHistoryData } from "../data/password-history.data";
import { PasswordHistoryView } from "../view/password-history.view";
2018-07-27 22:44:20 +02:00
import Domain from "./domain-base";
import { EncString } from "./enc-string";
import { SymmetricCryptoKey } from "./symmetric-crypto-key";
2018-07-27 22:44:20 +02:00
export class Password extends Domain {
password: EncString;
2018-07-27 22:44:20 +02:00
lastUsedDate: Date;
constructor(obj?: PasswordHistoryData) {
2018-07-27 22:44:20 +02:00
super();
if (obj == null) {
return;
}
this.buildDomainModel(this, obj, {
password: null,
});
2018-08-20 22:01:26 +02:00
this.lastUsedDate = new Date(obj.lastUsedDate);
2018-07-27 22:44:20 +02:00
}
decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise<PasswordHistoryView> {
2019-04-14 03:20:04 +02:00
return this.decryptObj(
new PasswordHistoryView(this),
2021-12-16 13:36:21 +01:00
{
2018-07-27 22:44:20 +02:00
password: null,
2021-12-16 13:36:21 +01:00
},
orgId,
encKey
);
}
2018-07-27 22:44:20 +02:00
toPasswordHistoryData(): PasswordHistoryData {
const ph = new PasswordHistoryData();
2018-08-20 22:01:26 +02:00
ph.lastUsedDate = this.lastUsedDate.toISOString();
2018-07-27 22:44:20 +02:00
this.buildDataModel(this, ph, {
password: null,
});
return ph;
}
static fromJSON(obj: Partial<Jsonify<Password>>): Password {
if (obj == null) {
return null;
}
const password = EncString.fromJSON(obj.password);
const lastUsedDate = obj.lastUsedDate == null ? null : new Date(obj.lastUsedDate);
return Object.assign(new Password(), obj, {
password,
lastUsedDate,
});
}
2018-07-27 22:44:20 +02:00
}