pub struct HttpSignature { /* fields omitted */ }
The HttpSignature
struct, this is the entry point for creating Authorization or Signature
headers. It contains all the values required for generation.
Create a new HttpSignature from its components.
This method will Error if headers
is empty.
use http_signatures::{
CreateKey,
HttpSignature,
Input,
ShaSize,
REQUEST_TARGET,
};
use ring::signature::RSAKeyPair;
let mut priv_key_file = File::open("tests/assets/private.der")?;
let mut priv_key_vec = Vec::new();
priv_key_file.read_to_end(&mut priv_key_vec)?;
let priv_key_input = Input::from(&priv_key_vec);
let priv_key = RSAKeyPair::from_der(priv_key_input).unwrap();
let priv_creation_key = CreateKey::rsa(priv_key, ShaSize::SHA512);
let key_id = "tests/assets/public.der".into();
let mut headers = BTreeMap::new();
headers.insert(REQUEST_TARGET.into(), vec!["get /".into()]);
let http_sig = HttpSignature::new(key_id, priv_creation_key, headers)?;
Generate the Authorization Header from the HttpSignature
This method errors if signing the signing-string fails.
use http_signatures::HttpSignature;
let auth_header = http_signature.authorization_header()?;
println!("Authorization: {}", auth_header);
Generate the Signature Header from the HttpSignature
This method errors if signing the signing-string fails.
use http_signatures::HttpSignature;
let sig_header = http_signature.signature_header()?;
println!("Signature: {}", sig_header);
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static