pub struct Rwt<T> {
pub payload: T,
/* private fields */
}Expand description
Represents a web token.
For optimal usage, your payload should be any struct implementing Serialize, Deserialize,
and FromStr, but none of these are technically required.
Fields§
§payload: TImplementations§
Source§impl<T: Serialize> Rwt<T>
impl<T: Serialize> Rwt<T>
Sourcepub fn with_payload<S: AsRef<[u8]>>(payload: T, secret: S) -> Result<Rwt<T>>
pub fn with_payload<S: AsRef<[u8]>>(payload: T, secret: S) -> Result<Rwt<T>>
Create a web token with the provided payload.
This function requires that the payload be Serialize.
Sourcepub fn encode(&self) -> Result<String>
pub fn encode(&self) -> Result<String>
Encode the token as base64 in the usual format.
In this case, “the usual format” means xxx.xxx where the left hand side is the token
itself and the right hand side is the signature. The base64 implementation used currently
introduces padding into the equation.
Sourcepub fn is_valid<S: AsRef<[u8]>>(&self, secret: S) -> bool
pub fn is_valid<S: AsRef<[u8]>>(&self, secret: S) -> bool
Validate the token.
This function compares the token as serialized against a freshly-derived signature to
ensure that it is original and un-tampered-with. This version uses rust-crypto to
compare the two results in order to protect against timing attacks.