BeNu
Simple & Compact Binary Credentials
Fields
| Name |
Flag |
Type |
Description |
TYP |
0x1 |
byte |
The type of the token (e.g. user or session) |
SUBJECT |
0x2 |
data |
The subject of the token |
INCREMENT |
0x4 |
int |
An increment for invalidating tokens |
BEFORE |
0x8 |
int |
When the token expires |
AFTER |
0x10 |
int |
When the token is valid from |
DATA |
0x20 |
data |
Defined token claims |
SALT |
0x40 |
data |
An pinch of extra salt (why not?) |
Usage
use std::time::Duration;
use crate::signed::SignedToken;
use crate::{Header, Token};
let key = [0u8; 32];
let token = Token::builder()
.typ(0x01)
.subject("Sam")
.data("Hello World!")
.before(Duration::from_secs(300));
println!("{:?}", token);
let token = token
.seal()
.sign(key.as_ref());
println!("{:?} -> {:?}", token.len(), token);
let token = SignedToken::decode(&token).unwrap()
.verify(&key.as_ref()).unwrap()
.require(Header::TYP | Header::SUBJECT | Header::DATA | Header::BEFORE).unwrap()
.match_typ(0x01).unwrap()
.validate().unwrap()
.unseal();
println!("{:?}", token.subject().unwrap().as_str());