mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
* Extract getFeatureFlagValue to pure function Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add broadcasting abstractions and OnServerConfigChange interface. Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add implementation of onServerConfigChange on encrypt services Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add onServerConfigChange implementation for encrypt worker Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Wire up broadcasting in dependency injection Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add unit tests * Handle subscribing for onServerConfigChange in init services --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com>
47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { BulkEncryptService } from "@bitwarden/common/key-management/crypto/abstractions/bulk-encrypt.service";
|
|
import { Decryptable } from "@bitwarden/common/platform/interfaces/decryptable.interface";
|
|
import { InitializerMetadata } from "@bitwarden/common/platform/interfaces/initializer-metadata.interface";
|
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
|
|
|
import { ServerConfig } from "../../../platform/abstractions/config/server-config";
|
|
import { EncryptService } from "../abstractions/encrypt.service";
|
|
|
|
/**
|
|
* @deprecated For the feature flag from PM-4154, remove once feature is rolled out
|
|
*/
|
|
export class FallbackBulkEncryptService implements BulkEncryptService {
|
|
private featureFlagEncryptService: BulkEncryptService;
|
|
private currentServerConfig: ServerConfig | undefined = undefined;
|
|
|
|
constructor(protected encryptService: EncryptService) {}
|
|
|
|
/**
|
|
* Decrypts items using a web worker if the environment supports it.
|
|
* Will fall back to the main thread if the window object is not available.
|
|
*/
|
|
async decryptItems<T extends InitializerMetadata>(
|
|
items: Decryptable<T>[],
|
|
key: SymmetricCryptoKey,
|
|
): Promise<T[]> {
|
|
if (this.featureFlagEncryptService != null) {
|
|
return await this.featureFlagEncryptService.decryptItems(items, key);
|
|
} else {
|
|
return await this.encryptService.decryptItems(items, key);
|
|
}
|
|
}
|
|
|
|
async setFeatureFlagEncryptService(featureFlagEncryptService: BulkEncryptService) {
|
|
if (this.currentServerConfig !== undefined) {
|
|
featureFlagEncryptService.onServerConfigChange(this.currentServerConfig);
|
|
}
|
|
this.featureFlagEncryptService = featureFlagEncryptService;
|
|
}
|
|
|
|
onServerConfigChange(newConfig: ServerConfig): void {
|
|
this.currentServerConfig = newConfig;
|
|
(this.featureFlagEncryptService ?? this.encryptService).onServerConfigChange(newConfig);
|
|
}
|
|
}
|