jaws/
lib.rs

1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2#![cfg_attr(all(feature = "rsa", feature = "fmt"), doc = include_str!("../README.md"))]
3#![cfg_attr(
4    not(all(feature = "rsa", feature = "fmt")),
5    doc = "# JAWS: JSON Web tokens
6
7JSON Web Tokens are used to send signed, authenticated and/or encrypted data using
8a JavaScript Object Notation (JSON) object. This crate provides a strongly typed
9interface for creating and validating [JWTs][JWT], built on top of the [RustCrypto][]
10ecosystem.
11
12
13[RustCrypto]: https://github.com/RustCrypto
14[JWT]: https://tools.ietf.org/html/rfc7519
15"
16)]
17//! # Working with dyn Keys (supporting multiple algorithms)
18//!
19//! This crate supports working with multiple different types of keys simultaneously.
20//! Most of the traits are designed to be object-safe when used with the [`Token`] type,
21//! so that they can be used with a single type-erased key type.
22//!
23//! RustCrypto [signature](https://docs.rs/signature/latest/signature/) signing and
24//! verifying traits are generic over the signature type, to allow for optimizations
25//! from specific signature algorithms to be used when desired. When using a type-erased
26//! keys, this is not possible, so the [`TokenSigner`] and [`TokenVerifier`] traits are
27//! also designed to work with the [`SignatureBytes`] type, which is a type-erased
28//! signature type.
29//!
30//! ```rust
31//! use jaws::algorithms::SignatureBytes;
32//! use jaws::algorithms::TokenSigner;
33//! use jaws::algorithms::TokenVerifier;
34//!
35//! type Signer = Box<dyn TokenSigner<SignatureBytes>>;
36//! type Verifier = Box<dyn TokenVerifier<SignatureBytes>>;
37//!
38//! ```
39
40#![deny(unsafe_code)]
41#![deny(missing_docs)]
42#![deny(clippy::self_named_module_files)]
43#![deny(clippy::dbg_macro)]
44
45pub mod algorithms;
46pub mod base64data;
47pub mod claims;
48
49#[cfg(feature = "fmt")]
50pub mod fmt;
51
52pub mod jose;
53pub mod key;
54mod numeric_date;
55pub mod token;
56
57pub use algorithms::{SignatureBytes, TokenSigner, TokenVerifier};
58pub use claims::{Claims, RegisteredClaims};
59#[cfg(feature = "fmt")]
60pub use fmt::JWTFormat;
61pub use token::Token;
62pub use token::{Compact, Flat, FlatUnprotected};
63
64/// Module for re-exports of related crates
65///
66/// Use these aliases to access related traits and types.
67pub mod crypto {
68    pub use digest;
69    #[cfg(feature = "ecdsa")]
70    pub use ecdsa;
71    #[cfg(feature = "p256")]
72    pub use p256;
73    #[cfg(feature = "p384")]
74    pub use p384;
75    #[cfg(feature = "p521")]
76    pub use p521;
77    pub use pkcs8;
78    #[cfg(feature = "rand")]
79    pub use rand_core;
80    #[cfg(feature = "rsa")]
81    pub use rsa;
82    pub use sha2;
83    pub use signature;
84}