1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-17 16:53:20 +00:00

Move decrypt to FolderView

This commit is contained in:
Hinton
2022-04-20 10:50:51 +02:00
parent fc67f99521
commit 708bfcb026
7 changed files with 64 additions and 29 deletions

View File

@@ -96,11 +96,10 @@ export class EncString {
}
}
/**
* @deprecated As of 2022-04-20, use {@link decryptWithCryptoService} instead
*/
async decrypt(orgId: string, key: SymmetricCryptoKey = null): Promise<string> {
if (this.decryptedValue != null) {
return this.decryptedValue;
}
let cryptoService: CryptoService;
const containerService = (Utils.global as any).bitwardenContainerService;
if (containerService) {
@@ -109,8 +108,20 @@ export class EncString {
throw new Error("global bitwardenContainerService not initialized.");
}
return this.decryptWithCryptoService(cryptoService, orgId, key);
}
async decryptWithCryptoService(
cryptoService: CryptoService,
orgId?: string,
key: SymmetricCryptoKey = null
): Promise<string> {
if (this.decryptedValue != null) {
return this.decryptedValue;
}
try {
if (key == null) {
if (orgId != null && key == null) {
key = await cryptoService.getOrgKey(orgId);
}
this.decryptedValue = await cryptoService.decryptToUtf8(this, key);

View File

@@ -1,9 +1,24 @@
import { CryptoService } from "jslib-common/abstractions/crypto.service";
import { Folder } from "../domain/folder";
import { SymmetricCryptoKey } from "../domain/symmetricCryptoKey";
import { ITreeNodeObject } from "../domain/treeNode";
import { View } from "./view";
export class FolderView implements View, ITreeNodeObject {
export class FolderView implements ITreeNodeObject {
id: string = null;
name: string = null;
revisionDate: Date = null;
static async fromFolder(
cryptoService: CryptoService,
folder: Folder,
key?: SymmetricCryptoKey
): Promise<FolderView> {
const view = new FolderView();
view.id = folder.id;
view.name = await folder.name.decryptWithCryptoService(cryptoService, null, key);
view.revisionDate = folder.revisionDate;
return view;
}
}