Add client secret and session ID types
This commit is contained in:
parent
ef96b0f381
commit
2577225ba5
@ -1,6 +1,7 @@
|
|||||||
//! [POST /_matrix/client/r0/account/3pid/add](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-add)
|
//! [POST /_matrix/client/r0/account/3pid/add](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-account-3pid-add)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
use crate::r0::uiaa::{AuthData, IncomingAuthData, UiaaResponse};
|
||||||
|
|
||||||
@ -20,10 +21,10 @@ ruma_api! {
|
|||||||
pub auth: Option<AuthData<'a>>,
|
pub auth: Option<AuthData<'a>>,
|
||||||
|
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -34,7 +35,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given client secret and session identifier.
|
/// Creates a new `Request` with the given client secret and session identifier.
|
||||||
pub fn new(client_secret: &'a str, sid: &'a str) -> Self {
|
pub fn new(client_secret: &'a ClientSecret, sid: &'a SessionId) -> Self {
|
||||||
Self { auth: None, client_secret, sid }
|
Self { auth: None, client_secret, sid }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! [POST /_matrix/client/r0/account/3pid/bind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind)
|
//! [POST /_matrix/client/r0/account/3pid/bind](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-3pid-bind)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The ID server to send the onward request to as a hostname with an
|
/// The ID server to send the onward request to as a hostname with an
|
||||||
/// appended colon and port number if the port is not the default.
|
/// appended colon and port number if the port is not the default.
|
||||||
@ -24,7 +25,7 @@ ruma_api! {
|
|||||||
pub identity_server_info: IdentityServerInfo<'a>,
|
pub identity_server_info: IdentityServerInfo<'a>,
|
||||||
|
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -37,9 +38,9 @@ impl<'a> Request<'a> {
|
|||||||
/// Creates a new `Request` with the given client secret, identity server information and
|
/// Creates a new `Request` with the given client secret, identity server information and
|
||||||
/// session identifier.
|
/// session identifier.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
identity_server_info: IdentityServerInfo<'a>,
|
identity_server_info: IdentityServerInfo<'a>,
|
||||||
sid: &'a str,
|
sid: &'a SessionId,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { client_secret, identity_server_info, sid }
|
Self { client_secret, identity_server_info, sid }
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The email address.
|
/// The email address.
|
||||||
pub email: &'a str,
|
pub email: &'a str,
|
||||||
@ -37,7 +38,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -56,14 +57,14 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the client secret, email and send-attempt counter.
|
/// Creates a new `Request` with the client secret, email and send-attempt counter.
|
||||||
pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self {
|
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// Two-letter ISO 3166 country code for the phone number.
|
/// Two-letter ISO 3166 country code for the phone number.
|
||||||
pub country: &'a str,
|
pub country: &'a str,
|
||||||
@ -40,7 +41,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -61,7 +62,7 @@ impl<'a> Request<'a> {
|
|||||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||||
/// send-attempt counter.
|
/// send-attempt counter.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
country: &'a str,
|
country: &'a str,
|
||||||
phone_number: &'a str,
|
phone_number: &'a str,
|
||||||
send_attempt: UInt,
|
send_attempt: UInt,
|
||||||
@ -79,7 +80,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The email address.
|
/// The email address.
|
||||||
pub email: &'a str,
|
pub email: &'a str,
|
||||||
@ -37,7 +38,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -57,14 +58,14 @@ ruma_api! {
|
|||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
||||||
/// counter.
|
/// counter.
|
||||||
pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self {
|
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,7 +16,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// Two-letter ISO 3166 country code for the phone number.
|
/// Two-letter ISO 3166 country code for the phone number.
|
||||||
pub country: &'a str,
|
pub country: &'a str,
|
||||||
@ -33,7 +34,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -54,7 +55,7 @@ impl<'a> Request<'a> {
|
|||||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||||
/// send-attempt counter.
|
/// send-attempt counter.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
country: &'a str,
|
country: &'a str,
|
||||||
phone_number: &'a str,
|
phone_number: &'a str,
|
||||||
send_attempt: UInt,
|
send_attempt: UInt,
|
||||||
@ -65,7 +66,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The email address.
|
/// The email address.
|
||||||
pub email: &'a str,
|
pub email: &'a str,
|
||||||
@ -37,7 +38,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -57,14 +58,14 @@ ruma_api! {
|
|||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
/// Creates a new `Request` with the given client secret, email address and send-attempt
|
||||||
/// counter.
|
/// counter.
|
||||||
pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self {
|
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||||
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
use super::{IdentityServerInfo, IncomingIdentityServerInfo};
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// Two-letter ISO 3166 country code for the phone number.
|
/// Two-letter ISO 3166 country code for the phone number.
|
||||||
pub country: &'a str,
|
pub country: &'a str,
|
||||||
@ -40,7 +41,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session identifier given by the identity server.
|
/// The session identifier given by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
|
|
||||||
/// URL to submit validation token to. If omitted, verification happens without client.
|
/// URL to submit validation token to. If omitted, verification happens without client.
|
||||||
///
|
///
|
||||||
@ -61,7 +62,7 @@ impl<'a> Request<'a> {
|
|||||||
/// Creates a new `Request` with the given client secret, country code, phone number and
|
/// Creates a new `Request` with the given client secret, country code, phone number and
|
||||||
/// send-attempt counter.
|
/// send-attempt counter.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
country: &'a str,
|
country: &'a str,
|
||||||
phone_number: &'a str,
|
phone_number: &'a str,
|
||||||
send_attempt: UInt,
|
send_attempt: UInt,
|
||||||
@ -79,7 +80,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Creates a new `Response` with the given session identifier.
|
/// Creates a new `Response` with the given session identifier.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid, submit_url: None }
|
Self { sid, submit_url: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::ClientSecret;
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,7 +16,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// Client-generated secret string used to protect this session.
|
/// Client-generated secret string used to protect this session.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The email address.
|
/// The email address.
|
||||||
pub email: &'a str,
|
pub email: &'a str,
|
||||||
@ -49,7 +50,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a new `Request` with the given client secret, email and send-attempt counter.
|
/// Creates a new `Request` with the given client secret, email and send-attempt counter.
|
||||||
pub fn new(client_secret: &'a str, email: &'a str, send_attempt: UInt) -> Self {
|
pub fn new(client_secret: &'a ClientSecret, email: &'a str, send_attempt: UInt) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client_secret,
|
client_secret,
|
||||||
email,
|
email,
|
||||||
|
13
crates/ruma-identifiers-validation/src/client_secret.rs
Normal file
13
crates/ruma-identifiers-validation/src/client_secret.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
pub fn validate(s: &str) -> Result<(), Error> {
|
||||||
|
if s.len() > 255 {
|
||||||
|
return Err(Error::MaximumLengthExceeded);
|
||||||
|
} else if !s.chars().all(|c| c.is_alphanumeric() || ".=_-".contains(c)) {
|
||||||
|
return Err(Error::InvalidCharacters);
|
||||||
|
} else if s.is_empty() {
|
||||||
|
return Err(Error::EmptyClientSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -5,6 +5,9 @@ use std::fmt;
|
|||||||
/// An error encountered when trying to parse an invalid ID string.
|
/// An error encountered when trying to parse an invalid ID string.
|
||||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
/// The client secret is empty.
|
||||||
|
EmptyClientSecret,
|
||||||
|
|
||||||
/// The room version ID is empty.
|
/// The room version ID is empty.
|
||||||
EmptyRoomVersionId,
|
EmptyRoomVersionId,
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ pub enum Error {
|
|||||||
impl fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let message = match self {
|
let message = match self {
|
||||||
|
Error::EmptyClientSecret => "client secret is empty",
|
||||||
Error::EmptyRoomVersionId => "room version ID is empty",
|
Error::EmptyRoomVersionId => "room version ID is empty",
|
||||||
Error::InvalidCharacters => "localpart contains invalid characters",
|
Error::InvalidCharacters => "localpart contains invalid characters",
|
||||||
Error::InvalidKeyAlgorithm => "invalid key algorithm specified",
|
Error::InvalidKeyAlgorithm => "invalid key algorithm specified",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#![doc(html_favicon_url = "https://www.ruma.io/favicon.ico")]
|
#![doc(html_favicon_url = "https://www.ruma.io/favicon.ico")]
|
||||||
#![doc(html_logo_url = "https://www.ruma.io/images/logo.png")]
|
#![doc(html_logo_url = "https://www.ruma.io/images/logo.png")]
|
||||||
|
|
||||||
|
pub mod client_secret;
|
||||||
pub mod device_key_id;
|
pub mod device_key_id;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod event_id;
|
pub mod event_id;
|
||||||
@ -11,6 +12,7 @@ pub mod room_id;
|
|||||||
pub mod room_id_or_alias_id;
|
pub mod room_id_or_alias_id;
|
||||||
pub mod room_version_id;
|
pub mod room_version_id;
|
||||||
pub mod server_name;
|
pub mod server_name;
|
||||||
|
pub mod session_id;
|
||||||
pub mod user_id;
|
pub mod user_id;
|
||||||
|
|
||||||
use std::num::NonZeroU8;
|
use std::num::NonZeroU8;
|
||||||
|
13
crates/ruma-identifiers-validation/src/session_id.rs
Normal file
13
crates/ruma-identifiers-validation/src/session_id.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use crate::Error;
|
||||||
|
|
||||||
|
pub fn validate(s: &str) -> Result<(), Error> {
|
||||||
|
if s.len() > 255 {
|
||||||
|
return Err(Error::MaximumLengthExceeded);
|
||||||
|
} else if !s.chars().all(|c| c.is_alphanumeric() || ".=_-".contains(c)) {
|
||||||
|
return Err(Error::InvalidCharacters);
|
||||||
|
} else if s.is_empty() {
|
||||||
|
return Err(Error::EmptyClientSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
23
crates/ruma-identifiers/src/client_secret.rs
Normal file
23
crates/ruma-identifiers/src/client_secret.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//! Client secret identifier.
|
||||||
|
|
||||||
|
use ruma_identifiers_validation::client_secret::validate;
|
||||||
|
|
||||||
|
opaque_identifier_validated! {
|
||||||
|
/// A client secret.
|
||||||
|
///
|
||||||
|
/// Client secrets in Matrix are opaque character sequences of `[0-9a-zA-Z.=_-]`. Their length must
|
||||||
|
/// must not exceed 255 characters.
|
||||||
|
pub type ClientSecret [ validate ];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use super::ClientSecret;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn valid_secret() {
|
||||||
|
assert!(<&ClientSecret>::try_from("this_=_a_valid_secret_1337").is_ok())
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ use serde::de::{self, Deserializer, Unexpected};
|
|||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
|
client_secret::{ClientSecret, ClientSecretBox},
|
||||||
crypto_algorithms::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, SigningKeyAlgorithm},
|
crypto_algorithms::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, SigningKeyAlgorithm},
|
||||||
device_key_id::DeviceKeyId,
|
device_key_id::DeviceKeyId,
|
||||||
event_id::EventId,
|
event_id::EventId,
|
||||||
@ -31,6 +32,7 @@ pub use crate::{
|
|||||||
room_id_or_room_alias_id::RoomIdOrAliasId,
|
room_id_or_room_alias_id::RoomIdOrAliasId,
|
||||||
room_version_id::RoomVersionId,
|
room_version_id::RoomVersionId,
|
||||||
server_name::{ServerName, ServerNameBox},
|
server_name::{ServerName, ServerNameBox},
|
||||||
|
session_id::{SessionId, SessionIdBox},
|
||||||
signatures::{DeviceSignatures, EntitySignatures, ServerSignatures, Signatures},
|
signatures::{DeviceSignatures, EntitySignatures, ServerSignatures, Signatures},
|
||||||
user_id::UserId,
|
user_id::UserId,
|
||||||
};
|
};
|
||||||
@ -42,6 +44,7 @@ mod macros;
|
|||||||
|
|
||||||
pub mod user_id;
|
pub mod user_id;
|
||||||
|
|
||||||
|
mod client_secret;
|
||||||
mod crypto_algorithms;
|
mod crypto_algorithms;
|
||||||
mod device_key_id;
|
mod device_key_id;
|
||||||
mod event_id;
|
mod event_id;
|
||||||
@ -53,6 +56,7 @@ mod room_id;
|
|||||||
mod room_id_or_room_alias_id;
|
mod room_id_or_room_alias_id;
|
||||||
mod room_version_id;
|
mod room_version_id;
|
||||||
mod server_name;
|
mod server_name;
|
||||||
|
mod session_id;
|
||||||
mod signatures;
|
mod signatures;
|
||||||
|
|
||||||
/// Check whether a given string is a valid server name according to [the specification][].
|
/// Check whether a given string is a valid server name according to [the specification][].
|
||||||
|
@ -288,3 +288,172 @@ macro_rules! opaque_identifier {
|
|||||||
partial_eq_string!(Box<$id>);
|
partial_eq_string!(Box<$id>);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! opaque_identifier_validated {
|
||||||
|
(
|
||||||
|
$( #[doc = $docs:literal] )*
|
||||||
|
$vis:vis type $id:ident [ $validate_id:ident ];
|
||||||
|
) => {
|
||||||
|
$( #[doc = $docs] )*
|
||||||
|
#[repr(transparent)]
|
||||||
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent, crate = "serde"))]
|
||||||
|
pub struct $id(str);
|
||||||
|
|
||||||
|
paste::paste! {
|
||||||
|
doc_concat! {
|
||||||
|
#[doc = concat!("An owned [", stringify!($id), "].")]
|
||||||
|
pub type [<$id Box>] = Box<$id>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $id {
|
||||||
|
#[allow(clippy::transmute_ptr_to_ptr)]
|
||||||
|
fn from_borrowed(s: &str) -> &Self {
|
||||||
|
unsafe { std::mem::transmute(s) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn from_owned(s: Box<str>) -> Box<Self> {
|
||||||
|
unsafe { Box::from_raw(Box::into_raw(s) as _) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_owned(self: Box<Self>) -> Box<str> {
|
||||||
|
unsafe { Box::from_raw(Box::into_raw(self) as _) }
|
||||||
|
}
|
||||||
|
|
||||||
|
doc_concat! {
|
||||||
|
#[doc = concat!("Creates a string slice from this `", stringify!($id), "`.")]
|
||||||
|
pub fn as_str(&self) -> &str {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc_concat! {
|
||||||
|
#[doc = concat!("Creates a byte slice from this `", stringify!($id), "`.")]
|
||||||
|
pub fn as_bytes(&self) -> &[u8] {
|
||||||
|
self.0.as_bytes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for $id {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(self.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for Box<$id> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
(**self).to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToOwned for $id {
|
||||||
|
type Owned = Box<$id>;
|
||||||
|
|
||||||
|
fn to_owned(&self) -> Self::Owned {
|
||||||
|
Self::from_owned(self.0.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&$id> for Box<$id> {
|
||||||
|
fn from(id: &$id) -> Self {
|
||||||
|
id.to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for $id {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.as_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AsRef<str> for Box<$id> {
|
||||||
|
fn as_ref(&self) -> &str {
|
||||||
|
self.as_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&$id> for std::rc::Rc<$id> {
|
||||||
|
fn from(s: &$id) -> std::rc::Rc<$id> {
|
||||||
|
let rc = std::rc::Rc::<str>::from(s.as_str());
|
||||||
|
unsafe { std::rc::Rc::from_raw(std::rc::Rc::into_raw(rc) as *const $id) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&$id> for std::sync::Arc<$id> {
|
||||||
|
fn from(s: &$id) -> std::sync::Arc<$id> {
|
||||||
|
let arc = std::sync::Arc::<str>::from(s.as_str());
|
||||||
|
unsafe { std::sync::Arc::from_raw(std::sync::Arc::into_raw(arc) as *const $id) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
impl From<Box<$id>> for String {
|
||||||
|
fn from(id: Box<$id>) -> Self {
|
||||||
|
id.into_owned().into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
impl<'de> serde::Deserialize<'de> for Box<$id> {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
Box::<str>::deserialize(deserializer).map($id::from_owned)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_from<S>(s: S) -> Result<Box<$id>, crate::Error>
|
||||||
|
where
|
||||||
|
S: AsRef<str> + Into<Box<str>>,
|
||||||
|
{
|
||||||
|
$validate_id(s.as_ref())?;
|
||||||
|
Ok($id::from_owned(s.into()))
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> std::convert::TryFrom<&'a str> for &'a $id {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
|
||||||
|
$validate_id(s)?;
|
||||||
|
Ok($id::from_borrowed(s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::str::FromStr for Box<$id> {
|
||||||
|
type Err = crate::Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::convert::TryFrom<&str> for Box<$id> {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||||
|
try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::convert::TryFrom<String> for Box<$id> {
|
||||||
|
type Error = crate::Error;
|
||||||
|
|
||||||
|
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||||
|
try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for $id {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.as_str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
partial_eq_string!($id);
|
||||||
|
partial_eq_string!(Box<$id>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,159 +1,12 @@
|
|||||||
//! Matrix-spec compliant server names.
|
//! Matrix-spec compliant server names.
|
||||||
use std::{convert::TryFrom, fmt, mem, rc::Rc, str::FromStr, sync::Arc};
|
|
||||||
|
|
||||||
use ruma_identifiers_validation::server_name::validate;
|
use ruma_identifiers_validation::server_name::validate;
|
||||||
|
|
||||||
/// A Matrix-spec compliant server name.
|
opaque_identifier_validated! {
|
||||||
#[repr(transparent)]
|
/// A Matrix-spec compliant server name.
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
pub type ServerName [ validate ];
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent, crate = "serde"))]
|
|
||||||
pub struct ServerName(str);
|
|
||||||
|
|
||||||
/// An owned server name.
|
|
||||||
pub type ServerNameBox = Box<ServerName>;
|
|
||||||
|
|
||||||
impl ServerName {
|
|
||||||
fn from_borrowed(s: &str) -> &Self {
|
|
||||||
unsafe { mem::transmute(s) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_owned(s: Box<str>) -> Box<Self> {
|
|
||||||
unsafe { Box::from_raw(Box::into_raw(s) as _) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn into_owned(self: Box<Self>) -> Box<str> {
|
|
||||||
unsafe { Box::from_raw(Box::into_raw(self) as _) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a string slice from this `ServerName`.
|
|
||||||
pub fn as_str(&self) -> &str {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a byte slice from this `ServerName`.
|
|
||||||
pub fn as_bytes(&self) -> &[u8] {
|
|
||||||
self.0.as_bytes()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ServerName {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str(self.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for Box<ServerName> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
(**self).to_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToOwned for ServerName {
|
|
||||||
type Owned = Box<ServerName>;
|
|
||||||
|
|
||||||
fn to_owned(&self) -> Self::Owned {
|
|
||||||
Self::from_owned(self.0.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ServerName> for Box<ServerName> {
|
|
||||||
fn from(s: &ServerName) -> Self {
|
|
||||||
s.to_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ServerName> for Rc<ServerName> {
|
|
||||||
fn from(s: &ServerName) -> Self {
|
|
||||||
let rc = Rc::<str>::from(s.as_str());
|
|
||||||
unsafe { Rc::from_raw(Rc::into_raw(rc) as *const ServerName) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&ServerName> for Arc<ServerName> {
|
|
||||||
fn from(s: &ServerName) -> Self {
|
|
||||||
let arc = Arc::<str>::from(s.as_str());
|
|
||||||
unsafe { Arc::from_raw(Arc::into_raw(arc) as *const ServerName) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_from<S>(server_name: S) -> Result<Box<ServerName>, crate::Error>
|
|
||||||
where
|
|
||||||
S: AsRef<str> + Into<Box<str>>,
|
|
||||||
{
|
|
||||||
validate(server_name.as_ref())?;
|
|
||||||
Ok(ServerName::from_owned(server_name.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<str> for ServerName {
|
|
||||||
fn as_ref(&self) -> &str {
|
|
||||||
self.as_str()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<str> for Box<ServerName> {
|
|
||||||
fn as_ref(&self) -> &str {
|
|
||||||
self.as_str()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Box<ServerName>> for String {
|
|
||||||
fn from(s: Box<ServerName>) -> Self {
|
|
||||||
s.into_owned().into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a str> for &'a ServerName {
|
|
||||||
type Error = crate::Error;
|
|
||||||
|
|
||||||
fn try_from(server_name: &'a str) -> Result<Self, Self::Error> {
|
|
||||||
validate(server_name)?;
|
|
||||||
Ok(ServerName::from_borrowed(server_name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for Box<ServerName> {
|
|
||||||
type Err = crate::Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
try_from(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&str> for Box<ServerName> {
|
|
||||||
type Error = crate::Error;
|
|
||||||
|
|
||||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
|
||||||
try_from(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<String> for Box<ServerName> {
|
|
||||||
type Error = crate::Error;
|
|
||||||
|
|
||||||
fn try_from(s: String) -> Result<Self, Self::Error> {
|
|
||||||
try_from(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for ServerName {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
impl<'de> serde::Deserialize<'de> for Box<ServerName> {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
crate::deserialize_id(deserializer, "An IP address or hostname")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
partial_eq_string!(ServerName);
|
|
||||||
partial_eq_string!(Box<ServerName>);
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
11
crates/ruma-identifiers/src/session_id.rs
Normal file
11
crates/ruma-identifiers/src/session_id.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
//! Matrix session ID.
|
||||||
|
|
||||||
|
use ruma_identifiers_validation::session_id::validate;
|
||||||
|
|
||||||
|
opaque_identifier_validated! {
|
||||||
|
/// A session ID.
|
||||||
|
///
|
||||||
|
/// Session IDs in Matrix are opaque character sequences of `[0-9a-zA-Z.=_-]`. Their length must
|
||||||
|
/// must not exceed 255 characters.
|
||||||
|
pub type SessionId [ validate ];
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::{thirdparty::Medium, MilliSecondsSinceUnixEpoch};
|
use ruma_common::{thirdparty::Medium, MilliSecondsSinceUnixEpoch};
|
||||||
use ruma_identifiers::{ServerSignatures, UserId};
|
use ruma_identifiers::{ClientSecret, ServerSignatures, SessionId, UserId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -16,10 +16,10 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The session ID generated by the `requestToken` call.
|
/// The session ID generated by the `requestToken` call.
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret passed to the `requestToken` call.
|
/// The client secret passed to the `requestToken` call.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The Matrix user ID to associate with the 3PIDs.
|
/// The Matrix user ID to associate with the 3PIDs.
|
||||||
pub mxid: &'a UserId,
|
pub mxid: &'a UserId,
|
||||||
@ -52,7 +52,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a `Request` with the given session ID, client secret and Matrix user ID.
|
/// Creates a `Request` with the given session ID, client secret and Matrix user ID.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str, mxid: &'a UserId) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, mxid: &'a UserId) -> Self {
|
||||||
Self { sid, client_secret, mxid }
|
Self { sid, client_secret, mxid }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
use ruma_common::thirdparty::Medium;
|
use ruma_common::thirdparty::Medium;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -17,11 +18,11 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The Session ID generated by the `requestToken` call.
|
/// The Session ID generated by the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret passed to the `requestToken` call.
|
/// The client secret passed to the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
}
|
}
|
||||||
|
|
||||||
response: {
|
response: {
|
||||||
@ -38,7 +39,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Creates a `Request` with the given Session ID and client secret.
|
/// Creates a `Request` with the given Session ID and client secret.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret) -> Self {
|
||||||
Self { sid, client_secret }
|
Self { sid, client_secret }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,7 +16,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// A unique string generated by the client, and used to identify the validation attempt.
|
/// A unique string generated by the client, and used to identify the validation attempt.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The email address to validate.
|
/// The email address to validate.
|
||||||
pub email: &'a str,
|
pub email: &'a str,
|
||||||
@ -32,7 +33,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session ID. Session IDs are opaque strings generated by the identity server.
|
/// The session ID. Session IDs are opaque strings generated by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ impl<'a> Request<'a> {
|
|||||||
/// Create a new `Request` with the given client secret, email ID, `send_attempt` number, and
|
/// Create a new `Request` with the given client secret, email ID, `send_attempt` number, and
|
||||||
/// the link to redirect to after validation.
|
/// the link to redirect to after validation.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
email: &'a str,
|
email: &'a str,
|
||||||
send_attempt: UInt,
|
send_attempt: UInt,
|
||||||
next_link: Option<&'a str>,
|
next_link: Option<&'a str>,
|
||||||
@ -51,7 +52,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Create a new `Response` with the given session ID.
|
/// Create a new `Response` with the given session ID.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid }
|
Self { sid }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! [POST /_matrix/identity/v2/validate/email/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-email-submittoken)
|
//! [POST /_matrix/identity/v2/validate/email/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-email-submittoken)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -14,10 +15,10 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The session ID, generated by the `requestToken` call.
|
/// The session ID, generated by the `requestToken` call.
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret that was supplied to the `requestToken` call.
|
/// The client secret that was supplied to the `requestToken` call.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The token generated by the `requestToken` call and emailed to the user.
|
/// The token generated by the `requestToken` call and emailed to the user.
|
||||||
pub token: &'a str,
|
pub token: &'a str,
|
||||||
@ -31,7 +32,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Create a new `Request` with the given session ID, client secret and token.
|
/// Create a new `Request` with the given session ID, client secret and token.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self {
|
||||||
Self { sid, client_secret, token }
|
Self { sid, client_secret, token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! [GET /_matrix/identity/v2/validate/email/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#get-matrix-identity-v2-validate-email-submittoken)
|
//! [GET /_matrix/identity/v2/validate/email/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#get-matrix-identity-v2-validate-email-submittoken)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,11 +16,11 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The session ID, generated by the `requestToken` call.
|
/// The session ID, generated by the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret that was supplied to the `requestToken` call.
|
/// The client secret that was supplied to the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The token generated by the `requestToken` call and emailed to the user.
|
/// The token generated by the `requestToken` call and emailed to the user.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
@ -32,7 +33,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Create a new `Request` with the given session ID, client secret and token.
|
/// Create a new `Request` with the given session ID, client secret and token.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self {
|
||||||
Self { sid, client_secret, token }
|
Self { sid, client_secret, token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionIdBox};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,7 +16,7 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// A unique string generated by the client, and used to identify the validation attempt.
|
/// A unique string generated by the client, and used to identify the validation attempt.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in
|
/// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in
|
||||||
/// `phone_number` should be parsed as if it were dialled from.
|
/// `phone_number` should be parsed as if it were dialled from.
|
||||||
@ -37,7 +38,7 @@ ruma_api! {
|
|||||||
|
|
||||||
response: {
|
response: {
|
||||||
/// The session ID. Session IDs are opaque strings generated by the identity server.
|
/// The session ID. Session IDs are opaque strings generated by the identity server.
|
||||||
pub sid: String,
|
pub sid: SessionIdBox,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ impl<'a> Request<'a> {
|
|||||||
/// Create a new `Request` with the given client secret, country code, phone number, the
|
/// Create a new `Request` with the given client secret, country code, phone number, the
|
||||||
/// `send_attempt` number and the next link to go to after validation.
|
/// `send_attempt` number and the next link to go to after validation.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
client_secret: &'a str,
|
client_secret: &'a ClientSecret,
|
||||||
country: &'a str,
|
country: &'a str,
|
||||||
phone_number: &'a str,
|
phone_number: &'a str,
|
||||||
send_attempt: UInt,
|
send_attempt: UInt,
|
||||||
@ -57,7 +58,7 @@ impl<'a> Request<'a> {
|
|||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
/// Create a new `Response` with the given session ID.
|
/// Create a new `Response` with the given session ID.
|
||||||
pub fn new(sid: String) -> Self {
|
pub fn new(sid: SessionIdBox) -> Self {
|
||||||
Self { sid }
|
Self { sid }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! [POST /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-msisdn-submittoken)
|
//! [POST /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-msisdn-submittoken)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -14,10 +15,10 @@ ruma_api! {
|
|||||||
|
|
||||||
request: {
|
request: {
|
||||||
/// The session ID, generated by the `requestToken` call.
|
/// The session ID, generated by the `requestToken` call.
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret that was supplied to the `requestToken` call.
|
/// The client secret that was supplied to the `requestToken` call.
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The token generated by the `requestToken` call and sent to the user.
|
/// The token generated by the `requestToken` call and sent to the user.
|
||||||
pub token: &'a str,
|
pub token: &'a str,
|
||||||
@ -31,7 +32,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Create a new `Request` with the given session ID, client secret and token.
|
/// Create a new `Request` with the given session ID, client secret and token.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self {
|
||||||
Self { sid, client_secret, token }
|
Self { sid, client_secret, token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! [GET /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#get-matrix-identity-v2-validate-msisdn-submittoken)
|
//! [GET /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#get-matrix-identity-v2-validate-msisdn-submittoken)
|
||||||
|
|
||||||
use ruma_api::ruma_api;
|
use ruma_api::ruma_api;
|
||||||
|
use ruma_identifiers::{ClientSecret, SessionId};
|
||||||
|
|
||||||
ruma_api! {
|
ruma_api! {
|
||||||
metadata: {
|
metadata: {
|
||||||
@ -15,11 +16,11 @@ ruma_api! {
|
|||||||
request: {
|
request: {
|
||||||
/// The session ID, generated by the `requestToken` call.
|
/// The session ID, generated by the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub sid: &'a str,
|
pub sid: &'a SessionId,
|
||||||
|
|
||||||
/// The client secret that was supplied to the `requestToken` call.
|
/// The client secret that was supplied to the `requestToken` call.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
pub client_secret: &'a str,
|
pub client_secret: &'a ClientSecret,
|
||||||
|
|
||||||
/// The token generated by the `requestToken` call and sent to the user.
|
/// The token generated by the `requestToken` call and sent to the user.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
@ -32,7 +33,7 @@ ruma_api! {
|
|||||||
|
|
||||||
impl<'a> Request<'a> {
|
impl<'a> Request<'a> {
|
||||||
/// Create a new `Request` with the given session ID, client secret and token.
|
/// Create a new `Request` with the given session ID, client secret and token.
|
||||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self {
|
||||||
Self { sid, client_secret, token }
|
Self { sid, client_secret, token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,8 +258,10 @@ fn strip_lifetimes(field_type: &mut Type) -> bool {
|
|||||||
if last_seg.ident == "str" {
|
if last_seg.ident == "str" {
|
||||||
// &str -> String
|
// &str -> String
|
||||||
Some(parse_quote! { ::std::string::String })
|
Some(parse_quote! { ::std::string::String })
|
||||||
} else if last_seg.ident == "DeviceId"
|
} else if last_seg.ident == "ClientSecret"
|
||||||
|
|| last_seg.ident == "DeviceId"
|
||||||
|| last_seg.ident == "ServerName"
|
|| last_seg.ident == "ServerName"
|
||||||
|
|| last_seg.ident == "SessionId"
|
||||||
|| last_seg.ident == "RawJsonValue"
|
|| last_seg.ident == "RawJsonValue"
|
||||||
{
|
{
|
||||||
// The identifiers that need to be boxed `Box<T>` since they are DST's.
|
// The identifiers that need to be boxed `Box<T>` since they are DST's.
|
||||||
|
@ -84,11 +84,12 @@ pub use ruma_serde::Outgoing;
|
|||||||
#[allow(deprecated)] // Allow re-export of deprecated items
|
#[allow(deprecated)] // Allow re-export of deprecated items
|
||||||
pub use ruma_identifiers::{
|
pub use ruma_identifiers::{
|
||||||
device_id, device_key_id, event_id, mxc_uri, room_alias_id, room_id, room_version_id,
|
device_id, device_key_id, event_id, mxc_uri, room_alias_id, room_id, room_version_id,
|
||||||
server_key_id, server_name, server_signing_key_id, user_id, DeviceId, DeviceIdBox,
|
server_key_id, server_name, server_signing_key_id, user_id, ClientSecret, ClientSecretBox,
|
||||||
DeviceKeyAlgorithm, DeviceKeyId, DeviceSignatures, DeviceSigningKeyId, EntitySignatures,
|
DeviceId, DeviceIdBox, DeviceKeyAlgorithm, DeviceKeyId, DeviceSignatures, DeviceSigningKeyId,
|
||||||
EventEncryptionAlgorithm, EventId, KeyId, KeyName, KeyNameBox, MxcUri, RoomAliasId, RoomId,
|
EntitySignatures, EventEncryptionAlgorithm, EventId, KeyId, KeyName, KeyNameBox, MxcUri,
|
||||||
RoomIdOrAliasId, RoomVersionId, ServerName, ServerNameBox, ServerSignatures,
|
RoomAliasId, RoomId, RoomIdOrAliasId, RoomVersionId, ServerName, ServerNameBox,
|
||||||
ServerSigningKeyId, Signatures, SigningKeyAlgorithm, UserId,
|
ServerSignatures, ServerSigningKeyId, SessionId, SessionIdBox, Signatures, SigningKeyAlgorithm,
|
||||||
|
UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user