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
impl Verifier
Sourcepub fn new(
app_uuid: impl Into<String>,
public_key_data: String,
) -> Result<Self, Error>
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());
Sourcepub 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>
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(_))));