#pragma once #include #include #include #include #include #include #include #include // ADR-0131: a small, bounded JSON reader for access-token claims and the realm's JWKS. // It accepts RFC 8259 JSON within the bounds below and nothing else (no comments, no // trailing commas, no duplicate-key resolution beyond "first wins"). namespace evo::serialization { inline constexpr std::size_t max_json_bytes = std::size_t{16} * 1024; inline constexpr std::size_t max_json_depth = 16; class JsonValue { public: enum class Kind : std::uint8_t { null, boolean, number, string, array, object }; [[nodiscard]] Kind kind() const noexcept { return kind_; } // Typed views; nullopt or nullptr when the value has another kind. [[nodiscard]] std::optional boolean() const; [[nodiscard]] std::optional string() const; // Integers only (no fraction or exponent), within 0..2^63-1. [[nodiscard]] std::optional integer() const; [[nodiscard]] const JsonValue* member(std::string_view name) const; [[nodiscard]] const std::vector* array() const; // Whole-document parse; nullopt for anything malformed or out of bounds. `limit` bounds // the text: access tokens and keys keep the default; a service's answer may allow more. [[nodiscard]] static std::optional parse(std::string_view text, std::size_t limit = max_json_bytes); private: friend class JsonParser; Kind kind_{Kind::null}; bool boolean_{}; std::string text_; // String value, or the number's literal. std::vector items_; std::vector> members_; }; } // namespace evo::serialization