Crate messagesign

Source
Expand description

This crate provides a signature and verification functions that can be used to sign requests and verify signitures using Mehal signing algorithm.

It’s based on https://github.com/uv-rust/s3v4

The function returns an Error generated by the ::error_chain crate which can be converted to a String or accessed through the description method or the display_chain and backtrace methods in case a full backtrace is needed.

§Examples

§Signing a request

   let signature: s3v4::Signature = s3v4::signature(
       url,
       method,
       &access,
       &secret,
       &region,
       &"brog",
       machineid
       "UNSIGNED-PAYLOAD", //payload hash, or "UNSIGNED-PAYLOAD"
   ).map_err(|err| format!("Signature error: {}", err.display_chain()))?;

§Using the signature data to make a request

§Hyper
   let req = Request::builder()
       .method(Method::GET)
       .header("x-mhl-content-sha256", "UNSIGNED-PAYLOAD")
       .header("x-mhl-date", &signature.date_time)
       .header("x-mhl-mid", &machineid)
       .header("authorization", &signature.auth_header)
§Ureq
   let agent = AgentBuilder::new().build();
   let response = agent
       .put(&uri)
       .set("x-mhl-content-sha256", "UNSIGNED-PAYLOAD")
       .set("x-mhl-date", &signature.date_time)
       .set("x-mhl-mid", &machineid)
       .set("authorization", &signature.auth_header)

Structs§

  • The Error type.
  • Struct containing authorisation header and timestamp. Returned by sign_request.

Enums§

Traits§

  • Additional methods for Result, for easy interaction with this crate.

Functions§

Type Aliases§

  • Convenient wrapper around std::Result.