1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 05:30:01 +00:00

Added implementation to cipher service

This commit is contained in:
gbubemismith
2025-03-28 14:02:53 -04:00
parent 876d8ce66a
commit 3d4f3309e5

View File

@@ -15,6 +15,7 @@ import {
import { SemVer } from "semver";
import { KeyService } from "@bitwarden/key-management";
import { CipherView as SdkCipherView } from "@bitwarden/sdk-internal";
import { ApiService } from "../../abstractions/api.service";
import { SearchService } from "../../abstractions/search.service";
@@ -30,6 +31,7 @@ import { ListResponse } from "../../models/response/list.response";
import { View } from "../../models/view/view";
import { ConfigService } from "../../platform/abstractions/config/config.service";
import { I18nService } from "../../platform/abstractions/i18n.service";
import { SdkService } from "../../platform/abstractions/sdk/sdk.service";
import { StateService } from "../../platform/abstractions/state.service";
import { sequentialize } from "../../platform/misc/sequentialize";
import { Utils } from "../../platform/misc/utils";
@@ -111,6 +113,7 @@ export class CipherService implements CipherServiceAbstraction {
private configService: ConfigService,
private stateProvider: StateProvider,
private accountService: AccountService,
private sdkService: SdkService,
) {}
localData$(userId: UserId): Observable<Record<CipherId, LocalData>> {
@@ -156,6 +159,23 @@ export class CipherService implements CipherServiceAbstraction {
);
}
/**
* {@link CipherServiceAbstraction.decrypt$}
*/
decrypt$(userId: UserId, cipher: Cipher): Observable<SdkCipherView> {
return this.sdkService.userClient$(userId).pipe(
map((sdk) => {
if (!sdk) {
throw new Error("SDK is undefined");
}
using ref = sdk.take();
return ref.value.vault().ciphers().decrypt(cipher.toSdkCipher());
}),
);
}
async setDecryptedCipherCache(value: CipherView[], userId: UserId) {
// Sometimes we might prematurely decrypt the vault and that will result in no ciphers
// if we cache it then we may accidentally return it when it's not right, we'd rather try decryption again.