1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! JWT verification engine — single entry point per STANDARDS_JWT_DETAILS §3.
//!
//! Every JWT verification flow in the workspace MUST funnel through
//! [`verify`]. Direct calls to `jsonwebtoken::decode` / `decode_header`
//! from outside this module are forbidden (M51/M52 lint, enforced in
//! Phase 7).
//!
//! Module layout reflects the per-area `check_*` discipline (D-09):
//!
//! - `check_algorithm` — M01-M06 (alg whitelist + per-request pinning)
//! - `check_header` — M07-M16a (jku/x5u/jwk/x5c/crit/kid/typ/cty/JWE/extras/b64)
//! - `check_claims` — M17-M30 + M32 (claims required/value + JSON dup keys)
//! - `check_domain` — M39-M45 (ppoppo-specific domain rules) [Phase 4]
//! - `check_replay` — M35 (jti replay-cache enforcement) [Phase 5]
//! - `check_session` — M36 (session-row liveness via sid) [Phase 5]
//! - `check_epoch` — sv-port (per-account session_version) [Phase 5]
//! - `raw` — base64url + JSON parsing helpers (M32 + M33)
//! Phase 2 wires signature verification implicitly via `check_claims`'s
//! payload parse; the dedicated cryptographic verification step lands
//! when the `jsonwebtoken::decode` integration ships in Phase 6 cutover.
pub
pub
pub
pub
pub
pub
pub
pub
pub
use crate::;
/// Verify a JWS Compact-serialized token against the configured policy.
///
/// Returns `Ok(claims)` when every active mitigation (Phase 2: M01-M34
/// minus replay/revocation) passes — the validated `Claims` payload is
/// the engine's contract with downstream consumers (audit logs, audit
/// resolvers, per-client rate limits).
///
/// Returns the **first** failing `AuthError` variant. Order matters:
/// cheaper structural checks fire before signature verification so a
/// malformed token never reaches the crypto path. Audit logs treat the
/// variant as the mitigation ID; do not swallow or remap.
///
/// `async fn` shape is locked in (D-11) so Phase 5 can add a replay-cache
/// trait parameter without rippling a sync→async change through every
/// call site.
///
/// ── M38 invariant: transport-blind by signature ─────────────────────────
///
/// `token` MUST be the bare JWS Compact string — three base64url-encoded
/// segments separated by `.` — with NO transport wrapper. The engine
/// does not strip `"Bearer "` prefixes, cookie attributes (`access_token=
/// ...; Path=/; Secure`), URL encoding, or any other framing.
/// Extraction from the wire is the *consumer middleware's*
/// responsibility — chat-auth, pas-external, and any future RP must
/// produce a bare token before calling `verify`.
///
/// This invariant is what STANDARDS_JWT_DETAILS_MITIGATION §E M38 codifies
/// as "Cookie + Bearer header treated as the same surface". The engine
/// achieves it *structurally*: the function signature carries no
/// transport hint, and no `check_*` submodule reads anything beyond
/// `(token, cfg, key_set)`. Adding a `transport_hint: Transport`
/// parameter — or any path-dependent branch inside `verify` — would
/// break M38 and require re-evaluating the test in
/// `tests/transport_equivalence.rs`.
pub async
/// Issue a signed Compact JWS for the given request + config + key.
///
/// Mirrors `verify` on the issuance side. Order of operations:
///
/// 1. **kid match** — fail-fast on a misconfigured pipeline before any
/// encoding work. The `KeyMismatch` audit signal carries both kids
/// so operators can diagnose without a debugger.
/// 2. **clock sanity** — refuse to emit if `now()` is before UNIX_EPOCH
/// (cannot happen on a correctly configured machine; the check
/// exists so the engine fails closed rather than emitting garbage
/// timestamps).
/// 3. **payload assembly** via `encode::IssuePayload::build`.
/// 4. **header construction** — pin `alg=EdDSA`, `typ=cfg.typ` (`at+jwt`
/// for access), `kid=cfg.kid`. Forbidden headers (`jku`/`x5u`/`jwk`/
/// `x5c`/`crit`/extras) are never set; the invariant test in
/// `tests/issue_invariants.rs::issue_emits_only_alg_typ_kid_in_header`
/// is the regression guard.
/// 5. **encode** via `jsonwebtoken::encode` — the only call site for
/// `jsonwebtoken::*` on the issue path; the M51 "no jsonwebtoken
/// outside engine/" lint accommodates this single use site.
///
/// `issue` stays sync (D-11): no I/O on the issuance path.