WebhookPublicKey

Trait WebhookPublicKey 

Source
pub trait WebhookPublicKey: Webhook {
    type ALG: WebhookPublicKeyAlgorithm;

    // Required methods
    fn public_key(
        &self,
        req: &Request<'_>,
    ) -> impl Future<Output = Outcome<'_, Bytes, WebhookError>> + Send + Sync;
    fn expected_signature(
        &self,
        req: &Request<'_>,
    ) -> Outcome<'_, Vec<u8>, WebhookError>;

    // Provided methods
    fn message_to_verify(
        &self,
        req: &Request<'_>,
        body: &Bytes,
        time_bounds: (u32, u32),
    ) -> Outcome<'_, Bytes, WebhookError> { ... }
    fn validate_with_public_key(
        &self,
        req: &Request<'_>,
        body: impl AsyncRead + Unpin + Send + Sync,
        time_bounds: (u32, u32),
    ) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
       where Self: Sync { ... }
}
Available on crate feature public-key only.
Expand description

Trait for webhooks that use asymmetric keys for signatures

Required Associated Types§

Source

type ALG: WebhookPublicKeyAlgorithm

Algorithm used for verification

Required Methods§

Source

fn public_key( &self, req: &Request<'_>, ) -> impl Future<Output = Outcome<'_, Bytes, WebhookError>> + Send + Sync

Get the public key for the webhook signature. This is async in case the public key needs to be fetched externally. The public key can be cached in Rocket state, accessible via req.rocket().state().

Uses the tokio_util::bytes::Bytes struct to avoid unnecessary cloning.

Source

fn expected_signature( &self, req: &Request<'_>, ) -> Outcome<'_, Vec<u8>, WebhookError>

Get the expected signature from the request

Provided Methods§

Source

fn message_to_verify( &self, req: &Request<'_>, body: &Bytes, time_bounds: (u32, u32), ) -> Outcome<'_, Bytes, WebhookError>

Get the message that needs to be verified. Any adjustments can be made to the body here before calculating the signature (e.g. prefixes or hashes, etc.)

Uses the tokio_util::bytes::Bytes struct to avoid unnecessary cloning of the body.

Source

fn validate_with_public_key( &self, req: &Request<'_>, body: impl AsyncRead + Unpin + Send + Sync, time_bounds: (u32, u32), ) -> impl Future<Output = Outcome<'_, Vec<u8>, WebhookError>> + Send + Sync
where Self: Sync,

Read the raw body and verify with the public key and configured algorithm

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl WebhookPublicKey for DiscordWebhook

Available on crate feature discord only.
Source§

impl WebhookPublicKey for SendGridWebhook

Available on crate feature sendgrid only.