diff --git a/Cargo.toml b/Cargo.toml index 568bde6a..9e1d003d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ mime = "0.3" minidom = "0.16" parking_lot = "0.12" pretty_assertions = "1.4" -secrecy = "0.8" +secrecy = "0.10" serde = "1.0" serde_json = "1.0" sha1 = "0.10" diff --git a/bindings/prose-sdk-ffi/src/client.rs b/bindings/prose-sdk-ffi/src/client.rs index cfb07de2..a44ef733 100644 --- a/bindings/prose-sdk-ffi/src/client.rs +++ b/bindings/prose-sdk-ffi/src/client.rs @@ -15,7 +15,7 @@ use prose_core_client::infra::encryption::{EncryptionKeysRepository, SessionRepo use prose_core_client::infra::general::OsRngProvider; use prose_core_client::{ open_store, Client as ProseClient, ClientDelegate as ProseClientDelegate, FsAvatarRepository, - PlatformDriver, Secret, SignalServiceHandle, + PlatformDriver, SignalServiceHandle, }; use prose_xmpp::{connector, ConnectionError}; @@ -85,7 +85,7 @@ impl Client { self.client() .await .map_err(|e| ConnectionError::Generic { msg: e.to_string() })? - .connect(&self.jid.to_bare().unwrap().into(), Secret::new(password)) + .connect(&self.jid.to_bare().unwrap().into(), password.into()) .await?; Ok(()) } diff --git a/bindings/prose-sdk-js/src/client.rs b/bindings/prose-sdk-js/src/client.rs index bcfba661..20794a07 100644 --- a/bindings/prose-sdk-js/src/client.rs +++ b/bindings/prose-sdk-js/src/client.rs @@ -16,9 +16,7 @@ use wasm_bindgen::prelude::*; use prose_core_client::dtos::{MucId, SoftwareVersion, UserStatus}; use prose_core_client::infra::encryption::{EncryptionKeysRepository, SessionRepository}; -use prose_core_client::{ - open_store, Client as ProseClient, PlatformDriver, Secret, StoreAvatarRepository, -}; +use prose_core_client::{open_store, Client as ProseClient, PlatformDriver, StoreAvatarRepository}; use crate::connector::{Connector, ProseConnectionProvider}; use crate::delegate::{Delegate, JSDelegate}; @@ -208,9 +206,7 @@ impl Client { jid: &BareJid, password: &str, ) -> std::result::Result<(), ConnectionError> { - self.client - .connect(&jid.into(), Secret::new(password.to_string())) - .await?; + self.client.connect(&jid.into(), password.into()).await?; Ok(()) } diff --git a/bindings/prose-sdk-js/src/connector/strophe_js.rs b/bindings/prose-sdk-js/src/connector/strophe_js.rs index a0a432fb..fc808bd0 100644 --- a/bindings/prose-sdk-js/src/connector/strophe_js.rs +++ b/bindings/prose-sdk-js/src/connector/strophe_js.rs @@ -10,7 +10,7 @@ use anyhow::Result; use async_trait::async_trait; use jid::FullJid; use minidom::Element; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretString}; use thiserror::Error; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::spawn_local; @@ -96,7 +96,7 @@ impl ConnectorTrait for Connector { async fn connect( &self, jid: &FullJid, - password: Secret, + password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { let client = Rc::new(self.provider.provide_connection(self.config.clone())); diff --git a/crates/prose-core-client/src/app/services/connection_service.rs b/crates/prose-core-client/src/app/services/connection_service.rs index c7409c41..de93417c 100644 --- a/crates/prose-core-client/src/app/services/connection_service.rs +++ b/crates/prose-core-client/src/app/services/connection_service.rs @@ -4,7 +4,7 @@ // License: Mozilla Public License v2.0 (MPL v2.0) use chrono::{DateTime, Utc}; -use secrecy::Secret; +use secrecy::SecretString; use tracing::{error, info, warn}; use prose_proc_macros::InjectDependencies; @@ -60,7 +60,7 @@ impl ConnectionService { pub async fn connect( &self, user_id: &UserId, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError> { self.ctx.set_connection_state(ConnectionState::Connecting); self.offline_messages_repo.drain(); diff --git a/crates/prose-core-client/src/client.rs b/crates/prose-core-client/src/client.rs index 988d5f1a..b7aa91f6 100644 --- a/crates/prose-core-client/src/client.rs +++ b/crates/prose-core-client/src/client.rs @@ -7,7 +7,7 @@ use std::ops::Deref; use std::sync::Arc; use anyhow::Result; -use secrecy::Secret; +use secrecy::SecretString; use crate::app::deps::DynAppContext; use prose_wasm_utils::{SendUnlessWasm, SyncUnlessWasm}; @@ -74,7 +74,7 @@ impl Client { pub async fn connect( &self, id: &UserId, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError> { self.connection.connect(id, password).await } diff --git a/crates/prose-core-client/src/domain/connection/services/connection_service.rs b/crates/prose-core-client/src/domain/connection/services/connection_service.rs index 3d0dfb01..a126d7eb 100644 --- a/crates/prose-core-client/src/domain/connection/services/connection_service.rs +++ b/crates/prose-core-client/src/domain/connection/services/connection_service.rs @@ -5,7 +5,7 @@ use anyhow::Result; use async_trait::async_trait; -use secrecy::Secret; +use secrecy::SecretString; use prose_wasm_utils::{SendUnlessWasm, SyncUnlessWasm}; use prose_xmpp::ConnectionError; @@ -20,7 +20,7 @@ pub trait ConnectionService: SendUnlessWasm + SyncUnlessWasm { async fn connect( &self, jid: &UserResourceId, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError>; async fn disconnect(&self); diff --git a/crates/prose-core-client/src/infra/connection/connection_service.rs b/crates/prose-core-client/src/infra/connection/connection_service.rs index 361e144a..f1595cea 100644 --- a/crates/prose-core-client/src/infra/connection/connection_service.rs +++ b/crates/prose-core-client/src/infra/connection/connection_service.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Result}; use async_trait::async_trait; use chrono::Utc; -use secrecy::Secret; +use secrecy::SecretString; use tracing::{info, warn}; use prose_xmpp::{mods, ns, ConnectionError}; @@ -23,7 +23,7 @@ impl ConnectionService for XMPPClient { async fn connect( &self, jid: &UserResourceId, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError> { self.client.connect(jid.as_ref(), password).await } diff --git a/crates/prose-core-client/src/lib.rs b/crates/prose-core-client/src/lib.rs index 07ddd5ac..6f8c63d9 100644 --- a/crates/prose-core-client/src/lib.rs +++ b/crates/prose-core-client/src/lib.rs @@ -5,7 +5,7 @@ extern crate core; -pub use secrecy::Secret; +pub use secrecy::SecretString; pub use app::deps::{DynEncryptionKeysRepository, DynSessionRepository}; pub use app::{dtos, services}; diff --git a/crates/prose-core-client/tests/connection_service.rs b/crates/prose-core-client/tests/connection_service.rs index 4b3692f9..1fb1aeed 100644 --- a/crates/prose-core-client/tests/connection_service.rs +++ b/crates/prose-core-client/tests/connection_service.rs @@ -7,7 +7,7 @@ use std::sync::{Arc, OnceLock}; use anyhow::Result; use mockall::predicate; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretString}; use prose_core_client::app::deps::DynAppContext; use prose_core_client::app::services::ConnectionService; @@ -65,7 +65,7 @@ async fn test_starts_available_and_generates_resource() -> Result<()> { .once() .with( predicate::eq(user_resource_id!("jane.doe@prose.org/resource-id")), - predicate::function(|pw: &Secret| pw.expose_secret().as_str() == "my-password"), + predicate::function(|pw: &SecretString| pw.expose_secret() == "my-password"), ) .return_once(|_, _| Box::pin(async { Ok(Default::default()) })); deps.contact_list_domain_service @@ -138,10 +138,7 @@ async fn test_starts_available_and_generates_resource() -> Result<()> { assert!(deps.ctx.muc_service().is_err()); service - .connect( - &user_id!("jane.doe@prose.org"), - Secret::new("my-password".to_string()), - ) + .connect(&user_id!("jane.doe@prose.org"), "my-password".into()) .await?; assert_eq!( @@ -268,10 +265,7 @@ async fn test_restores_availability_and_resource() -> Result<()> { let service = ConnectionService::from(&deps); service - .connect( - &user_id!("jane.doe@prose.org"), - Secret::new("my-password".to_string()), - ) + .connect(&user_id!("jane.doe@prose.org"), "my-password".into()) .await?; Ok(()) @@ -325,10 +319,7 @@ async fn test_connection_failure() -> Result<()> { assert!(deps.ctx.muc_service().is_err()); assert!(service - .connect( - &user_id!("jane.doe@prose.org"), - Secret::new("my-password".to_string()) - ) + .connect(&user_id!("jane.doe@prose.org"), "my-password".into()) .await .is_err()); diff --git a/crates/prose-xmpp/src/client/builder.rs b/crates/prose-xmpp/src/client/builder.rs index 55bb0b01..b72796b9 100644 --- a/crates/prose-xmpp/src/client/builder.rs +++ b/crates/prose-xmpp/src/client/builder.rs @@ -13,7 +13,7 @@ use jid::FullJid; use minidom::Element; use parking_lot::RwLock; use prose_wasm_utils::{PinnedFuture, SendUnlessWasm, SyncUnlessWasm}; -use secrecy::Secret; +use secrecy::SecretString; use crate::client::client::ClientInner; use crate::client::module_context::ModuleContextInner; @@ -147,7 +147,7 @@ impl Connector for UndefinedConnector { async fn connect( &self, _jid: &FullJid, - _password: Secret, + _password: SecretString, _event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { panic!("Client doesn't have a connector. Provide one before calling connect()") diff --git a/crates/prose-xmpp/src/client/client.rs b/crates/prose-xmpp/src/client/client.rs index 08257604..e7f97a76 100644 --- a/crates/prose-xmpp/src/client/client.rs +++ b/crates/prose-xmpp/src/client/client.rs @@ -13,7 +13,7 @@ use std::time::{Duration, SystemTime}; use anyhow::Result; use jid::FullJid; use minidom::Element; -use secrecy::Secret; +use secrecy::SecretString; use tracing::{error, warn}; use prose_wasm_utils::PinnedFuture; @@ -46,7 +46,7 @@ impl Client { pub async fn connect( &self, jid: &FullJid, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError> { self.inner.clone().connect(jid, password).await } @@ -79,7 +79,7 @@ impl ClientInner { async fn connect( self: Arc, jid: &FullJid, - password: Secret, + password: SecretString, ) -> Result<(), ConnectionError> { self.disconnect(); diff --git a/crates/prose-xmpp/src/connector/connector.rs b/crates/prose-xmpp/src/connector/connector.rs index 12aff4f0..27c248a1 100644 --- a/crates/prose-xmpp/src/connector/connector.rs +++ b/crates/prose-xmpp/src/connector/connector.rs @@ -8,7 +8,7 @@ use async_trait::async_trait; use jid::FullJid; use minidom::Element; use prose_wasm_utils::{PinnedFuture, SendUnlessWasm, SyncUnlessWasm}; -use secrecy::Secret; +use secrecy::SecretString; #[derive(Debug, thiserror::Error, Clone, PartialEq)] pub enum ConnectionError { @@ -33,7 +33,7 @@ pub trait Connector: SendUnlessWasm + SyncUnlessWasm { async fn connect( &self, jid: &FullJid, - password: Secret, + password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError>; } diff --git a/crates/prose-xmpp/src/connector/proxy_connector.rs b/crates/prose-xmpp/src/connector/proxy_connector.rs index 43700110..e46d716d 100644 --- a/crates/prose-xmpp/src/connector/proxy_connector.rs +++ b/crates/prose-xmpp/src/connector/proxy_connector.rs @@ -9,7 +9,7 @@ use anyhow::Result; use async_trait::async_trait; use jid::FullJid; use minidom::Element; -use secrecy::Secret; +use secrecy::SecretString; use prose_wasm_utils::{spawn, SendUnlessWasm, SyncUnlessWasm}; @@ -50,7 +50,7 @@ impl Connector async fn connect( &self, jid: &FullJid, - password: Secret, + password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { let orig_event_handler = Arc::new(event_handler); diff --git a/crates/prose-xmpp/src/connector/xmpp_rs.rs b/crates/prose-xmpp/src/connector/xmpp_rs.rs index d87232ff..a7576664 100644 --- a/crates/prose-xmpp/src/connector/xmpp_rs.rs +++ b/crates/prose-xmpp/src/connector/xmpp_rs.rs @@ -12,7 +12,7 @@ use futures::stream::StreamExt; use futures::SinkExt; use jid::FullJid; use minidom::Element; -use secrecy::{ExposeSecret, Secret}; +use secrecy::{ExposeSecret, SecretString}; use tokio::sync::mpsc; use tokio::sync::mpsc::UnboundedSender; use tokio::task::JoinHandle; @@ -40,12 +40,12 @@ impl ConnectorTrait for Connector { async fn connect( &self, jid: &FullJid, - password: Secret, + password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { async fn connect( jid: &FullJid, - password: Secret, + password: SecretString, ) -> Result, ConnectionError> { let mut client = AsyncClient::new(jid.clone(), password.expose_secret()); client.set_reconnect(false); diff --git a/crates/prose-xmpp/src/lib.rs b/crates/prose-xmpp/src/lib.rs index 1e1928bf..d9910570 100644 --- a/crates/prose-xmpp/src/lib.rs +++ b/crates/prose-xmpp/src/lib.rs @@ -4,7 +4,7 @@ // License: Mozilla Public License v2.0 (MPL v2.0) pub use jid::{BareJid, FullJid, Jid}; -pub use secrecy::Secret; +pub use secrecy::SecretString; pub use client::{Client, ClientBuilder}; pub use connector::{Connection, ConnectionError, Connector}; diff --git a/crates/prose-xmpp/src/test/connected_client.rs b/crates/prose-xmpp/src/test/connected_client.rs index 87705df9..df2d5907 100644 --- a/crates/prose-xmpp/src/test/connected_client.rs +++ b/crates/prose-xmpp/src/test/connected_client.rs @@ -10,7 +10,6 @@ use anyhow::Result; use async_trait::async_trait; use jid::{BareJid, FullJid}; use parking_lot::RwLock; -use secrecy::Secret; use crate::test::{BareJidTestAdditions, Connection, Connector, IncrementingIDProvider}; use crate::{Client, Event, IDProvider}; @@ -52,7 +51,7 @@ impl ClientTestAdditions for Client { })) .build(); - client.connect(&jid, Secret::new("".to_string())).await?; + client.connect(&jid, "".into()).await?; id_provider.reset(); sent_events.write().clear(); diff --git a/crates/prose-xmpp/src/test/connector.rs b/crates/prose-xmpp/src/test/connector.rs index 50c94dbc..e7857210 100644 --- a/crates/prose-xmpp/src/test/connector.rs +++ b/crates/prose-xmpp/src/test/connector.rs @@ -10,7 +10,7 @@ use async_trait::async_trait; use jid::FullJid; use minidom::Element; use parking_lot::{Mutex, RwLock}; -use secrecy::Secret; +use secrecy::SecretString; use xmpp_parsers::disco::DiscoItemsResult; use xmpp_parsers::iq::Iq; @@ -39,7 +39,7 @@ impl ConnectorTrait for Connector { async fn connect( &self, _jid: &FullJid, - _password: Secret, + _password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { *self.connection.inner.event_handler.write() = Some(event_handler); diff --git a/examples/prose-core-client-cli/src/main.rs b/examples/prose-core-client-cli/src/main.rs index 105fd864..d1958a26 100644 --- a/examples/prose-core-client-cli/src/main.rs +++ b/examples/prose-core-client-cli/src/main.rs @@ -35,7 +35,7 @@ use prose_core_client::{ open_store, Client, ClientDelegate, ClientEvent, ClientRoomEventType, PlatformDriver, SignalServiceHandle, }; -use prose_xmpp::{connector, mods, Secret}; +use prose_xmpp::{connector, mods}; use crate::type_display::{ ConnectedRoomEnvelope, DeviceInfoEnvelope, JidWithName, MessageEnvelope, ParticipantEnvelope, @@ -78,7 +78,7 @@ async fn configure_client() -> Result<(BareJid, Client)> { println!("Connecting to server as {}…", jid); client - .connect(&UserId::from(jid.to_bare()), Secret::new(password)) + .connect(&UserId::from(jid.to_bare()), password.into()) .await?; println!("Connected."); diff --git a/examples/xmpp-client/src/main.rs b/examples/xmpp-client/src/main.rs index d14c8ecf..6beca900 100644 --- a/examples/xmpp-client/src/main.rs +++ b/examples/xmpp-client/src/main.rs @@ -10,7 +10,7 @@ use tracing::info; use common::{enable_debug_logging, load_credentials, Level}; use prose_xmpp::mods::{chat, Chat, Profile, Status}; use prose_xmpp::stanza::presence::Show; -use prose_xmpp::{connector, Client, Event, Secret}; +use prose_xmpp::{connector, Client, Event}; // This example starts a XMPP client and listens for messages. If a message is received it loads // the sender's vCard and response with a greeting and some text. @@ -27,7 +27,7 @@ async fn main() -> Result<()> { let (jid, password) = load_credentials(); info!("Connecting…"); - client.connect(&jid, Secret::new(password)).await?; + client.connect(&jid, password.into()).await?; info!("Connected."); client diff --git a/tests/prose-core-integration-tests/src/tests/client/helpers/connector.rs b/tests/prose-core-integration-tests/src/tests/client/helpers/connector.rs index b764b57b..59858c5a 100644 --- a/tests/prose-core-integration-tests/src/tests/client/helpers/connector.rs +++ b/tests/prose-core-integration-tests/src/tests/client/helpers/connector.rs @@ -13,7 +13,7 @@ use parking_lot::Mutex; use pretty_assertions::assert_eq; use crate::tests::client::helpers::test_message_queue::MessageType; -use prose_core_client::Secret; +use prose_core_client::SecretString; use prose_xmpp::client::ConnectorProvider; use prose_xmpp::connector::{ Connection as ConnectionTrait, ConnectionError, ConnectionEvent, ConnectionEventHandler, @@ -99,7 +99,7 @@ impl ConnectorTrait for Connector { async fn connect( &self, _jid: &FullJid, - _password: Secret, + _password: SecretString, event_handler: ConnectionEventHandler, ) -> Result, ConnectionError> { let connection = Connection { diff --git a/tests/prose-core-integration-tests/src/tests/client/helpers/test_client_login.rs b/tests/prose-core-integration-tests/src/tests/client/helpers/test_client_login.rs index 470790b0..a950c43f 100644 --- a/tests/prose-core-integration-tests/src/tests/client/helpers/test_client_login.rs +++ b/tests/prose-core-integration-tests/src/tests/client/helpers/test_client_login.rs @@ -11,7 +11,7 @@ use xmpp_parsers::roster::Item as RosterItem; use prose_core_client::domain::user_info::models::UserProfile; use prose_core_client::dtos::{Bookmark, DeviceBundle, DeviceId, UserId}; -use prose_core_client::{ClientEvent, ConnectionEvent, Secret}; +use prose_core_client::{ClientEvent, ConnectionEvent}; use prose_xmpp::stanza::vcard4::Nickname; use prose_xmpp::stanza::VCard4; use prose_xmpp::IDProvider; @@ -201,8 +201,7 @@ impl TestClient { event!(self, ClientEvent::AccountInfoChanged); - self.connect(&user, Secret::new(password.as_ref().to_string())) - .await?; + self.connect(&user, password.as_ref().into()).await?; if let Some(vcard) = strategy.user_vcard { self.push_ctx([("VCARD", String::from(&Element::from(vcard)))]);