All Projects → slowli → jwt-compact

slowli / jwt-compact

Licence: Apache-2.0 license
Compact JWT implementation in Rust

Programming Languages

rust
11053 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jwt-compact

Borer
Efficient CBOR and JSON (de)serialization in Scala
Stars: ✭ 131 (+403.85%)
Mutual labels:  cbor
restish
Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
Stars: ✭ 453 (+1642.31%)
Mutual labels:  cbor
Number-Theory-Python
Python code to implement various number theory, elliptic curve and finite field computations.
Stars: ✭ 85 (+226.92%)
Mutual labels:  elliptic-curves
Libcbor
CBOR protocol implementation for C
Stars: ✭ 215 (+726.92%)
Mutual labels:  cbor
btclib
btclib: a Python3 library for 'bitcoin cryptography'
Stars: ✭ 16 (-38.46%)
Mutual labels:  elliptic-curves
crypto-in-action
algebra arithmetic, finite fields, elliptic curves, zero-knowledge
Stars: ✭ 65 (+150%)
Mutual labels:  elliptic-curves
Rpc.py
A fast and powerful RPC framework based on ASGI/WSGI.
Stars: ✭ 98 (+276.92%)
Mutual labels:  cbor
bulletproofs
Bulletproofs and Bulletproofs+ Rust implementation for Aggregated Range Proofs over multiple elliptic curves
Stars: ✭ 62 (+138.46%)
Mutual labels:  elliptic-curves
h2c-rust-ref
Hash to curves - Rust reference implementation
Stars: ✭ 21 (-19.23%)
Mutual labels:  elliptic-curves
keystore-idb
In-browser key management with IndexedDB and the Web Crypto API
Stars: ✭ 37 (+42.31%)
Mutual labels:  elliptic-curves
Jackson Dataformats Binary
Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Stars: ✭ 221 (+750%)
Mutual labels:  cbor
Cbor
CBOR RFC 7049 (Go/Golang) - safe & fast with standard API + toarray & keyasint, CBOR tags, float64/32/16, fuzz tested.
Stars: ✭ 250 (+861.54%)
Mutual labels:  cbor
cryptotools
No description or website provided.
Stars: ✭ 182 (+600%)
Mutual labels:  elliptic-curves
Libxo
The libxo library allows an application to generate text, XML, JSON, and HTML output using a common set of function calls. The application decides at run time which output style should be produced.
Stars: ✭ 185 (+611.54%)
Mutual labels:  cbor
libgoldilocks
An implementation of Mike Hamburg's Ed448 (Goldilocks) curve - derived from libdecaf. This is a mirror of https://bugs.otr.im/otrv4/libgoldilocks
Stars: ✭ 17 (-34.62%)
Mutual labels:  elliptic-curves
Kripton
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.
Stars: ✭ 110 (+323.08%)
Mutual labels:  cbor
curves
Implementations of popular elliptic curves
Stars: ✭ 229 (+780.77%)
Mutual labels:  elliptic-curves
jubjub
Supporting evidence for security of the Jubjub curve to be used in Zcash
Stars: ✭ 13 (-50%)
Mutual labels:  elliptic-curves
fs2-data
streaming data parsing and transformation library
Stars: ✭ 103 (+296.15%)
Mutual labels:  cbor
ECTester
Tests support and behavior of elliptic curve cryptography implementations on JavaCards (TYPE_EC_FP and TYPE_EC_F2M) and in selected software libraries.
Stars: ✭ 51 (+96.15%)
Mutual labels:  elliptic-curves

Compact JWT implementation in Rust

Build Status License: Apache-2.0 rust 1.60+ required no_std supported

Documentation: Docs.rs crate docs (master)

Minimalistic JSON web token (JWT) implementation with focus on type safety and secure cryptographic primitives.

Usage

Add this to your Crate.toml:

[dependencies]
jwt-compact = "0.6.0"

Basic token lifecycle

use chrono::{Duration, Utc};
use jwt_compact::{prelude::*, alg::{Hs256, Hs256Key}};
use serde::{Serialize, Deserialize};

/// Custom claims encoded in the token.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct CustomClaims {
    #[serde(rename = "sub")]
    subject: String,
    // other fields...
}

// Choose time-related options for token creation / validation.
let time_options = TimeOptions::default();
// Create a symmetric HMAC key, which will be used both to create and verify tokens.
let key = Hs256Key::new(b"super_secret_key_donut_steel");
// Create a token.
let header = Header::default().with_key_id("my-key");
let claims = Claims::new(CustomClaims { subject: "alice".to_owned() })
    .set_duration_and_issuance(&time_options, Duration::hours(1))
    .set_not_before(Utc::now());
let token_string = Hs256.token(header, &claims, &key)?;
println!("token: {}", token_string);

// Parse the token.
let token = UntrustedToken::new(&token_string)?;
// Before verifying the token, we might find the key which has signed the token
// using the `Header.key_id` field.
assert_eq!(token.header().key_id.as_deref(), Some("my-key"));
// Validate the token integrity.
let token: Token<CustomClaims> = Hs256.validate_integrity(&token, &key)?;
// Validate additional conditions.
token.claims()
    .validate_expiration(&time_options)?
    .validate_maturity(&time_options)?;
Ok::<_, anyhow::Error>(())

See the crate docs for more examples of usage.

Features

  • Algorithm-specific signing and verifying keys (i.e., type safety).
  • Key strength requirements from RFC 7518 are expressed with wrapper types.
  • Easy to extend to support new signing algorithms.
  • The crate supports more compact CBOR encoding of the claims.
  • Basic JWK functionality for key conversion from human-readable formats (JSON / YAML / TOML) and computing key thumbprints.
  • HS256, HS384 and HS512 algorithms are implemented via pure Rust sha2 crate.
  • The crate supports EdDSA algorithm with the Ed25519 elliptic curve, and ES256K algorithm with the secp256k1 elliptic curve. Both curves are widely used in crypto community and believed to be securely generated (there are some doubts about parameter generation for elliptic curves used in standard ES* algorithms).
  • The ES256 algorithm is supported via pure Rust p256 crate.
  • RSA algorithms (RS* and PS*) are supported via pure Rust rsa crate.
  • The crate supports the no_std mode. No-std support and WASM compatibility are explicitly tested.

Missing features

  • Built-in checks of some claims (e.g., iss – the token issuer). This is intentional: depending on the use case, such claims can have different semantics and thus be represented by different datatypes (e.g., iss may be a human-readable short ID, a hex-encoded key digest, etc.)
  • ES384 and ES512 algorithms.

Alternatives

jsonwebtoken, frank_jwt or biscuit may be viable alternatives depending on the use case (e.g., none of them seems to implement EdDSA or ES256K algorithms).

See also

  • justwebtoken.io – educational mini-website that uses this library packaged in a WASM module.

License

Licensed under the Apache-2.0 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].