Skip to main content

bitwarden_core/key_management/
crypto_settings.rs

1use std::sync::atomic::{AtomicBool, Ordering};
2
3/// Key-management settings the host sets on a client after building it.
4///
5/// An application can run several clients for one user at once, e.g. a browser extension's
6/// background and each of its open popups. Work that must happen once per application, such as
7/// migrations, belongs to one of them.
8pub(crate) struct CryptoSettings {
9    /// Whether unlock runs local state migrations, such as the V1 to V2 PIN migration.
10    perform_local_unlock_migrations: AtomicBool,
11}
12
13impl CryptoSettings {
14    pub(crate) fn new() -> Self {
15        Self {
16            perform_local_unlock_migrations: AtomicBool::new(true),
17        }
18    }
19
20    pub(crate) fn perform_local_unlock_migrations(&self) -> bool {
21        self.perform_local_unlock_migrations.load(Ordering::Relaxed)
22    }
23
24    pub(crate) fn disable_local_unlock_migrations(&self) {
25        self.perform_local_unlock_migrations
26            .store(false, Ordering::Relaxed);
27    }
28}
29
30impl Default for CryptoSettings {
31    fn default() -> Self {
32        Self::new()
33    }
34}