Shared utilities for the security subsystem. Decode a base64url-encoded string (no padding required). Handles the URL-safe alphabet (`-` and `_`) and adds padding as needed. Used across JWT validation, JWKS key parsing, and token introspection.
(input: &str)
| 7 | /// Handles the URL-safe alphabet (`-` and `_`) and adds padding as needed. |
| 8 | /// Used across JWT validation, JWKS key parsing, and token introspection. |
| 9 | pub fn base64_url_decode(input: &str) -> Option<Vec<u8>> { |
| 10 | let padded = match input.len() % 4 { |
| 11 | 2 => format!("{input}=="), |
| 12 | 3 => format!("{input}="), |
| 13 | _ => input.to_string(), |
| 14 | }; |
| 15 | let standard = padded.replace('-', "+").replace('_', "/"); |
| 16 | use base64::Engine; |
| 17 | base64::engine::general_purpose::STANDARD |
| 18 | .decode(&standard) |
| 19 | .ok() |
| 20 | } |