Function sign_with_jwt

Source
pub fn sign_with_jwt<T: Serialize>(
    value: T,
    secret: &[u8],
) -> Result<String, LangsError>
Expand description

Signs the given serializable value with the given secret using JWT.

§Example

#[derive(serde::Serialize)]
struct TestResult {
    passed: bool,
}

let token = tmc_langs::sign_with_jwt(TestResult { passed: true }, "secret".as_bytes()).unwrap();
assert_eq!(token, "eyJhbGciOiJIUzI1NiJ9.eyJwYXNzZWQiOnRydWV9.y-jXHgxZ_5wRqursLTb1hJOYob6LKj0mYBPnZSGtsnU");

§Errors

Should never fail, but returns an error to be safe against changes in external libraries.