pub trait Signer {
    fn sign<S: AsRef<str>>(&self, value: S) -> String;
fn unsign<'a>(&'a self, value: &'a str) -> Result<&'a str, BadSignature<'a>>;
fn separator(&self) -> Separator;
fn verify_encoded_signature(
        &self,
        value: &[u8],
        encoded_signature: &[u8]
    ) -> bool;
fn signature_output_size(&self) -> usize; }
Expand description

A signer 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 itsdangerous::{default_builder, Signer};

// 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!");

Required methods

Signs the given string.

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.

Given a base-64 encoded signature, attempt to verify whether or not it is valid for the given value.

Gets the output size in bytes of the base-64 encoded signature part that this signer will emit.

Implementors