From 6353e06bd5af12ac52633691471ace627ecd7d60 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 27 Sep 2021 13:25:16 +0200 Subject: [PATCH] client-api: make ThirdpartyIdCredentials an owned type --- crates/ruma-client-api/CHANGELOG.md | 3 +++ crates/ruma-client-api/src/r0/uiaa.rs | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index 47c1e1e9..7abdb756 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -3,6 +3,9 @@ Breaking changes: * Use an enum for user-interactive auth stage type (used to be `&str` / `String`) +* Make `r0::uiaa::ThirdpartyIdCredentials` an owned type and remove its `Incoming` equivalent + * Previously, we had two fields of type `&'a [ThirdpartyIdCredentials<'a>]` and this kind of + nested borrowing can be very annoying Improvements: diff --git a/crates/ruma-client-api/src/r0/uiaa.rs b/crates/ruma-client-api/src/r0/uiaa.rs index bb0783fa..f57e2b30 100644 --- a/crates/ruma-client-api/src/r0/uiaa.rs +++ b/crates/ruma-client-api/src/r0/uiaa.rs @@ -333,7 +333,7 @@ impl<'a> OAuth2<'a> { pub struct EmailIdentity<'a> { /// Thirdparty identifier credentials. #[serde(rename = "threepidCreds")] - pub thirdparty_id_creds: &'a [ThirdpartyIdCredentials<'a>], + pub thirdparty_id_creds: &'a [ThirdpartyIdCredentials], /// The value of the session key given by the homeserver, if any. pub session: Option<&'a str>, @@ -350,7 +350,7 @@ pub struct EmailIdentity<'a> { pub struct Msisdn<'a> { /// Thirdparty identifier credentials. #[serde(rename = "threepidCreds")] - pub thirdparty_id_creds: &'a [ThirdpartyIdCredentials<'a>], + pub thirdparty_id_creds: &'a [ThirdpartyIdCredentials], /// The value of the session key given by the homeserver, if any. pub session: Option<&'a str>, @@ -478,30 +478,30 @@ pub enum UserIdentifier<'a> { } /// Credentials for thirdparty authentification (e.g. email / phone number). -#[derive(Clone, Debug, Outgoing, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ThirdpartyIdCredentials<'a> { +pub struct ThirdpartyIdCredentials { /// Identity server session ID. - pub sid: &'a SessionId, + pub sid: Box, /// Identity server client secret. - pub client_secret: &'a ClientSecret, + pub client_secret: Box, /// Identity server URL. - pub id_server: &'a str, + pub id_server: String, /// Identity server access token. - pub id_access_token: &'a str, + pub id_access_token: String, } -impl<'a> ThirdpartyIdCredentials<'a> { +impl ThirdpartyIdCredentials { /// Creates a new `ThirdpartyIdCredentials` with the given session ID, client secret, identity /// server address and access token. pub fn new( - sid: &'a SessionId, - client_secret: &'a ClientSecret, - id_server: &'a str, - id_access_token: &'a str, + sid: Box, + client_secret: Box, + id_server: String, + id_access_token: String, ) -> Self { Self { sid, client_secret, id_server, id_access_token } }