Skip to main content

CavageSigner

Struct CavageSigner 

Source
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>

Source

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.

Source

pub fn with_headers<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replaces the header set to sign.

Source

pub fn with_header_set(self, headers: CavageHeaderSet) -> Self

Replaces the header set directly.

Source

pub const fn with_created(self, seconds: i64) -> Self

Attaches a (created) timestamp. Required if the header set includes (created).

Source

pub const fn with_expires(self, seconds: i64) -> Self

Attaches an (expires) timestamp.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for CavageSigner<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CavageSigner<'a>

§

impl<'a> RefUnwindSafe for CavageSigner<'a>

§

impl<'a> Send for CavageSigner<'a>

§

impl<'a> Sync for CavageSigner<'a>

§

impl<'a> Unpin for CavageSigner<'a>

§

impl<'a> UnsafeUnpin for CavageSigner<'a>

§

impl<'a> UnwindSafe for CavageSigner<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more