mirror of
https://github.com/bitwarden/jslib
synced 2025-12-28 06:03:14 +00:00
Move decrypt to FolderView
This commit is contained in:
@@ -7,7 +7,6 @@ import { FolderView } from "../models/view/folderView";
|
||||
export abstract class FolderService {
|
||||
clearCache: (userId?: string) => Promise<void>;
|
||||
encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise<Folder>;
|
||||
decrypt: (model: Folder, key?: SymmetricCryptoKey) => Promise<FolderView>;
|
||||
get: (id: string) => Promise<Folder>;
|
||||
getAll: () => Promise<Folder[]>;
|
||||
getAllDecrypted: () => Promise<FolderView[]>;
|
||||
|
||||
@@ -81,7 +81,7 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
|
||||
const folder = FolderWithIdExport.toDomain(f);
|
||||
if (folder != null) {
|
||||
folder.id = null;
|
||||
const view = await this.folderService.decrypt(folder);
|
||||
const view = await FolderView.fromFolder(this.cryptoService, folder);
|
||||
groupingsMap.set(f.id, this.result.folders.length);
|
||||
this.result.folders.push(view);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user