#[non_exhaustive]pub struct XMatrix {
pub origin: OwnedServerName,
pub destination: Option<OwnedServerName>,
pub key: OwnedServerSigningKeyId,
pub sig: Base64,
}client or server only.Expand description
Typed representation of an X-Matrix authentication scheme, as defined in the Matrix
Server-Server API.
This is a scheme used in an Authorization HTTP header, as defined in RFC 7235.
It can be extracted from an incoming HTTP request using XMatrix::parse() or
XMatrix::extract_from_http_headers(). The HTTP request should then be verified with
XMatrix::verify_http_request().
It can also be generated by signing an outgoing request with XMatrix::sign_http_request().
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.origin: OwnedServerNameThe server name of the sending server.
destination: Option<OwnedServerName>The server name of the receiving sender.
For compatibility with older servers, recipients should accept requests without this
parameter, but MUST always send it. If this property is included, but the value does
not match the receiving server’s name, the receiving server must deny the request with
a 401 Unauthorized HTTP status code.
key: OwnedServerSigningKeyIdThe ID - including the algorithm name - of the sending server’s key that was used to sign the request.
sig: Base64The signature of the canonical JSON request object.
Implementations§
Source§impl XMatrix
impl XMatrix
Sourcepub const AUTH_SCHEME: &'static str = "X-Matrix"
pub const AUTH_SCHEME: &'static str = "X-Matrix"
The auth-scheme token used to identify the X-Matrix authentication scheme in the
Authorization HTTP header.
Sourcepub fn new(
origin: OwnedServerName,
destination: OwnedServerName,
key: OwnedServerSigningKeyId,
sig: Base64,
) -> Self
pub fn new( origin: OwnedServerName, destination: OwnedServerName, key: OwnedServerSigningKeyId, sig: Base64, ) -> Self
Construct a new X-Matrix authentication scheme from its parts.
Sourcepub fn parse(s: impl AsRef<str>) -> Result<Self, XMatrixParseError>
pub fn parse(s: impl AsRef<str>) -> Result<Self, XMatrixParseError>
Parse an X-Matrix authentication scheme from the given string.
The string should be the value of an Authorization HTTP header.
§Errors
Returns an error if the scheme could not be parsed.
Sourcepub fn extract_from_http_headers(
headers: &HeaderMap,
) -> Result<Self, XMatrixExtractError>
pub fn extract_from_http_headers( headers: &HeaderMap, ) -> Result<Self, XMatrixExtractError>
Try to extract an X-Matrix authentication scheme from the given HTTP headers.
§Errors
Returns an error if the Authorization header is not found in the map, or if the scheme
could not be parsed.
Sourcepub fn request_object<T: AsRef<[u8]>>(
request: &Request<T>,
origin: &ServerName,
destination: &ServerName,
) -> Result<CanonicalJsonObject, Error>
pub fn request_object<T: AsRef<[u8]>>( request: &Request<T>, origin: &ServerName, destination: &ServerName, ) -> Result<CanonicalJsonObject, Error>
Construct the canonical JSON object representation to sign to generate or verify the
X-Matrix authentication scheme for the given request, with the given origin and
destination.
§Errors
Returns an error if the body of the request could not be serialized to canonical JSON.
Sourcepub fn sign_http_request<T: AsRef<[u8]>>(
request: &Request<T>,
input: XMatrixSigningInput<'_>,
) -> Result<Self, XMatrixFromRequestError>
pub fn sign_http_request<T: AsRef<[u8]>>( request: &Request<T>, input: XMatrixSigningInput<'_>, ) -> Result<Self, XMatrixFromRequestError>
Try to generate an X-Matrix authentication scheme by signing the given HTTP request with
the given signing input.
The returned scheme should be added as the value of the Authorization header of the
request.
§Errors
Returns an error if the body of the request could not be serialized to canonical JSON or if the ID of the signing key pair is invalid.
Sourcepub fn verify_http_request<T: AsRef<[u8]>>(
&self,
request: &Request<T>,
destination: &ServerName,
public_key_map: &PublicKeyMap,
) -> Result<(), XMatrixVerificationError>
pub fn verify_http_request<T: AsRef<[u8]>>( &self, request: &Request<T>, destination: &ServerName, public_key_map: &PublicKeyMap, ) -> Result<(), XMatrixVerificationError>
Verify that the signature in the sig field of this X-Matrix authentication scheme is
valid for the given incoming HTTP request and destination, with the given public keys map
from the origin.
§Errors
Returns an error if the given destination doesn’t match the one present in the scheme, if the body of the request could not be serialized to canonical JSON, or it the verification of the signature failed.
Trait Implementations§
Source§impl From<&XMatrix> for HeaderValue
impl From<&XMatrix> for HeaderValue
Source§impl TryFrom<&HeaderValue> for XMatrix
impl TryFrom<&HeaderValue> for XMatrix
Source§type Error = XMatrixParseError
type Error = XMatrixParseError
Auto Trait Implementations§
impl Freeze for XMatrix
impl RefUnwindSafe for XMatrix
impl Send for XMatrix
impl Sync for XMatrix
impl Unpin for XMatrix
impl UnsafeUnpin for XMatrix
impl UnwindSafe for XMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more