benu 0.0.1-rc2

compact binary signed tokens
Documentation
  • Coverage
  • 18.52%
    5 out of 27 items documented4 out of 4 items with examples
  • Size
  • Source code size: 35.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.02 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SamHDev

BeNu

Simple & Compact Binary Credentials

Not Done

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};

// define key
let key = [0u8; 32];

// build the token
let token = Token::builder()
    .typ(0x01)
    .subject("Sam")
    .data("Hello World!")
    .before(Duration::from_secs(300));

println!("{:?}", token);

// seal and sign the token with the key
let token = token
    .seal()
    .sign(key.as_ref());

    println!("{:?} -> {:?}", token.len(), token);

// create a signed token
let token = SignedToken::decode(&token).unwrap()
    // verify the token with the key
    .verify(&key.as_ref()).unwrap()

    // require typ, subject, data.
    .require(Header::TYP | Header::SUBJECT | Header::DATA | Header::BEFORE).unwrap()

    // check the token is of the given type
    .match_typ(0x01).unwrap()

    // validate before time
    .validate().unwrap()

// unseal the token
.unseal();

// get the subject field
println!("{:?}", token.subject().unwrap().as_str());