#http #signatures #digest #actix


An HTTP Signatures library that leaves the signing to you

44 releases

Uses new Rust 2021

0.6.1 Mar 8, 2022
0.6.0-beta.6 Feb 26, 2022
0.5.0-beta.14 Dec 13, 2021
0.5.0-beta.12 Oct 27, 2021
0.1.0 Sep 21, 2019

#79 in Cryptography

Download history 388/week @ 2022-06-16 312/week @ 2022-06-23 305/week @ 2022-06-30 356/week @ 2022-07-07 262/week @ 2022-07-14 304/week @ 2022-07-21 536/week @ 2022-07-28 339/week @ 2022-08-04 348/week @ 2022-08-11 217/week @ 2022-08-18 168/week @ 2022-08-25 223/week @ 2022-09-01 496/week @ 2022-09-08 211/week @ 2022-09-15 482/week @ 2022-09-22 387/week @ 2022-09-29

1,654 downloads per month
Used in 17 crates (9 directly)

Custom license


HTTP Signature Normaliztion Actix

An HTTP Signatures library that leaves the signing to you

Http Signature Normalization is a minimal-dependency crate for producing HTTP Signatures with user-provided signing and verification. The API is simple; there's a series of steps for creation and verification with types that ensure reasonable usage.


This crate provides extensions the ClientRequest type from Actix Web, and provides middlewares for verifying HTTP Signatures, and optionally, Digest headers

First, add this crate to your dependencies

actix-rt = "2.6.0"
actix-web = "4.0.0"
thiserror = "0.1"
http-signature-normalization-actix = { version = "0.6.0", default-features = false, features = ["sha-2"] }
sha2 = "0.9"

Then, use it in your client

async fn request(config: Config) -> Result<(), Box<dyn std::error::Error>> {
    let digest = Sha256::new();

    let mut response = Client::default()
        .append_header(("User-Agent", "Actix Web"))
        .append_header(("Accept", "text/plain"))
        .signature_with_digest(config, "my-key-id", digest, "Hewwo-owo", |s| {
            info!("Signing String\n{}", s);
            Ok(base64::encode(s)) as Result<_, MyError>
        .map_err(|e| {
            error!("Error, {}", e);

    let body = response.body().await.map_err(|e| {
        error!("Error, {}", e);

    info!("{:?}", body);

Or, use it in your server

#[derive(Clone, Debug)]
struct MyVerify;

impl SignatureVerify for MyVerify {
    type Error = MyError;
    type Future = Ready<Result<bool, Self::Error>>;

    fn signature_verify(
        &mut self,
        algorithm: Option<Algorithm>,
        key_id: String,
        signature: String,
        signing_string: String,
    ) -> Self::Future {
        match algorithm {
            Some(Algorithm::Hs2019) => (),
            _ => return ready(Err(MyError::Algorithm)),

        if key_id != "my-key-id" {
            return ready(Err(MyError::Key));

        let decoded = match base64::decode(&signature) {
            Ok(decoded) => decoded,
            Err(_) => return ready(Err(MyError::Decode)),

        info!("Signing String\n{}", signing_string);

        ready(Ok(decoded == signing_string.as_bytes()))

async fn index(
    (_, sig_verified): (DigestVerified, SignatureVerified),
    req: HttpRequest,
    _body: web::Bytes,
) -> &'static str {
    info!("Verified request for {}", sig_verified.key_id());
    info!("{:?}", req);

async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));

    let subscriber = tracing_subscriber::Registry::default()


    let config = Config::default().require_header("accept").require_digest();

    HttpServer::new(move || {
            .wrap(VerifySignature::new(MyVerify, config.clone()).optional())
            .route("/", web::post().to(index))


#[derive(Debug, thiserror::Error)]
enum MyError {
    #[error("Failed to verify, {0}")]
    Verify(#[from] PrepareVerifyError),

    #[error("Unsupported algorithm")]

    #[error("Couldn't decode signature")]

    #[error("Invalid key")]

impl ResponseError for MyError {
    fn status_code(&self) -> StatusCode {

    fn error_response(&self) -> HttpResponse {


Unless otherwise stated, all contributions to this project will be licensed under the CSL with the exceptions listed in the License section of this file.


This work is licensed under the Cooperative Software License. This is not a Free Software License, but may be considered a "source-available License." For most hobbyists, self-employed developers, worker-owned companies, and cooperatives, this software can be used in most projects so long as this software is distributed under the terms of the CSL. For more information, see the provided LICENSE file. If none exists, the license can be found online here. If you are a free software project and wish to use this software under the terms of the GNU Affero General Public License, please contact me at asonix@asonix.dog and we can sort that out. If you wish to use this project under any other license, especially in proprietary software, the answer is likely no.

Http Signature Normalization Actix is currently licensed under the AGPL to the Lemmy project, found at github.com/LemmyNet/lemmy


~374K SLoC