[−][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::{ CreationKey, 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 = CreationKey::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::*, 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), pub_key)?;
Modules
prelude | This module defines useful traits for using HTTP Signatures. |
Structs
HttpSignature | The |
Input | A wrapper around |
SignedHeader | The |
Enums
CreationKey | |
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 |