// 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( items: Decryptable[], key: SymmetricCryptoKey, ): Promise { 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); } }