Struct Webhook

Source
pub struct Webhook { /* private fields */ }

Implementations§

Source§

impl Webhook

Source

pub fn insecure(payload: &str) -> Result<Event, WebhookError>

Construct an event from a webhook payload, ignoring the secret.

This method is considered insecure and intended for early-stage local testing only. Use construct_event for production instead.

§Errors

This function will return a WebhookError if the payload could not be parsed

Source

pub fn construct_event( payload: &str, sig: &str, secret: &str, ) -> Result<Event, WebhookError>

Construct an event from a webhook payload and signature.

§Errors

This function will return a WebhookError if:

  • the provided signature is invalid
  • the provided secret is invalid
  • the signature timestamp is older than 5 minutes
  • the payload could not be parsed
Source

pub fn construct_event_with_timestamp( payload: &str, sig: &str, secret: &str, timestamp: i64, ) -> Result<Event, WebhookError>

Construct an event from a webhook payload and signature, verifying its signature using the provided timestamp.

This is helpful for replaying requests in tests and should be avoided otherwise in production use.

§Errors

This function will return a WebhookError if:

  • the provided signature is invalid
  • the provided secret is invalid
  • the signature timestamp is older than 5 minutes from the provided timestamp
  • the payload could not be parsed

Trait Implementations§

Source§

impl Debug for Webhook

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.