[][src]Crate http_signatures

HTTP Signatures, an implementation of the http signatures specification

The base crate provides types for creating and verifying signatures, and the features use_hyper, use_reqwest, and use_rocket provide implementations of required traits for easily using HTTP Signatures with web applications.

Creating an HTTP Signature

To get a string that would be the contents of an HTTP Request's Authorization header, a few steps must be taken. The method, path, and query must be known, furthermore, there must be at least one item in the headers hashmap, if there is not, the HTTP Signature creation will fail.

use http_signatures::{
    CreateKey,
    HttpSignature,
    ShaSize,
    REQUEST_TARGET,
};

let method = "GET";
let path = "/test";
let query = "key=value";

let mut headers: BTreeMap<String, Vec<String>> = BTreeMap::new();
headers.insert("Accept".into(), vec!["application/json".into()]);
headers.insert(
    REQUEST_TARGET.into(),
    vec![format!("{} {}?{}", method.to_lowercase(), path, query)],
);

let priv_creation_key = CreateKey::rsa(priv_key, ShaSize::SHA512);
let key_id = "1".into();

let auth_header = HttpSignature::new(key_id, priv_creation_key, headers)?
    .authorization_header()?;

println!("Authorization: {}", auth_header);

Verifying an HTTP Signature

use http_signatures::{
    prelude::*,
    VerifyKey,
    SignedHeader,
};


let mut headers = Vec::new();
headers.push(("Accept".into(), "application/json".into()));

let method = "GET";
let path = "/test";
let query = "key=value";

let auth_header = SignedHeader::new(&auth_header)?;
auth_header
    .verify(&headers, method, path, Some(query), VerifyKey::unchecked_from_vec(pub_key_vec))?;

Modules

prelude

This module defines useful traits for using HTTP Signatures.

Structs

HttpSignature

The HttpSignature struct, this is the entry point for creating Authorization or Signature headers. It contains all the values required for generation.

SignedHeader

The SignedHeader struct is the direct reasult of reading in the Authorization or Signature header from a given request.

VerifyKey

The verification key

Enums

CreateKey
Error

The root Error

ShaSize

Variations of the Sha hashing function.

SignatureAlgorithm

Which algorithm should be used to create an HTTP header.

Constants

REQUEST_TARGET