[][src]Struct itsdangerous::timed::TimestampSigner

pub struct TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder>(_)
where
    DerivedKeySize: ArrayLength<u8>
;

A TimestampSigner wraps an inner Signer, giving it the ability to dish out signatures with timestamps.

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().into_timestamp_signer();

// 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");
let value = unsigned
    .value_if_not_expired(Duration::from_secs(60))
    .expect("Signature was expired");
assert_eq!(value, "hello world!");

Methods

impl<Algorithm, DerivedKeySize, SignatureEncoder> TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder> where
    Algorithm: SigningAlgorithm,
    DerivedKeySize: ArrayLength<u8>,
    SignatureEncoder: Base64Sized
[src]

pub fn as_signer(&self) -> &Signer<Algorithm, DerivedKeySize, SignatureEncoder>[src]

Returns a reference to the underlying Signer if you wish to use its methods.

Example

use itsdangerous::default_builder;

let timestamp_signer = default_builder("hello world").build().into_timestamp_signer();
let signer = timestamp_signer.as_signer();
let signer = signer.sign("hello without a timestamp!");

pub fn seperator(&self) -> Seperator[src]

pub fn sign_with_timestamp<S: AsRef<str>>(
    &self,
    value: S,
    timestamp: SystemTime
) -> String
[src]

Signs a value with an arbitrary timestamp.

pub fn sign<S: AsRef<str>>(&self, value: S) -> String[src]

Signs a value using the current system timestamp (as provided by SystemTime::now).

pub fn unsign<'a>(
    &'a self,
    value: &'a str
) -> Result<UnsignedValue, BadTimedSignature<'a>>
[src]

The inverse of sign / sign_with_timestamp, returning an UnsignedValue, which you can grab the value, timestamp, and assert the max age of the signed value with.

Remarks

This method performs zero copies or heap allocations and returns a reference to a slice of the provided value, inside of the UnsignedValue that is returned. If you need a copy, consider doing unsigned_value.value().to_owned() to convert the &str to a String.

Auto Trait Implementations

impl<Algorithm, DerivedKeySize, SignatureEncoder> Send for TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder> where
    Algorithm: Send,
    SignatureEncoder: Send

impl<Algorithm, DerivedKeySize, SignatureEncoder> Sync for TimestampSigner<Algorithm, DerivedKeySize, SignatureEncoder> where
    Algorithm: Sync,
    SignatureEncoder: Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self