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 { ... }
}
public-key
only.Expand description
Trait for webhooks that use asymmetric keys for signatures
Required Associated Types§
Sourcetype ALG: WebhookPublicKeyAlgorithm
type ALG: WebhookPublicKeyAlgorithm
Algorithm used for verification
Required Methods§
Sourcefn public_key(
&self,
req: &Request<'_>,
) -> impl Future<Output = Outcome<'_, Bytes, WebhookError>> + Send + Sync
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.
Sourcefn expected_signature(
&self,
req: &Request<'_>,
) -> Outcome<'_, Vec<u8>, WebhookError>
fn expected_signature( &self, req: &Request<'_>, ) -> Outcome<'_, Vec<u8>, WebhookError>
Get the expected signature from the request
Provided Methods§
Sourcefn message_to_verify(
&self,
req: &Request<'_>,
body: &Bytes,
time_bounds: (u32, u32),
) -> Outcome<'_, Bytes, WebhookError>
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.
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.
impl WebhookPublicKey for DiscordWebhook
discord
only.Source§impl WebhookPublicKey for SendGridWebhook
Available on crate feature sendgrid
only.
impl WebhookPublicKey for SendGridWebhook
sendgrid
only.