pub struct Signatory { /* private fields */ }
Expand description
Struct responsible for signing operations.
Trait Implementations§
Source§impl Signer for Signatory
impl Signer for Signatory
Source§fn new(key: String) -> Signatory
fn new(key: String) -> Signatory
Creates a new instance of the Signatory struct with the provided secret key.
§Arguments
key
- AString
representing the secret key to be used in signing.
Source§fn generate_sign(
&self,
params: HashMap<String, Value>,
) -> Result<String, Box<dyn Error>>
fn generate_sign( &self, params: HashMap<String, Value>, ) -> Result<String, Box<dyn Error>>
Generates a signature from a given HashMap<String, Value>
.
Steps:
- Removes the
sign
field fromparams
if it exists. - Sorts the remaining keys in ascending order.
- Builds a query string from key-value pairs.
- Appends the secret key to the query string.
- Computes the MD5 hash of the string.
- Converts the hash to an uppercase hexadecimal string and returns it.
§Arguments
params
- A mutableHashMap<String, Value>
containing the parameters to sign.
§Returns
Returns the generated signature as a Result<String, Box<dyn Error>>
.
Source§fn to_string(
&self,
params: HashMap<String, Value>,
) -> Result<String, Box<dyn Error>>
fn to_string( &self, params: HashMap<String, Value>, ) -> Result<String, Box<dyn Error>>
Converts a HashMap<String, Value>
into a Base64-encoded string.
This function:
- Adds the current timestamp if the
timestamp
key does not exist. - Adds the generated signature to
params
if thesign
key does not exist. - Serializes the
params
to a JSON string. - Base64 encodes the JSON string and returns it.
§Arguments
params
- A mutableHashMap<String, Value>
containing the parameters to encode.
§Returns
Returns the Base64 encoded string as Result<String, Box<dyn Error>>
.
Source§fn decrypt(
&self,
params: String,
) -> Result<HashMap<String, Value>, Box<dyn Error>>
fn decrypt( &self, params: String, ) -> Result<HashMap<String, Value>, Box<dyn Error>>
Decodes a Base64-encoded string into a HashMap<String, Value>
.
This function:
- Base64 decodes the input string.
- Converts the resulting bytes into a UTF-8 string.
- Deserializes the string into a
HashMap
.
§Arguments
params
- A Base64-encoded string representing serializedHashMap<String, Value>
.
§Returns
Returns the decoded HashMap<String, Value>
as Result<HashMap<String, Value>, Box<dyn Error>>
.
Source§fn check_sign(&self, params: HashMap<String, Value>, sign: String) -> bool
fn check_sign(&self, params: HashMap<String, Value>, sign: String) -> bool
Verifies the integrity of the provided signature.
This function:
- Regenerates the signature based on the
params
. - Compares the regenerated signature with the provided
sign
.
§Arguments
params
- AHashMap<String, Value>
representing the parameters to verify.sign
- AString
representing the signature to verify.
§Returns
Returns true
if the signature matches, otherwise false
.
Auto Trait Implementations§
impl Freeze for Signatory
impl RefUnwindSafe for Signatory
impl Send for Signatory
impl Sync for Signatory
impl Unpin for Signatory
impl UnwindSafe for Signatory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more