Crates.io | tenet |
lib.rs | tenet |
version | 0.0.4 |
source | src |
created_at | 2022-01-14 16:11:14.270478 |
updated_at | 2022-01-15 14:23:43.274468 |
description | A godawful JWT implementation |
homepage | |
repository | https://github.com/samhdev/tenet |
max_upload_size | |
id | 513934 |
size | 54,652 |
A godawful jwt implementation
[dependencies.jwt]
package="tenet"
version = "*"
features = ["HS256"]
This library is slow, baldly implemented and took a total of 20 minutes to write and bug check.
You are much better off using another tried and tested JWT implementation:
Why does it exist? I got fed up with shitty API design around signing and verifying tokens.
This library has two token types:
Token<T>
)SignedToken
)Token algorithms are decided by a enum: TokenAlgorithm
HS256
HS512
use serde::{Serialize, Deserialize};
use jwt::{Token, TokenAlgorithm, SignedToken};
// Create a new token type.
// This uses serde's Serialize and Deserialize procedural macros.
#[derive(Serialize, Deserialize, Debug)]
struct MyToken {
foo: u8,
bar: bool,
baz: String,
}
// create a key to sign and verify tokens.
let token_key = b"VERY_SECURE_KEY".to_vec();
// create a new token, sign it, and get the string representation
let token = Token::create(
TokenAlgorithm::HS256,
MyToken { foo: 10, bar: true, baz: "Hello World".to_string() }
)
.sign(&token_key).unwrap().string();
println!("{}", token);
// verify a token input
let payload = Token::<MyToken>::verify(token, &token_key).unwrap();
println!("{:?}", payload);