Verifier

Struct Verifier 

Source
pub struct Verifier { /* private fields */ }
Expand description

Used to verify incoming requests. Struct can be initialized once and used to verify many requests.

Implementations§

Source§

impl Verifier

Source

pub fn new( app_uuid: impl Into<String>, public_key_data: String, ) -> Result<Self, Error>

Initialize a new verifier with the source app UUID and the public key. The format of the public key should be a raw RSA public key in the public key PEM format, as generated by openssl rsa -pubout -out. An error will be returned if the input data is unable to be parsed as a public key. The app_uuid is expected to be a valid UUID, however this is not checked. If you pass something other than a valid UUID, no error will be returned, but none of the signatures will be able to be validated.

let verifier = Verifier::new("101c139a-236c-11ef-b5e3-125eb8485a60", public_key);
assert!(verifier.is_ok());
Source

pub fn verify_signature( &self, version: u8, verb: impl Into<String>, path: impl Into<String>, query: impl Into<String>, body: &[u8], timestamp: impl Into<String>, signature: impl Into<String>, ) -> Result<(), Error>

This function will verify that a provided signature is valid given the uuid and public key the struct was constructed with, the request properties passed into the function, and the signature passed in. It will return Ok(()) if the signature validates successfully, and Err if it does not. It is the responsibility of the consuming crate and application to use these cases to determine whether to process a request further, or return error information.

let result = verifier.verify_signature(2, "GET", "/item", "page=2", b"", "2024-01-28T19:11:35.000", "");
// Passing in an empty signature, so it will result in a verification error
assert!(matches!(result, Err(Error::SignatureVerifyError(_))));

Trait Implementations§

Source§

impl Clone for Verifier

Source§

fn clone(&self) -> Verifier

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Verifier

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V