Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
allow original cipher to be passed during encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Aug 15, 2018
1 parent d56c5ff commit f16fc58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/abstractions/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class CipherService {
decryptedCipherCache: CipherView[];

clearCache: () => void;
encrypt: (model: CipherView, key?: SymmetricCryptoKey) => Promise<Cipher>;
encrypt: (model: CipherView, key?: SymmetricCryptoKey, originalCipher?: Cipher) => Promise<Cipher>;
encryptFields: (fieldsModel: FieldView[], key: SymmetricCryptoKey) => Promise<Field[]>;
encryptField: (fieldModel: FieldView, key: SymmetricCryptoKey) => Promise<Field>;
get: (id: string) => Promise<Cipher>;
Expand Down
9 changes: 6 additions & 3 deletions src/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ export class CipherService implements CipherServiceAbstraction {
this.decryptedCipherCache = null;
}

async encrypt(model: CipherView, key?: SymmetricCryptoKey): Promise<Cipher> {
async encrypt(model: CipherView, key?: SymmetricCryptoKey, originalCipher: Cipher = null): Promise<Cipher> {
// Adjust password history
if (model.id != null) {
const existingCipher = await (await this.get(model.id)).decrypt();
if (existingCipher != null) {
if (originalCipher == null) {
originalCipher = await this.get(model.id);
}
if (originalCipher != null) {
const existingCipher = await originalCipher.decrypt();
model.passwordHistory = existingCipher.passwordHistory || [];
if (model.type === CipherType.Login && existingCipher.type === CipherType.Login) {
if (existingCipher.login.password != null && existingCipher.login.password !== '' &&
Expand Down

0 comments on commit f16fc58

Please sign in to comment.