http_sig/lib.rs
1#![deny(missing_docs)]
2//! Implementation of the IETF draft 'Signing HTTP Messages'
3//! https://tools.ietf.org/id/draft-cavage-http-signatures-12.html
4//!
5//! ## Features
6//!
7//! This crate is intended to be used with multiple different HTTP clients and/or servers.
8//! As such, client/server-specific implementations are gated by correspondingly named
9//! features.
10//!
11//! ### Supported crates:
12//!
13//! | Crate / Feature name | Client/Server | Notes |
14//! | ------------------------------------------------- | ------------- | ------------------------------------------------------------- |
15//! | [reqwest](https://crates.io/crates/reqwest) | Client | Supports blocking and non-blocking requests.<sup>1</sup> |
16//! | [rouille](https://crates.io/crates/rouille) | Server | |
17//!
18//! 1. Due to limitations of the reqwest API, digests can only be calculated automatically for non-blocking non-streaming requests. For
19//! blocking or streaming requests, the user must add the digest manually before signing the request, or else the `Digest` header will
20//! not be included in the signature.
21//!
22//! ### Supported signature algorithms:
23//!
24//! Algorithm registry: https://tools.ietf.org/id/draft-cavage-http-signatures-12.html#hsa-registry
25//!
26//! - `hmac-sha256`
27//!
28//! ### Supported digest algorithms:
29//!
30//! Digest registry: https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml
31//!
32//! - `SHA-256`
33//! - `SHA-512`
34//!
35//! ## Example usage (reqwest)
36//!
37//! ```rust,no_run
38//! use http_sig::*;
39//!
40//! const SECRET_KEY: &[u8] = b"secret";
41//!
42//! let config = SigningConfig::new_default("My Key", SECRET_KEY);
43//!
44//! let client = reqwest::blocking::Client::new();
45//!
46//! let req = client
47//! .get("http://localhost:8080/")
48//! .build()
49//! .unwrap()
50//! .signed(&config)
51//! .unwrap();
52//!
53//! let result = client.execute(req).unwrap();
54//! ```
55
56use sha2::Sha256;
57
58const DATE_FORMAT: &str = "%a, %d %b %Y %T GMT";
59type DefaultSignatureAlgorithm = algorithm::HmacSha256;
60type DefaultDigestAlgorithm = Sha256;
61
62#[macro_use]
63mod macros;
64
65mod algorithm;
66pub use algorithm::*;
67
68mod header;
69pub use header::*;
70
71mod canonicalize;
72pub use canonicalize::*;
73
74mod signing;
75pub use signing::*;
76
77mod verifying;
78pub use verifying::*;
79
80/// Module containg a mock request type which implements both
81/// `ClientRequestLike` and `ServerRequestLike` for testing.
82pub mod mock_request;
83
84#[cfg(feature = "reqwest")]
85mod reqwest_impls;
86
87#[cfg(feature = "rouille")]
88mod rouille_impls;
89#[cfg(feature = "rouille")]
90pub use rouille_impls::*;