mirror of
https://github.com/bitwarden/browser
synced 2026-01-07 11:03:30 +00:00
* Remove orgid in vault decryption code * Remove folder usage without provided key * Fix folder test * Fix build * Fix build * Fix build * Fix tests * Update spec to not use EncString decrypt * Fix tests * Fix test * Fix test * Remove comment * Remove org id parameter
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { Jsonify } from "type-fest";
|
|
|
|
import { PasswordHistory } from "@bitwarden/sdk-internal";
|
|
|
|
import { EncString } from "../../../key-management/crypto/models/enc-string";
|
|
import Domain from "../../../platform/models/domain/domain-base";
|
|
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
|
|
import { PasswordHistoryData } from "../data/password-history.data";
|
|
import { PasswordHistoryView } from "../view/password-history.view";
|
|
|
|
export class Password extends Domain {
|
|
password!: EncString;
|
|
lastUsedDate!: Date;
|
|
|
|
constructor(obj?: PasswordHistoryData) {
|
|
super();
|
|
if (obj == null) {
|
|
return;
|
|
}
|
|
|
|
this.password = new EncString(obj.password);
|
|
this.lastUsedDate = new Date(obj.lastUsedDate);
|
|
}
|
|
|
|
decrypt(encKey: SymmetricCryptoKey): Promise<PasswordHistoryView> {
|
|
return this.decryptObj<Password, PasswordHistoryView>(
|
|
this,
|
|
new PasswordHistoryView(this),
|
|
["password"],
|
|
encKey,
|
|
"DomainType: PasswordHistory",
|
|
);
|
|
}
|
|
|
|
toPasswordHistoryData(): PasswordHistoryData {
|
|
const ph = new PasswordHistoryData();
|
|
ph.lastUsedDate = this.lastUsedDate.toISOString();
|
|
this.buildDataModel(this, ph, {
|
|
password: null,
|
|
});
|
|
return ph;
|
|
}
|
|
|
|
static fromJSON(obj: Jsonify<Password> | undefined): Password | undefined {
|
|
if (obj == null) {
|
|
return undefined;
|
|
}
|
|
|
|
const passwordHistory = new Password();
|
|
passwordHistory.password = EncString.fromJSON(obj.password);
|
|
passwordHistory.lastUsedDate = new Date(obj.lastUsedDate);
|
|
|
|
return passwordHistory;
|
|
}
|
|
|
|
/**
|
|
* Maps Password to SDK format.
|
|
*
|
|
* @returns {PasswordHistory} The SDK password history object.
|
|
*/
|
|
toSdkPasswordHistory(): PasswordHistory {
|
|
return {
|
|
password: this.password.toSdk(),
|
|
lastUsedDate: this.lastUsedDate.toISOString(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Maps an SDK PasswordHistory object to a Password
|
|
* @param obj - The SDK PasswordHistory object
|
|
*/
|
|
static fromSdkPasswordHistory(obj?: PasswordHistory): Password | undefined {
|
|
if (!obj) {
|
|
return undefined;
|
|
}
|
|
|
|
const passwordHistory = new Password();
|
|
passwordHistory.password = EncString.fromJSON(obj.password);
|
|
passwordHistory.lastUsedDate = new Date(obj.lastUsedDate);
|
|
|
|
return passwordHistory;
|
|
}
|
|
}
|