Skip to content

Commit

Permalink
chore: Bump secrecy (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiBardon authored Dec 16, 2024
1 parent ca86578 commit a2a1b8b
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions bindings/prose-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
}
Expand Down
8 changes: 2 additions & 6 deletions bindings/prose-sdk-js/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}

Expand Down
4 changes: 2 additions & 2 deletions bindings/prose-sdk-js/src/connector/strophe_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl ConnectorTrait for Connector {
async fn connect(
&self,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
event_handler: ConnectionEventHandler,
) -> Result<Box<dyn ConnectionTrait>, ConnectionError> {
let client = Rc::new(self.provider.provide_connection(self.config.clone()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl ConnectionService {
pub async fn connect(
&self,
user_id: &UserId,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError> {
self.ctx.set_connection_state(ConnectionState::Connecting);
self.offline_messages_repo.drain();
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-core-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Client {
pub async fn connect(
&self,
id: &UserId,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError> {
self.connection.connect(id, password).await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +20,7 @@ pub trait ConnectionService: SendUnlessWasm + SyncUnlessWasm {
async fn connect(
&self,
jid: &UserResourceId,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError>;
async fn disconnect(&self);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -23,7 +23,7 @@ impl ConnectionService for XMPPClient {
async fn connect(
&self,
jid: &UserResourceId,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError> {
self.client.connect(jid.as_ref(), password).await
}
Expand Down
2 changes: 1 addition & 1 deletion crates/prose-core-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
19 changes: 5 additions & 14 deletions crates/prose-core-client/tests/connection_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>| 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
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Connector for UndefinedConnector {
async fn connect(
&self,
_jid: &FullJid,
_password: Secret<String>,
_password: SecretString,
_event_handler: ConnectionEventHandler,
) -> Result<Box<dyn Connection>, ConnectionError> {
panic!("Client doesn't have a connector. Provide one before calling connect()")
Expand Down
6 changes: 3 additions & 3 deletions crates/prose-xmpp/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Client {
pub async fn connect(
&self,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError> {
self.inner.clone().connect(jid, password).await
}
Expand Down Expand Up @@ -79,7 +79,7 @@ impl ClientInner {
async fn connect(
self: Arc<Self>,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
) -> Result<(), ConnectionError> {
self.disconnect();

Expand Down
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/connector/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,7 +33,7 @@ pub trait Connector: SendUnlessWasm + SyncUnlessWasm {
async fn connect(
&self,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
event_handler: ConnectionEventHandler,
) -> Result<Box<dyn Connection>, ConnectionError>;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/connector/proxy_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -50,7 +50,7 @@ impl<C: Connector, T: ProxyTransformer + SendUnlessWasm + 'static> Connector
async fn connect(
&self,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
event_handler: ConnectionEventHandler,
) -> Result<Box<dyn Connection>, ConnectionError> {
let orig_event_handler = Arc::new(event_handler);
Expand Down
6 changes: 3 additions & 3 deletions crates/prose-xmpp/src/connector/xmpp_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,12 +40,12 @@ impl ConnectorTrait for Connector {
async fn connect(
&self,
jid: &FullJid,
password: Secret<String>,
password: SecretString,
event_handler: ConnectionEventHandler,
) -> Result<Box<dyn ConnectionTrait>, ConnectionError> {
async fn connect(
jid: &FullJid,
password: Secret<String>,
password: SecretString,
) -> Result<AsyncClient<ServerConfig>, ConnectionError> {
let mut client = AsyncClient::new(jid.clone(), password.expose_secret());
client.set_reconnect(false);
Expand Down
2 changes: 1 addition & 1 deletion crates/prose-xmpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions crates/prose-xmpp/src/test/connected_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/test/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -39,7 +39,7 @@ impl ConnectorTrait for Connector {
async fn connect(
&self,
_jid: &FullJid,
_password: Secret<String>,
_password: SecretString,
event_handler: ConnectionEventHandler,
) -> Result<Box<dyn ConnectionTrait>, ConnectionError> {
*self.connection.inner.event_handler.write() = Some(event_handler);
Expand Down
4 changes: 2 additions & 2 deletions examples/prose-core-client-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.");

Expand Down
4 changes: 2 additions & 2 deletions examples/xmpp-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Loading

0 comments on commit a2a1b8b

Please sign in to comment.