Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9ef5821
codecs: a value codec may state max_decode_input_size, the longest in…
Dec 2, 2026
882c242
codecs: the decode bound's tests lint fix
Dec 2, 2026
1ae1f73
codecs: the decode bound's Doc Comments and tests tidied
Dec 2, 2026
9e5624d
codecs: over decodes a value in place under the inner value codec's d…
Dec 2, 2026
df262ad
codecs: over's decode bound tests lint fix
Dec 2, 2026
50f1dc8
codecs: over's decode bound tests and Doc Comments completed
Dec 2, 2026
bf02539
codecs: the constant-time path and the fuzz target of a value decoded…
Dec 2, 2026
bbdd036
codecs: the constant-time path of a value through over lint fix
Dec 2, 2026
99a8321
codecs: the over_value fuzz target's expected error set where it is k…
Dec 2, 2026
0bb6358
codecs: a library declares a value type's formats and its pairs' reas…
Dec 2, 2026
5c7a7a6
codecs: the declaration of a value type's formats lint fix
Dec 2, 2026
9d2aef2
codecs: a declaration's has_format and has_reason found on MSVC 14.3
Dec 2, 2026
1edeb26
codecs: the declaration's refusals, every kind through every form, an…
Dec 2, 2026
6a8b86c
codecs: basic_armor, the armor whose label is in its type, exactly as…
Dec 2, 2026
46a0edb
codecs: basic_armor lint fix
Dec 2, 2026
daa05d6
codecs: basic_armor's Doc Comments, one sentence in a brief and no @t…
Dec 2, 2026
15d6a09
codecs: basic_armor's codec probes cleanly for any label, pinned
Dec 2, 2026
704e49f
codecs: the page says how a library declares its value types' formats…
Dec 2, 2026
ebc244d
codecs: the declaration's refuse of the example is maybe_unused, wher…
Dec 2, 2026
249c071
codecs: the examples' value codecs name their buffer apart from the m…
Dec 2, 2026
3e85896
codecs: over_value's example lint fix
Dec 3, 2026
37fa60f
codecs: the page's fix round, a true changelog, the verbs and the mem…
Dec 3, 2026
e1dbeaf
codecs: the example's helpers in an anonymous namespace (lint)
Dec 3, 2026
ddf67f6
codecs: the example's point is public by intent (lint)
Dec 3, 2026
e3e0421
codecs: the example's library types are public by intent (lint)
Dec 3, 2026
bb53cfb
codecs: a declared byte input or byte result whose pair has a value c…
Dec 3, 2026
7b90996
codecs: the pages follow the headers (a declared type's refusals, bas…
Dec 3, 2026
bd32b89
codecs: composition_inner's type spelled one way, as an alias, which …
Dec 3, 2026
5c84360
codecs: encodable's and decodable's briefs one sentence each, the rul…
Dec 3, 2026
886df9a
codecs: value_formats_test pins declared_byte_result's encode forms too
Dec 3, 2026
4272f29
Merge origin/main (main-ci-fix) into codecs/one-verb
Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/allocators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ codecs allocates through it and through nothing else.
| `over` with a static bound
| nothing

| `over` with a bound that is not static
| `over` with a bound that is not static, a decode under a decode bound of at most 4096 bytes aside
| its allocator, for the intermediate

| the stream transformers of the native formats, `pipe`, `drain`, and `each` and `buffered` with `codecs::capacity<N>`
Expand Down Expand Up @@ -103,6 +103,11 @@ adds no handling.

* The allocator of `over` is for its intermediate alone. The allocator of a
token is for its result alone. Neither is the other's.
* The allocator of `over` is not used for a decode whose value codec states
a `max_decode_input_size` of at most 4096 bytes: its intermediate is in place,
whatever the text's type, and an input past the bound is `input_too_long` before
anything is made. A bound above 4096 bytes takes the intermediate, of the exact
size written, from the allocator.
* A `std::pmr::monotonic_buffer_resource` never gives memory back: an encode of a
megabyte through an arena of a kilobyte throws once, and a loop that reuses the
arena must release it.
Expand Down
4 changes: 2 additions & 2 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ of every version are on webcpp's index page.
=== Unreleased

// tag::unreleased[]
* Added codecs.hpp and config.hpp: encode, decode, tokens, results, secrecy and over, errors as values.
* Added codecs.hpp and config.hpp: encode, decode, tokens, results, secrecy and over, errors as values, value_formats for a library's value types, and max_decode_input_size as a value codec's bound on every path.
* Added the stream contract: one-shot and stream transformers, pipe, drain, each, buffered, encoder and decoder.
* Added hex.hpp: hex, constant time, streaming natively and decoding in place.
* Added base32.hpp: base32 and base32hex of RFC 4648, padding an option, constant time, streaming natively and decoding in place.
* Added base64.hpp: base64 and base64url of RFC 4648, canonical on decode, constant time, streaming natively and decoding in place.
* Added base58.hpp: basic_base58 with a bound, an alphabet and a checksum as parameters, constant time when secret, streaming through buffered.
* Added bech32.hpp: bech32 and bech32m with a maximum length, words and bytes data, constant time and streaming natively.
* Added percent.hpp: percent-encoding over Boost.URL with any CharSet, and the target percent, streaming natively.
* Added armor.hpp: RFC 7468's strict armor, composing over any bytes format, its payload constant time, streaming natively.
* Added armor.hpp: RFC 7468's strict armor, composing over any bytes format, its payload constant time, streaming natively, with basic_armor for a label in the type.
* Added the guide, with its examples built and run on every target.
// end::unreleased[]
49 changes: 44 additions & 5 deletions doc/composition.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,39 @@ The intermediate, the bytes between the two links, is held:
`std::span` of a static extent, a `secure::secret`, `text<N>`, `bytes<N>`) or
the value codec states `max_encoded_size`. There is no cap: the cost is the
stack, an array of the middle bound, the inner link's bound on the input's size
for an encode and the outer link's bound on the text's size for a decode, in
every level of a chain of chains;
* *on the heap*, from the allocator of `over`, for any other input. The third
for an encode and, for a decode, the smaller of the outer link's bound on the
text's size and the decode bound, in every level of a chain of chains;
* *in place, under a decode bound*, when the inner link is a value codec that
states `max_decode_input_size`, the longest input its `decode` accepts, and it
is at most 4096 bytes: the decode of a value then holds its intermediate in
place whatever the text's type, a `std::string_view` included, and allocates
nothing. The intermediate is an array of the smaller of that bound and the
outer link's bound on a text of a static size, when the text has one, and it
is refused past the bound with `input_too_long` before it is made (see
"Errors"). The program below is a record whose value codec states 12 bytes
encoded and 16 accepted, through the armor, decoded from a `std::string`;
* *on the heap*, from the allocator of `over`, for any other input: a decode
whose value codec states no decode bound, or one above 4096 bytes, takes it
from the allocator, of exactly the written size. The third
template parameter of `over` is that allocator, `std::allocator<std::uint8_t>` by default,
deduced from `over{outer, inner, allocator}`. A program that passes an input of a
static size and wants the intermediate on the heap passes it as a view of a
dynamic extent, a `std::span<std::uint8_t const>` or a `std::string_view`.
dynamic extent, a `std::span<std::uint8_t const>` or a `std::string_view`,
unless a decode bound of at most 4096 bytes holds it in place.

[source,cpp]
----
include::{examples}/over_value.cpp[tag=example,indent=0]
----

[listing]
----
include::{examples}/over_value.expected[]
----

The allocator of a result or a token is not the intermediate's, and the
allocator of `over` is used for nothing else. A heap intermediate makes the exact
allocator of `over` is used for nothing else, and not for a decode under a
decode bound of at most 4096 bytes. A heap intermediate makes the exact
`encoded_size` and `decoded_size`, which run the inner link into it, and
`encode` and `decode` allocate: those forms are not `noexcept`, an allocator's
exception reaches the caller, and on a secret chain every buffer is wiped
Expand All @@ -71,6 +94,17 @@ every form reports it before it reads any data, in either link: a chain with
refuses every form with `invalid_prefix`. A data error of either link is the chain's:
the decode of `414` in the program is the outer link's, hex, odd length.

A decode of a value reports its first error in this order: a fault of a link's
configuration; the outer link's own error, found over the whole text before
anything is written; then, for an exact size of the intermediate past the value
codec's `max_decode_input_size`, `input_too_long`, the error a direct decode of
that input gives, with nothing written, allocated or wiped and the value codec
not called; then the value codec's own error. A text whose payload is 17 bytes,
under a bound of 16, is `input_too_long` when its characters are valid, and the
outer link's `invalid_character` when one is not. `input_too_long` is the error of an
input past a value codec's bound whatever the path, the typed decode of bytes, the
typed decode of text and the call `over` makes of the value codec alike.

A fault a link's encode has (bech32 with no human-readable part, the armor with
no label, the format's `encode_fault`) is the chain's too, before any token is
prepared: the inner link's in every form, and the outer link's on the
Expand All @@ -86,6 +120,11 @@ own error.
of chains has one in each level's frame. A program that puts a large array
through `over` passes a view of a dynamic extent to move the intermediate to
the heap.
* A chain of chains is in place for a text of a dynamic size only at the level
whose inner link is a value codec that states a decode bound: the value codec
of `over` itself states none, because a link may accept a text longer than the
longest it writes (the armor's CRLF line ends), so the levels above it take
their intermediate from the allocator, unless the text's size is static.
* The inner link's output is bytes, and the outer reads them as bytes, whatever
the inner's text was. The armor over hex, as in the program of
<<codecs-armor>>, armors the hex text; a program that wants the armor of
Expand Down
18 changes: 18 additions & 0 deletions doc/formats.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,24 @@ A label given to the call that is longer than 64 characters or outside the
grammar is a fault of the configuration, `invalid_prefix` before anything is
read.

*A label that is in the type.* When the label follows from what the bytes are, as
a public key's does, a program names it in the type and holds no value that could
be wrong: `formats::basic_armor<Label>`, where `Label::value` is a
`std::string_view`, the label. It encodes what `formats::armor("PUBLIC KEY")`
encodes and decodes what that armor accepts, any other label being
`invalid_prefix`, and it streams, composes and keeps secrets as the armor does.
Its capacity is exact: the bound of `over{formats::basic_armor<Label>{}, inner}`
is the length of the armor of the inner's longest output under that one label,
where the bound of `armor_t` counts the longest label of 64 characters, so that the
default result of 138 bytes under `PRIVATE KEY` is a `text<241>` and not a
`text<347>`. Naming the type checks nothing; a use of it does, and a label that is
empty, longer than 64 characters or outside RFC 7468's grammar stops the build there.

[source,cpp]
----
include::{examples}/pem.cpp[tag=fixed_label,indent=0]
----

*Composition.* The armor is a format over bytes, so it composes:
`over{formats::armor("PRIVATE KEY"), inner}` armors the output of any bytes
format, as the last line of the program does (<<codecs-composition>>).
Expand Down
19 changes: 12 additions & 7 deletions doc/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typed decode gives the digest back as a `std::array`, and a fault is a value of
| no
| <<codecs-percent>>

| `armor`
| `armor`, `basic_armor<Label>`
| `<webcpp/codecs/armor.hpp>`
| its payload, always; its structure is public
| yes
Expand Down Expand Up @@ -123,15 +123,20 @@ The values are fixed and never reused:
| 5 | `invalid_prefix` | the human-readable part or the label is not the format's, or is a fault of the format's configuration
| 6 | `mixed_case` | a bech32 text holds both cases
| 7 | `output_too_small` | the buffer or the token's capacity is shorter than the result
| 8 | `input_too_long` | the input, or the result's bound, is longer than the format or the platform's `std::size_t` allows
| 8 | `input_too_long` | the input, or the result's bound, is longer than the format, a value codec's `max_decode_input_size` or the platform's `std::size_t` allows
|===

A text with several faults reports the one with the lowest value, so that the
error does not depend on where a decoder looked first. A fault of the format's
configuration, a bech32 human-readable part of 84 characters or an armor label
that is no label, is reported first, before any data is read, in every form: a
one-shot call and the first call of a stream. A value codec may return an error
code of its own library's category, which reaches the caller unchanged.
error does not depend on where a decoder looked first, but for the decode bound:
an input past a value codec's `max_decode_input_size` is `input_too_long` before
the value codec reads it, in place of the value codec's own errors of a lower
value, and a decode through `over` reports the outer link's errors first, then
the bound, then the value codec's own (<<codecs-composition>>). A fault of the
format's configuration, a bech32 human-readable part of 84 characters or an
armor label that is no label, is reported first, before any data is read, in
every form: a one-shot call and the first call of a stream. A value codec may
return an error code of its own library's category, which reaches the caller
unchanged.

[#codecs-exceptions]
=== Exceptions
Expand Down
8 changes: 7 additions & 1 deletion doc/results.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ Decoding a pair that does not exist, `decode<std::chrono::seconds>(formats::hex,
stops the build in a `static_assert` whose message names the format's `name`,
says that the format does not convert this type and says to include the format's
header or to specialize `value_codec`. The same refusal is given for a format
named without its header: the name is undeclared.
named without its header: the name is undeclared. A type that declares its formats
is refused by its declaration instead (<<codecs-writing-a-format>>): the library's
reason, the assertion that names the formats the type has, or the assertion that
the type lists the format and no value codec of the pair decodes it. An input the
pair does not read stops the build with an assertion that names the input's type:
a value codec of bytes given what is no byte input says that it decodes from bytes,
and one of text given what is no text says that it decodes from text.

=== The sizes, and the buffer forms

Expand Down
84 changes: 84 additions & 0 deletions doc/writing_a_format.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,90 @@ include::{examples}/own_format.cpp[tag=value_codec,indent=0]
A value codec's format works with `over` as an inner link: `over{nibbles, big_endian}`
encodes a `temperature` to bytes and then to letters.

*The decode bound.* A value codec may state `max_decode_input_size`, the
longest input its `decode` accepts, in the elements it reads (bytes, or
characters for a value codec of text). It is the value codec's acceptance
contract, and the core enforces it on every path of a decode, the typed
`decode<Value>` and the call `over` makes of the value codec alike: an input longer
than the bound is `input_too_long`, before the value codec is called, after the
format's configuration fault, and an input of exactly the bound reaches the
value codec. A format author pins it with a test that the largest valid input
decodes, since a bound below it refuses that input on every path. The bound is
never below `max_encoded_size` when both are stated: the value codec's decode
would refuse its own longest encoding, and the build stops. It is also what sizes
the intermediate of `over` when the value is decoded from a text of a dynamic
size: in place, with no heap, up to 4096 bytes. The program of
<<codecs-composition>> is a record that writes 12 bytes and accepts a form of 16,
and states 16.

=== Declaring a value type's formats

codecs' verbs, `encode`, `encoded_size` and `decode<Value>`, are every library's: a
library that owns a value type adds no verb of its own, and declares what its type has;
a member it keeps (`key.encode`, `Key::decode`) calls codecs' verbs, or
`codecs::check_conversion` when it is an entry point of its own. `codecs::value_formats<Value>` is
declared and never defined, like `value_codec`, and the library specializes it for
its type, fully, or by a partial specialization constrained by a concept for a family
of types at once:

[source,cpp]
----
include::{examples}/value_formats.cpp[tag=declaration,indent=0]
----

`formats`, a `codecs::format_list` of the formats the type has, is the one required
member, and what a refusal prints. `has_format<Format>`, optional, says whether the
type has a format for a list that names a family; by default the format is one of
`formats`. `has_reason<Format, Direction>` and `refuse<Format, Direction>()`, optional
and together, are the library's reason for a pair it refuses in one `codecs::direction`
(`encode` or `decode`) or in both: the first says which pairs, and the second, a
function whose `static_assert` is false for those pairs alone, says why in the
library's sentence. The shapes are fixed, the format alone for `has_format` and the
format and then the direction for the other two; a member of another shape is not
found, and the type is read as not stating it. `refuse` must stop the build for
every pair whose `has_reason` is true: codecs calls it instead of converting, and an
operation it does not stop returns an error, never a value.

For a declared type, a pair converts in a direction exactly when it has no reason in
that direction, the type has the format, and a value codec of the pair converts in that
direction: `codecs::encodable<Value, Format>` and `codecs::decodable<Value, Format>`
are true exactly then, and every verb that converts a value builds exactly then. Any
other pair is refused with one error, the first that applies: the declaration's
reason, then, for a format the type does not have, codecs' assertion that prints the
list (`webcpp::codecs::detail::format_listed<Format, Value, List>`, with the list as
`+webcpp::codecs::format_list<...>+`), then, for a format the type has and no value
codec of the pair converts, codecs' assertion that the type lists the format and no
value codec of the pair encodes it, or decodes it. A value codec of a format the list
does not name is thus no conversion: the program below asks `encodable` of `der_t`, which
the point has a value codec for and does not list.

A declared type composes under any outer codec: `over<Outer, Inner>` converts when the
pair of `Inner` and the value converts in that direction, and a composition is refused
as its inner link is, after any reason given for the composition itself. The reason
above refuses the armor over `spki_t`, which the type's armor is not: a reason may
name a composition by its type, as it names a format. The program says, with the concepts,
where a verb builds.

[source,cpp]
----
include::{examples}/value_formats.cpp[tag=main,indent=0]
----

[listing]
----
include::{examples}/value_formats.expected[]
----

A library with an entry point of its own that converts a value and is not one of
codecs' verbs, as a decode that takes a memory resource, calls
`codecs::check_conversion<Direction, Value, Format>()` first: it does nothing for a
pair that converts, and stops the build for any other with the one error the verbs
give. A type with no declaration is converted and refused as before: the declaration
governs a value codec's pairs only, never the bytes a `codec` encodes or decodes. A
pair that has a value codec is a value codec's pair even when the type is also a byte
input or a byte result: its declaration governs it, and the pair is never converted as
bytes instead.

=== is_secret and fixed_byte_storage

`codecs::is_secret<T>` is false unless a library specializes it. A library
Expand Down
2 changes: 2 additions & 0 deletions example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ webcpp.example rfc4648.cpp ;
webcpp.example tokens.cpp ;
webcpp.example results.cpp ;
webcpp.example over_chain.cpp ;
webcpp.example over_value.cpp ;
webcpp.example value_formats.cpp ;
webcpp.example stream_flow.cpp ;
# The allocator that cannot give the memory throws std::bad_alloc, which the
# program catches.
Expand Down
Loading
Loading