rusty_paseto

A type-driven, ergonomic implementation of the PASETO protocol for secure stateless tokens.

PASETO: Platform-Agnostic Security Tokens

Paseto is everything you love about JOSE (JWT, JWE, JWS) without any of the many design deficits that plague the JOSE standards.

unit tests GitHub

Roadmap and Current Feature Status

| APIs, Tests & Documentation | v1.
local| v1.
public | v2.
local | v2.
public |v3.
local | v3.
public | v4.
local | v4.
public | | ------------: | :-----------: | :----------: |:-----------: |:-----------: |:-----------: |:-----------: |:-----------: |:-----------: | | PASETO Token Builder | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | PASETO Token Parser | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Flexible Claim Validation | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Generic Token Builder | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Generic Token Parser | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Encryption/Signing | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Decryption/Verification | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | PASETO Test vectors | [x] | [x] | [x] | [x] | [x] | [ ] | [x] | [x] | | Documentation | [ ] | [ ] | [ ] | [ ] | [ ] | [ ] | [ ] | [ ] |

| Feature | Status | | ------------: | :-----------: |
| Feature gates | [x] | | PASERK support | [ ] |

# Usage rustypaseto is meant to be flexible and configurable for your specific use case. Whether you want to get started quickly with sensible defaults, create your own version of rustypaseto in order to customize your own defaults and functionality or just want to use the core PASETO crypto features, the crate is heavily feature gated to allow for your needs.

## Architecture

The rustypaseto crate architecture is composed of three layers (batteriesincluded, generic and core) which can be further refined by the PASETO version(s) and purpose(s) required for your needs. All layers use a common crypto core which includes various cipher crates depending on the version and purpose you choose. The crate is heavily featured gated to allow you to use only the versions and purposes you need for your app which minimizes download compile times for using rusty_paseto. A description of each architectural layer, their uses and limitations and how to minimize your required dependencies based on your required PASETO version and purpose follows:

paseto<em>batteries</em>included<em>small paseto</em>generic<em>small paseto</em>core_small

batteries_included --> generic --> core

### default The default feature is the quickest way to get started using rusty_paseto.

paseto<em>default</em>small

The default feature includes the outermost architectural layer called batteries_included (described below) as well as the two latest PASETO versions (V3 - NIST MODERN, V4 - SODIUM MODERN) and the Public (Asymmetric) and Local (Symmetric) purposed key types for each of these versions. That should be four specific version and purpose combinations however at the time of this writing I have yet to implement the V3 - Public combination, so there are 3 in the default feature. Additionally, this feature includes JWT style claims and business rules for your PASETO token (default, but customizable expiration, issued at, not-before times, etc as described in the usage documentation and examples further below).

```toml ## Includes V3 (local) and V4 (local, public) versions, purposes and ciphers.

rustypaseto = "latest" // at the top of your source file use rustypaseto::prelude::*; ```

### batteries_included

The outermost architectural layer is called batteries_included. This is what most people will need. This feature includes JWT style claims and business rules for your PASETO token (default, but customizable expiration, issued at, not-before times, etc as described in the usage documentation and examples below).

paseto<em>batteries</em>included_small

You must specify a version and purpose with this feature in order to reduce the size of your dependencies like in the following Cargo.toml entry which only includes the V4 - Local types with batteries_included functionality:

```toml ## Includes only v4 modern sodium cipher crypto core and local (symmetric) ## key types with all claims and default business rules.

rustypaseto = {version = "latest", features = ["batteriesincluded", "v4local"] } ``` paseto</em>batteries<em>included</em>v4<em>local</em>small

#### Feature gates Valid version/purpose feature combinations are as follows: - "v1local" (NIST Original Symmetric Encryption) - "v2local" (Sodium Original Symmetric Encryption) - "v3local" (NIST Modern Symmetric Encryption) - "v4local" (Sodium Modern Symmetric Encryption) - "v1public" (NIST Original Asymmetric Authentication) - "v2public" (Sodium Original Asymmetric Authentication) - "v3_public" (NIST Modern Asymmetric Authentication) - NOT YET IMPLEMENTED - "v4_public" (Sodium Modern Asymmetric Authentication)

// at the top of your source file use rusty_paseto::prelude::*; ### generic

The generic architectural and feature layer allows you to create your own custom version of the batteries_included layer by following the same pattern I've used in the source code to create your own custom builder and parser. This is probably not what you need as it is for advanced usage. The feature includes a generic builder and parser along with claims for you to extend.

paseto<em>generic</em>small

It includes all the PASETO and custom claims but allows you to create different default claims in your custom builder and parser or use a different time crate or make up your own default business rules. As with the batteriesincluded layer, parsed tokens get returned as a serderjson Value. Again, specify the version and purpose to include in the crypto core:

```toml ## Includes only v4 modern sodium cipher crypto core and local (symmetric) ## key types with all claims and default business rules.

rustypaseto = {version = "latest", features = ["generic", "v4local"] } // at the top of your source file use rusty_paseto::generic::*; ``` ### core

The core architectural layer is the most basic PASETO implementation as it accepts a Payload, optional Footer and (if v3 or v4) an optional Implicit Assertion along with the appropriate key to encrypt/sign and decrypt/verify basic strings.

paseto<em>core</em>small

There are no default claims or included claim structures, business rules or anything other than basic PASETO crypto functions. Serde crates are not included in this feature so it is extremely lightweight. You can use this when you don't need JWT-esque functionality but still want to leverage the safe cipher combinations and algorithm lucidity afforded by the PASETO specification.

```toml ## Includes only v4 modern sodium cipher crypto core and local (symmetric) ## key types with NO claims, defaults or validation, just basic PASETO ## encrypt/signing and decrypt/verification.

rustypaseto = {version = "latest", features = ["core", "v4local"] } ```

# Examples

## Building and parsing tokens with batteries_included

Here's a basic, default token: ```rust use rusty_paseto::prelude::*;

// create a key specifying the PASETO version and purpose let key = PasetoSymmetricKey::::from(Key::from(b"wubbalubbadubdubwubbalubbadubdub")); // use a default token builder with the same PASETO version and purpose let token = PasetoBuilder::::default().build(&key)?; // token is a String in the form: "v4.local.encoded-payload"

```

## A default token

Questions?

File an issue or hit me up on Twitter!