reallyme_jose/lib.rs
1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! JOSE, JWT, and JWS helpers.
6//!
7//! `reallyme-jose` owns JOSE byte-format mechanics for compact JWS, JWT, and
8//! JWE. Cryptographic operations are routed through `reallyme-crypto`; this
9//! crate adds JOSE header policy, compact serialization, algorithm/key binding,
10//! temporal JWT policy, and JWE content-encryption handling.
11//!
12//! # Example
13//!
14//! ```
15//! use reallyme_jose::jwt::{decode_unsigned_jwt, encode_unsigned_jwt};
16//!
17//! let claims = serde_json::json!({
18//! "iss": "did:me:issuer",
19//! "sub": "alice",
20//! });
21//! let compact = encode_unsigned_jwt(&claims)?;
22//! let decoded: serde_json::Value = decode_unsigned_jwt(&compact)?;
23//!
24//! assert_eq!(decoded.get("sub"), Some(&serde_json::json!("alice")));
25//! # Ok::<(), reallyme_jose::jwt::JwtError>(())
26//! ```
27//!
28//! Unsigned JWT decoding is a parser for profiles that explicitly allow
29//! `alg = "none"`; it does not authenticate the sender. Use the signed JWT
30//! verification APIs for verifier-grade paths.
31
32#[cfg(not(any(feature = "native", feature = "wasm")))]
33compile_error!("reallyme-jose requires a supported runtime lane: enable feature `native` for audited Rust crypto or `wasm` for the WebAssembly host-provider lane.");
34
35/// Crypto algorithm selector used by JOSE/JWT public APIs.
36///
37/// Consumers should import this re-export instead of depending directly on
38/// `reallyme-crypto`; that keeps the algorithm type identical to the one used
39/// by `reallyme-jose`.
40#[cfg(any(feature = "native", feature = "wasm"))]
41pub use reallyme_crypto::{core::Algorithm, csprng::SecureRandom, jwk::Jwk, signer::Signer};
42
43/// JSON value type used by claim maps and protected-header values.
44#[cfg(any(feature = "native", feature = "wasm"))]
45pub use serde_json::Value as JsonValue;
46
47/// Zeroizing owner used for decrypted plaintext and derived CEK bytes.
48#[cfg(any(feature = "native", feature = "wasm"))]
49pub use zeroize::Zeroizing;
50
51#[cfg(any(feature = "native", feature = "wasm"))]
52pub mod jwe;
53#[cfg(any(feature = "native", feature = "wasm"))]
54pub mod jws;
55#[cfg(any(feature = "native", feature = "wasm"))]
56pub mod jwt;
57#[cfg(all(any(feature = "native", feature = "wasm"), feature = "wire"))]
58pub mod wire;