Crate digest_headers [] [src]

Digest Header, a simple library for verifying the content of HTTP Requests.

This library doesn't offer any verification of identity, it only ensures that the content of the request matches the signature in the Digest header of the request. If you want to verify that a request has not been tampered with, it is best to use this library in conjunction with http signatures. This way, the Headers are signed with a key, validating identity and authenticity, and the Digest header validates the body of the request.

Basic use without an HTTP library

use digest_headers::{Digest, ShaSize};

let message = b"Some message";

let digest = Digest::new(message, ShaSize::TwoFiftySix);

assert!(digest.verify(message).is_ok());

Getting a Digest from a 'raw' digest string

use digest_headers::Digest;

let raw_digest = "SHA-256=2EL3dJGSq4d5YyGi76VZ5ZHzq5km0aZ0k4L8g1c4Llk=";

let digest = raw_digest.parse::<Digest>()?;

assert!(digest.verify(br#"{"Library":"Hyper"}"#).is_ok());

Adding a Digest to a Hyper request

With the as_string method, a Digest can easily be added to an HTTP Request. This example shows adding a Digest to a Hyper Request without using the included DigestHeader from the use_hyper feature.

use digest_headers::{Digest, ShaSize};
use hyper::{Method, Request};

let uri = "http://example.com".parse().unwrap();

let body = "Some body";
let digest = Digest::new(body.as_bytes(), ShaSize::TwoFiftySix);

let mut req: Request = Request::new(Method::Post, uri);
req.headers_mut().set_raw("Digest", digest.as_string());
req.set_body(body);

Modules

prelude

The prelude module provides useful traits for working with Digest headers.

use_hyper

The use_hyper module provides useful Types and Traits for interacting with Hyper with Digests.

use_rocket

This file defines the types and logic for interacting with Digests from Rocket.

Structs

Digest

Defines the Digest type.

Enums

Error

The Error type

ShaSize

Defines variants for the size of SHA hash.