[−][src]Struct itsdangerous::signer::Signer
This struct can sign and unsign bytes, validating the signature provided.
A salt can be used to namespace the hash, so that a signed string is only valid for a given namespace. Leaving this at the default value or re-using a salt value across different parts of your application where the same signed value in one part can mean something different in another part is a security risk.
Basic Usage
use std::time::Duration; use itsdangerous::default_builder; // Create a signer using the default builder, and an arbitrary secret key. let signer = default_builder("secret key").build(); // Sign an arbitrary string. let signed = signer.sign("hello world!"); // Unsign the string and validate whether or not its expired. let unsigned = signer.unsign(&signed).expect("Signature was not valid"); assert_eq!(unsigned, "hello world!");
Methods
impl<Algorithm, DerivedKeySize, SignatureEncoder> Signer<Algorithm, DerivedKeySize, SignatureEncoder> where
Algorithm: SigningAlgorithm,
DerivedKeySize: ArrayLength<u8>,
SignatureEncoder: Base64Sized,
[src]
Algorithm: SigningAlgorithm,
DerivedKeySize: ArrayLength<u8>,
SignatureEncoder: Base64Sized,
pub fn sign<S: AsRef<str>>(&self, value: S) -> String
[src]
Signs the given string.
pub fn unsign<'a>(&'a self, value: &'a str) -> Result<&'a str, BadSignature<'a>>
[src]
Unsigns the given string. The logical inverse of sign
.
Remarks
This method performs zero copies or heap allocations and returns a reference to a slice
of the provided value
, If you need a copy, consider doing unsign(..).to_owned()
to convert the &str
to a String
.
pub fn into_timestamp_signer(
self
) -> TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder>
[src]
self
) -> TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder>
Converts this Signer
into a TimestampSigner
, giving it the ability
to do signing with timestamps!
Auto Trait Implementations
impl<Algorithm, DerivedKeySize, SignatureEncoder> Send for Signer<Algorithm, DerivedKeySize, SignatureEncoder> where
Algorithm: Send,
SignatureEncoder: Send,
Algorithm: Send,
SignatureEncoder: Send,
impl<Algorithm, DerivedKeySize, SignatureEncoder> Sync for Signer<Algorithm, DerivedKeySize, SignatureEncoder> where
Algorithm: Sync,
SignatureEncoder: Sync,
Algorithm: Sync,
SignatureEncoder: Sync,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self