Skip to content

Commit 546737a

Browse files
committed
Move everything to a separate crate
1 parent ccbba00 commit 546737a

File tree

23 files changed

+169
-51
lines changed

23 files changed

+169
-51
lines changed

Cargo.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" }
3131
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" }
3232
bitwarden-ipc = { path = "crates/bitwarden-ipc", version = "=1.0.0" }
3333
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
34+
bitwarden-state = { path = "crates/bitwarden-state", version = "=1.0.0" }
3435
bitwarden-threading = { path = "crates/bitwarden-threading", version = "=1.0.0" }
3536
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
3637
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
@@ -39,6 +40,7 @@ bitwarden-uuid-macro = { path = "crates/bitwarden-uuid-macro", version = "=1.0.0
3940
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=1.0.0" }
4041

4142
# External crates that are expected to maintain a consistent version across all crates
43+
async-trait = ">=0.1.80, <0.2"
4244
chrono = { version = ">=0.4.26, <0.5", features = [
4345
"clock",
4446
"serde",

crates/bitwarden-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ wasm = [
2828
] # WASM support
2929

3030
[dependencies]
31-
async-trait = ">=0.1.80, <0.2"
3231
base64 = ">=0.22.1, <0.23"
3332
bitwarden-api-api = { workspace = true }
3433
bitwarden-api-identity = { workspace = true }
3534
bitwarden-crypto = { workspace = true }
3635
bitwarden-error = { workspace = true }
36+
bitwarden-state = { workspace = true }
3737
bitwarden-uuid = { workspace = true }
3838
chrono = { workspace = true, features = ["std"] }
3939
# We don't use this directly (it's used by rand), but we need it here to enable WASM support

crates/bitwarden-core/src/client/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::sync::{Arc, OnceLock, RwLock};
22

33
use bitwarden_crypto::KeyStore;
4+
#[cfg(feature = "internal")]
5+
use bitwarden_state::repository::RepositoryMap;
46
use reqwest::header::{self, HeaderValue};
57

68
use super::internal::InternalClient;
@@ -9,7 +11,6 @@ use crate::client::flags::Flags;
911
use crate::client::{
1012
client_settings::ClientSettings,
1113
internal::{ApiConfigurations, Tokens},
12-
repository::RepositoryMap,
1314
};
1415

1516
/// The main struct to interact with the Bitwarden SDK.

crates/bitwarden-core/src/client/internal.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use bitwarden_crypto::KeyStore;
55
use bitwarden_crypto::SymmetricCryptoKey;
66
#[cfg(feature = "internal")]
77
use bitwarden_crypto::{EncString, Kdf, MasterKey, PinKey, UnsignedSharedKey};
8+
#[cfg(feature = "internal")]
9+
use bitwarden_state::repository::RepositoryMap;
810
use chrono::Utc;
911
use uuid::Uuid;
1012

@@ -19,7 +21,6 @@ use crate::{
1921
#[cfg(feature = "internal")]
2022
use crate::{
2123
client::encryption_settings::EncryptionSettingsError,
22-
client::repository::{Repository, RepositoryMap},
2324
client::{flags::Flags, login_method::UserLoginMethod},
2425
error::NotAuthenticatedError,
2526
};
@@ -66,7 +67,7 @@ pub struct InternalClient {
6667
pub(super) key_store: KeyStore<KeyIds>,
6768

6869
#[cfg(feature = "internal")]
69-
pub(super) repository_map: RwLock<RepositoryMap>,
70+
pub(crate) repository_map: RwLock<RepositoryMap>,
7071
}
7172

7273
impl InternalClient {
@@ -249,20 +250,4 @@ impl InternalClient {
249250
) -> Result<(), EncryptionSettingsError> {
250251
EncryptionSettings::set_org_keys(org_keys, &self.key_store)
251252
}
252-
253-
#[cfg(feature = "internal")]
254-
pub fn register_repository<T: 'static + Repository<V>, V: 'static>(&self, store: Arc<T>) {
255-
self.repository_map
256-
.write()
257-
.expect("RwLock is not poisoned")
258-
.insert(store);
259-
}
260-
261-
#[cfg(feature = "internal")]
262-
pub fn get_repository<T: 'static>(&self) -> Option<Arc<dyn Repository<T>>> {
263-
self.repository_map
264-
.read()
265-
.expect("RwLock is not poisoned")
266-
.get()
267-
}
268253
}

crates/bitwarden-core/src/client/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,3 @@ pub use client_settings::{ClientSettings, DeviceType};
2323
#[allow(missing_docs)]
2424
#[cfg(feature = "internal")]
2525
pub mod test_accounts;
26-
27-
#[cfg(feature = "internal")]
28-
pub mod repository;

crates/bitwarden-core/src/platform/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod generate_fingerprint;
66
mod get_user_api_key;
77
mod platform_client;
88
mod secret_verification_request;
9+
mod state_client;
910

1011
pub use generate_fingerprint::{
1112
FingerprintError, FingerprintRequest, FingerprintResponse, UserFingerprintError,
@@ -14,3 +15,4 @@ pub(crate) use get_user_api_key::get_user_api_key;
1415
pub use get_user_api_key::{UserApiKeyError, UserApiKeyResponse};
1516
pub use platform_client::PlatformClient;
1617
pub use secret_verification_request::SecretVerificationRequest;
18+
pub use state_client::StateClient;

crates/bitwarden-core/src/platform/platform_client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ impl PlatformClient {
3333
) -> Result<UserApiKeyResponse, UserApiKeyError> {
3434
get_user_api_key(&self.client, &input).await
3535
}
36+
37+
/// Access to state functionality.
38+
pub fn state(&self) -> super::StateClient {
39+
super::StateClient {
40+
client: self.client.clone(),
41+
}
42+
}
3643
}
3744

3845
impl Client {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::sync::Arc;
2+
3+
use bitwarden_state::repository::Repository;
4+
5+
use crate::Client;
6+
7+
/// Wrapper for state specific functionality.
8+
pub struct StateClient {
9+
pub(crate) client: Client,
10+
}
11+
12+
impl StateClient {
13+
/// Register a client managed state repository for a specific type.
14+
pub fn register_repository<T: 'static + Repository<V>, V: 'static>(&self, store: Arc<T>) {
15+
self.client
16+
.internal
17+
.repository_map
18+
.write()
19+
.expect("RwLock is not poisoned")
20+
.insert(store);
21+
}
22+
23+
/// Get a client managed state repository for a specific type, if it exists.
24+
pub fn get_repository<T: 'static>(&self) -> Option<Arc<dyn Repository<T>>> {
25+
self.client
26+
.internal
27+
.repository_map
28+
.read()
29+
.expect("RwLock is not poisoned")
30+
.get()
31+
}
32+
}

crates/bitwarden-fido/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ keywords.workspace = true
1818
uniffi = ["dep:uniffi", "bitwarden-core/uniffi", "bitwarden-vault/uniffi"]
1919

2020
[dependencies]
21-
async-trait = ">=0.1.80, <0.2"
21+
async-trait = { workspace = true }
2222
base64 = ">=0.22.1, <0.23"
2323
bitwarden-core = { workspace = true }
2424
bitwarden-crypto = { workspace = true }

0 commit comments

Comments
 (0)