Borrow strings and identifiers in uiaa::AuthData and dependent endpoints

This commit is contained in:
Jonas Platte 2020-08-13 21:11:28 +02:00
parent a842c5ccdc
commit f210f91611
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
7 changed files with 33 additions and 33 deletions

View File

@ -2,7 +2,7 @@
use ruma_api::ruma_api;
use crate::r0::uiaa::{AuthData, UiaaResponse};
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
ruma_api! {
metadata: {
@ -29,7 +29,7 @@ ruma_api! {
pub logout_devices: bool,
/// Additional authentication information for the user-interactive authentication API.
pub auth: Option<AuthData>,
pub auth: Option<AuthData<'a>>,
}
response: {}

View File

@ -2,7 +2,7 @@
use ruma_api::ruma_api;
use crate::r0::uiaa::{AuthData, UiaaResponse};
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
use super::ThirdPartyIdRemovalStatus;
@ -19,12 +19,12 @@ ruma_api! {
request: {
/// Additional authentication information for the user-interactive authentication API.
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<AuthData>,
pub auth: Option<AuthData<'a>>,
/// Identity server from which to unbind the user's third party
/// identifier.
#[serde(skip_serializing_if = "Option::is_none")]
pub id_server: Option<String>,
pub id_server: Option<&'a str>,
}
response: {

View File

@ -4,7 +4,7 @@ use ruma_api::ruma_api;
use ruma_identifiers::{DeviceId, UserId};
use serde::{Deserialize, Serialize};
use crate::r0::uiaa::{AuthData, UiaaResponse};
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
ruma_api! {
metadata: {
@ -22,26 +22,26 @@ ruma_api! {
/// May be empty for accounts that should not be able to log in again
/// with a password, e.g., for guest or application service accounts.
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
pub password: Option<&'a str>,
/// local part of the desired Matrix ID.
///
/// If omitted, the homeserver MUST generate a Matrix ID local part.
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
pub username: Option<&'a str>,
/// ID of the client device.
///
/// If this does not correspond to a known client device, a new device will be created.
/// The server will auto-generate a device_id if this is not specified.
#[serde(skip_serializing_if = "Option::is_none")]
pub device_id: Option<Box<DeviceId>>,
pub device_id: Option<&'a DeviceId>,
/// A display name to assign to the newly-created device.
///
/// Ignored if `device_id` corresponds to a known device.
#[serde(skip_serializing_if = "Option::is_none")]
pub initial_device_display_name: Option<String>,
pub initial_device_display_name: Option<&'a str>,
/// Additional authentication information for the user-interactive authentication API.
///
@ -50,7 +50,7 @@ ruma_api! {
/// It should be left empty, or omitted, unless an earlier call returned an response
/// with status code 401.
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<AuthData>,
pub auth: Option<AuthData<'a>>,
/// Kind of account to register
///

View File

@ -3,7 +3,7 @@
use ruma_api::ruma_api;
use ruma_identifiers::DeviceId;
use crate::r0::uiaa::{AuthData, UiaaResponse};
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
ruma_api! {
metadata: {
@ -18,11 +18,11 @@ ruma_api! {
request: {
/// The device to delete.
#[ruma_api(path)]
pub device_id: Box<DeviceId>,
pub device_id: &'a DeviceId,
/// Additional authentication information for the user-interactive authentication API.
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<AuthData>,
pub auth: Option<AuthData<'a>>,
}
response: {}

View File

@ -3,7 +3,7 @@
use ruma_api::ruma_api;
use ruma_identifiers::DeviceId;
use crate::r0::uiaa::{AuthData, UiaaResponse};
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
ruma_api! {
metadata: {
@ -17,11 +17,11 @@ ruma_api! {
request: {
/// List of devices to delete.
pub devices: Vec<Box<DeviceId>>,
pub devices: &'a [Box<DeviceId>],
/// Additional authentication information for the user-interactive authentication API.
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<AuthData>,
pub auth: Option<AuthData<'a>>,
}
response: {}

View File

@ -5,7 +5,7 @@ use std::{
fmt::{self, Display, Formatter},
};
use ruma_api::{error::ResponseDeserializationError, EndpointError};
use ruma_api::{error::ResponseDeserializationError, EndpointError, Outgoing};
use serde::{Deserialize, Serialize};
use serde_json::{
from_slice as from_json_slice, to_vec as to_json_vec, value::RawValue as RawJsonValue,
@ -15,19 +15,19 @@ use serde_json::{
use crate::error::{Error as MatrixError, ErrorBody};
/// Additional authentication information for the user-interactive authentication API.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Outgoing, Serialize)]
#[serde(untagged)]
pub enum AuthData {
pub enum AuthData<'a> {
/// Used for sending UIAA authentication requests to the homeserver directly
/// from the client.
DirectRequest {
/// The login type that the client is attempting to complete.
#[serde(rename = "type")]
kind: String,
kind: &'a str,
/// The value of the session key given by the homeserver.
#[serde(skip_serializing_if = "Option::is_none")]
session: Option<String>,
session: Option<&'a str>,
/// Parameters submitted for a particular authentication stage.
// FIXME: RawJsonValue doesn't work here, is that a bug?
@ -39,7 +39,7 @@ pub enum AuthData {
/// stage through the fallback method.
FallbackAcknowledgement {
/// The value of the session key given by the homeserver.
session: String,
session: &'a str,
},
}
@ -145,14 +145,14 @@ mod tests {
Value as JsonValue,
};
use super::{AuthData, AuthFlow, UiaaInfo, UiaaResponse};
use super::{AuthData, AuthFlow, IncomingAuthData, UiaaInfo, UiaaResponse};
use crate::error::{ErrorBody, ErrorKind};
#[test]
fn test_serialize_authentication_data_direct_request() {
let authentication_data = AuthData::DirectRequest {
kind: "example.type.foo".into(),
session: Some("ZXY000".into()),
kind: "example.type.foo",
session: Some("ZXY000"),
auth_parameters: btreemap! {
"example_credential".to_owned() => json!("verypoorsharedsecret")
},
@ -177,8 +177,8 @@ mod tests {
});
assert_matches!(
from_json_value::<AuthData>(json).unwrap(),
AuthData::DirectRequest { kind, session: Some(session), auth_parameters }
from_json_value(json).unwrap(),
IncomingAuthData::DirectRequest { kind, session: Some(session), auth_parameters }
if kind == "example.type.foo"
&& session == "opaque_session_id"
&& auth_parameters == btreemap!{
@ -189,7 +189,7 @@ mod tests {
#[test]
fn test_serialize_authentication_data_fallback() {
let authentication_data = AuthData::FallbackAcknowledgement { session: "ZXY000".into() };
let authentication_data = AuthData::FallbackAcknowledgement { session: "ZXY000" };
assert_eq!(json!({ "session": "ZXY000" }), to_json_value(authentication_data).unwrap());
}
@ -199,8 +199,8 @@ mod tests {
let json = json!({ "session": "opaque_session_id" });
assert_matches!(
from_json_value::<AuthData>(json).unwrap(),
AuthData::FallbackAcknowledgement { session }
from_json_value(json).unwrap(),
IncomingAuthData::FallbackAcknowledgement { session }
if session == "opaque_session_id"
);
}

View File

@ -282,8 +282,8 @@ where
/// omitted from this request, the server will generate one.
pub async fn register_user(
&self,
username: Option<String>,
password: String,
username: Option<&str>,
password: &str,
) -> Result<Session, Error<ruma_client_api::r0::uiaa::UiaaResponse>> {
use ruma_client_api::r0::account::register;