|
JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
|
Implements Base64URL (RFC 4648 §5) — the URL-safe variant of Base64. More...
Functions | |
| std::string | encode (const std::uint8_t *data, std::size_t len, bool pad=false) |
| Encode raw binary data into a Base64URL string. | |
| std::vector< std::uint8_t > | decode (const std::string &input) |
| Decode a Base64URL string into a byte vector. | |
| jh::pod::bytes_view | decode (const std::string &input, std::vector< std::uint8_t > &output_buffer) |
| Decode a Base64URL-encoded string into raw bytes. | |
| jh::pod::string_view | decode (const std::string &input, std::string &output_buffer) |
| Decode a Base64URL-encoded string into textual data. | |
Implements Base64URL (RFC 4648 §5) — the URL-safe variant of Base64.
Base64URL replaces '+' with '-' and '/' with '_' to ensure safe embedding in URLs and filenames without escaping.
This variant supports both padded (=) and non-padded forms. Non-padded encoding is the default behavior to comply with JWT and modern web APIs.
|
nodiscard |
Decode a Base64URL string into a byte vector.
| input | Base64URL string (with or without padding). |
| std::runtime_error | if input is not valid Base64URL. |
| jh::pod::string_view jh::serio::base64url::decode | ( | const std::string & | input, |
| std::string & | output_buffer ) |
Decode a Base64URL-encoded string into textual data.
This overload operates in string mode.
| input | Base64URL-encoded input string (padded or non-padded). |
| output_buffer | Output buffer storing the decoded string. |
jh::pod::string_view referencing the decoded text.output_buffer. string_view: operator[](std::uint64_t index) — direct character access (no bounds checking). sub(std::uint64_t offset, std::uint64_t length = 0) — create a substring view. compare(const string_view &rhs) — perform lexical comparison (similar to strcmp). starts_with(const string_view &prefix) — check if the view starts with the specified prefix. ends_with(const string_view &suffix) — check if the view ends with the specified suffix. find(char ch) — locate the first occurrence of a character; returns -1 if not found. hash(jh::meta::c_hash hash_method = jh::meta::c_hash::fnv1a64) — compute a stable 64-bit hash of the contents. operator std::string_view() or to_std() — explicit conversion to std::string_view for interoperability. operator<=>(const string_view &rhs) — perform lexicographical three-way comparison (returns std::strong_ordering). | jh::pod::bytes_view jh::serio::base64url::decode | ( | const std::string & | input, |
| std::vector< std::uint8_t > & | output_buffer ) |
Decode a Base64URL-encoded string into raw bytes.
This overload operates in byte mode.
| input | Base64URL-encoded input string (padded or non-padded). |
| output_buffer | Output buffer storing the decoded bytes. |
jh::pod::bytes_view referencing the decoded data.output_buffer. bytes_view: at<T>(offset = 0) — reinterpret a subregion as a reference to T (no bounds checking). fetch<T>(offset = 0) — safely fetch a pointer to T; returns nullptr if out of range. clone<T>() — clone the entire view into a value of type T; returns T{} on size mismatch. hash(jh::meta::c_hash hash_method = jh::meta::c_hash::fnv1a64) — compute a 64-bit hash of the byte content.
|
nodiscard |
Encode raw binary data into a Base64URL string.
| data | Pointer to input buffer. |
| len | Length of input buffer. |
| pad | Whether to include '=' padding (default: false). |
| std::invalid_argument | if data is null and len > 0. |
pad = false, the output omits trailing '=' characters.