[−][src]Struct mauth_client::MAuthInfo
This is the primary struct of this class. It contains all of the information required to sign requests using the MAuth protocol and verify the responses.
Note that it contains a cache of response keys for verifying response signatures. This cache makes the struct non-Sync.
Implementations
impl MAuthInfo
[src]
pub fn from_default_file() -> Result<MAuthInfo, ConfigReadError>
[src]
Construct the MAuthInfo struct based on the contents of the config file .mauth_config.yml
present in the current user's home directory. Returns an enum error type that includes the
error types of all crates used.
pub fn build_body_with_digest(body: String) -> (Body, BodyDigest)
[src]
The MAuth Protocol requires computing a digest of the full text body of the request to be
sent. This is incompatible with the Hyper crate's structs, which do not allow the body of a
constructed Request to be read. To solve this, use this function to compute both the body to
be used to build the Request struct, and the digest struct to be passed to the
sign_request_v2
function.
Note that this method must be used with all empty-body requests, including GET requests.
pub fn build_body_with_digest_from_bytes(body: Vec<u8>) -> (Body, BodyDigest)
[src]
The MAuth Protocol requires computing a digest of the full text body of the request to be
sent. This is incompatible with the Hyper crate's structs, which do not allow the body of a
constructed Request to be read. To solve this, use this function to compute both the body to
be used to build the Request struct, and the digest struct to be passed to the
sign_request_v2
function.
This function is an alternate version of the build_body_with_digest function that allows the user to build request bodies from data that does not meet the Rust String type requirements of being valid UTF8. Any binary data can be transformed into the appropriate objects and signed using this function.
Note that this method must be used with all empty-body requests, including GET requests.
pub fn sign_request(
&self,
mut req: &mut Request<Body>,
body_digest: &BodyDigest
)
[src]
&self,
mut req: &mut Request<Body>,
body_digest: &BodyDigest
)
This method determines how to sign the request automatically while respecting the
v2_only_sign_requests
flag in the config file. It always signs with the V2 algorithm and
signature, and will also sign with the V1 algorithm, if the configuration permits.
pub async fn validate_response(
&self,
response: &mut Response<Body>
) -> Result<Vec<u8>, MAuthValidationError>
[src]
&self,
response: &mut Response<Body>
) -> Result<Vec<u8>, MAuthValidationError>
Validate that a Hyper Response contains a valid MAuth signature. Returns either the validated response body, or an error with details on why the signature was invalid.
This method will attempt to validate a V2 signature first. If that fails, and if the
flag allow_v1_response_auth
is set in the configuration, it will then attempt to validate
a V1 signature. It will return Ok(body)
if the request successfully authenticates,
otherwise, it will return the most recent validation error.
This function requires a mutable borrow of the response and will consume the body contents, as that is the only way to get the body out and perform the necessary hashing on it. Once the validation is complete, the other properties of the response may be inspected as needed.
This method is async
because it may make a HTTP request to the MAuth server in order to
retrieve the public key for the application that signed the response. Application keys are
cached in the MAuth struct, so the request only needs to be made once.
pub fn sign_request_v2(
&self,
mut req: &mut Request<Body>,
body_digest: &BodyDigest
)
[src]
&self,
mut req: &mut Request<Body>,
body_digest: &BodyDigest
)
Sign a provided request using the MAuth V2 protocol. The signature consists of 2 headers
containing both a timestamp and a signature string, and will be added to the headers of the
request. It is required to pass a body_digest
computed by the
build_body_with_digest
method, even if the request is
an empty-body GET.
Note that, as the request signature includes a timestamp, the request must be sent out shortly after the signature takes place.
pub fn sign_request_v1(&self, req: &mut Request<Body>, body: &BodyDigest)
[src]
Sign a provided request using the MAuth V1 protocol. The signature consists of 2 headers
containing both a timestamp and a signature string, and will be added to the headers of the
request. It is required to pass a body
, even if the request is an empty-body GET.
Note that, as the request signature includes a timestamp, the request must be sent out shortly after the signature takes place.
Auto Trait Implementations
impl !RefUnwindSafe for MAuthInfo
[src]
impl Send for MAuthInfo
[src]
impl !Sync for MAuthInfo
[src]
impl Unpin for MAuthInfo
[src]
impl UnwindSafe for MAuthInfo
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,