# messagesign
A rust library to sign requests to mehal services based on the [AWS S3V4 approach](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html).
The implementation is based on the [s3v4](https://github.com/uv-rust/s3v4) library.
This crate provides a `signature` function that can be used to sign a request to an mehal services.
Both functions return an `Error` generated by the `error_chain` crate which can be
converted to a `String` or accessed through the `description` method or `display_chain`
and `backtrace` methods in case a full backtrace is needed.
# Examples
## Signing a request
```rust
let signature: s3v4::Signature = s3v4::signature(
url,
method,
&access,
&secret,
®ion,
&"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
```rust
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
```rust
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)
```