pub struct CavageSigner<'a> { /* private fields */ }Expand description
A request signer that attaches a Cavage Signature: header to an
http::Request.
Borrows the signing key so that multiple requests can share the same key without reallocating it.
Implementations§
Source§impl<'a> CavageSigner<'a>
impl<'a> CavageSigner<'a>
Sourcepub fn new(key: &'a SigningKey, key_id: &'a str) -> Self
pub fn new(key: &'a SigningKey, key_id: &'a str) -> Self
Creates a signer using the DEFAULT_HEADER_SET and emitting the
algorithm="…" parameter for maximum compatibility with older
Fediverse implementations.
Sourcepub fn with_headers<I, S>(self, headers: I) -> Self
pub fn with_headers<I, S>(self, headers: I) -> Self
Replaces the header set to sign.
Sourcepub fn with_header_set(self, headers: CavageHeaderSet) -> Self
pub fn with_header_set(self, headers: CavageHeaderSet) -> Self
Replaces the header set directly.
Sourcepub const fn with_created(self, seconds: i64) -> Self
pub const fn with_created(self, seconds: i64) -> Self
Attaches a (created) timestamp. Required if the header set
includes (created).
Sourcepub const fn with_expires(self, seconds: i64) -> Self
pub const fn with_expires(self, seconds: i64) -> Self
Attaches an (expires) timestamp.
Sourcepub const fn emit_algorithm(self, emit: bool) -> Self
pub const fn emit_algorithm(self, emit: bool) -> Self
Controls whether the algorithm="…" parameter is emitted.
Cavage draft-12 §2.1.1 recommends against emitting the algorithm,
but every Fediverse implementation today expects to see it, so
this defaults to true.
Sourcepub fn sign<B>(&self, req: &mut Request<B>) -> Result<(), Error>
pub fn sign<B>(&self, req: &mut Request<B>) -> Result<(), Error>
Computes the signature over req and inserts the resulting
Signature: header in place.
§Errors
Returns Error::RequiredHeaderAbsent if the request does not
carry every header listed in the signer’s header set, and any
error from SigningKey::sign.