Expand description
This crate provides a signature and verification functions that can be used to sign requests and verify Signatures 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
use error_chain::ChainedError;
let url = url::Url::parse("https://mehal.tech/endpoint").unwrap();
let signature: messagesign::Signature = messagesign::signature(
&url, // The endpoint of the mehel services
"GET", // The http Method
"ivegotthekey", // the access key provided with your secret
"ivegotthesecret", // The secret provided for your project
"global", // A supported region See mehal.tech docs
&"brog",
"hostname", // the name of the machine
"machineid", // The data in /etc/machine-id
"UNSIGNED-PAYLOAD", //payload hash, or "UNSIGNED-PAYLOAD"
"", // An empty string or a random u32
).map_err(|err| format!("Signature error: {}", err.display_chain())).unwrap();
§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("x-mhl-hostname", &hostname)
.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("x-mhl-hostname", &hostname)
.set("authorization", &signature.auth_header)
Structs§
- Error
- The Error type.
- Signature
- Struct containing authorisation header and timestamp. Returned by
sign_request
.
Enums§
- Error
Kind - The kind of an error.
Traits§
- Result
Ext - Additional methods for
Result
, for easy interaction with this crate.
Functions§
- signature
- Return signed header and timestamp.
- verification
Type Aliases§
- Result
- Convenient wrapper around
std::Result
.