jwtiny 1.8.2

Minimal JWT validation library for build web services
Documentation
//! Size limit constants for input validation

/// Maximum length for a JWT token string (64KB)
pub(crate) const MAX_TOKEN_LENGTH: usize = 64 * 1024;

/// Maximum length for issuer URLs (2048 characters)
pub(crate) const MAX_ISSUER_URL_LENGTH: usize = 2048;

/// Maximum length for JWKS URIs (2048 characters)
pub(crate) const MAX_JWKS_URI_LENGTH: usize = 2048;

/// Maximum size for OIDC discovery response (64KB)
pub(crate) const MAX_DISCOVERY_RESPONSE_SIZE: usize = 64 * 1024;

/// Maximum size for JWKS response (512KB)
pub(crate) const MAX_JWKS_RESPONSE_SIZE: usize = 512 * 1024;

/// Maximum size for decoded JWT header JSON (8KB)
/// Headers are typically small (< 1KB), but we allow reasonable margin
pub(crate) const MAX_DECODED_HEADER_SIZE: usize = 8 * 1024;

/// Maximum size for decoded JWT payload JSON (64KB)
/// Payloads can contain custom claims, but must be bounded to prevent DoS
pub(crate) const MAX_DECODED_PAYLOAD_SIZE: usize = 64 * 1024;

/// Maximum size for decoded signature bytes (1KB)
/// RSA signatures are typically 256-512 bytes
/// ECDSA signatures vary by curve: P-256 (~64 bytes), P-384 (~96 bytes), P-521 (~132 bytes)
pub(crate) const MAX_DECODED_SIGNATURE_SIZE: usize = 1024;

/// Maximum size for Base64URL-encoded signature string (1.5KB)
/// Base64URL encoding adds ~33% overhead, so 1KB decoded ≈ 1.3KB encoded
pub(crate) const MAX_SIGNATURE_B64_SIZE: usize = 1536;

/// Maximum size for RSA modulus (n) in bytes (4096 bytes)
/// For JWT/JWKS, practical RSA keys are 2048-4096 bits (256-512 bytes modulus)
pub(crate) const MAX_RSA_MODULUS_SIZE: usize = 4096;

/// Maximum size for Base64URL-encoded RSA modulus (n) field (12KB)
/// 8192-byte modulus (65536 bits) encodes to ~10.9KB Base64URL
pub(crate) const MAX_JWK_N_SIZE: usize = 12 * 1024;

/// Maximum size for Base64URL-encoded RSA exponent (e) field (64 bytes)
/// Standard exponent 65537 (0x010001) encodes to 4 bytes, but we allow margin
pub(crate) const MAX_JWK_E_SIZE: usize = 64;

/// Maximum size for JWK key ID (kid) field (256 bytes)
/// Key IDs are typically short identifiers, but must be bounded
pub(crate) const MAX_JWK_KID_SIZE: usize = 256;

/// Maximum size for JWK algorithm (alg) field (16 bytes)
/// Algorithm names are short (e.g., "RS256", "RS384", "RS512")
pub(crate) const MAX_JWK_ALG_SIZE: usize = 16;

/// Maximum size for JWK curve (crv) field (16 bytes)
/// Curve names are short (e.g., "P-256", "P-384", "P-521")
pub(crate) const MAX_JWK_CRV_SIZE: usize = 16;

/// Maximum size for Base64URL-encoded ECDSA x-coordinate field (128 bytes)
/// P-521 has 66-byte coordinates, encoding to ~88 bytes Base64URL
pub(crate) const MAX_JWK_X_SIZE: usize = 128;

/// Maximum size for Base64URL-encoded ECDSA y-coordinate field (128 bytes)
/// P-521 has 66-byte coordinates, encoding to ~88 bytes Base64URL
pub(crate) const MAX_JWK_Y_SIZE: usize = 128;

/// Minimum valid Unix timestamp (1970-01-01 00:00:00 UTC)
pub(crate) const MIN_TIMESTAMP: i64 = 0;

/// Maximum valid Unix timestamp (2100-01-01 00:00:00 UTC)
/// 4102444800 seconds since Unix epoch
pub(crate) const MAX_TIMESTAMP: i64 = 4_102_444_800;

/// Maximum length for algorithm (alg) field in JWT header (16 bytes)
/// Algorithm names are short (e.g., "RS256", "RS384", "RS512")
pub(crate) const MAX_ALG_LENGTH: usize = 16;

/// Maximum length for key ID (kid) field in JWT header (256 bytes)
/// Key IDs are typically short identifiers, but must be bounded
pub(crate) const MAX_KID_LENGTH: usize = 256;

/// Maximum clock skew tolerance (5 seconds)
pub(crate) const MAX_CLOCK_SKEW_SECONDS: u64 = 5;

/// Maximum token age (1 day = 86,400 seconds)
pub(crate) const MAX_MAX_AGE_SECONDS: u64 = 60 * 60 * 24;

/// Maximum length for cache keys (3KB)
pub(crate) const MAX_CACHE_KEY_LENGTH: usize = 3 * 1024;