Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
8d0dc45
codecs: the library's skeleton, its configuration, its errors and the…
Nov 26, 2026
4862340
codecs: skeleton lint fix
Nov 26, 2026
0694457
codecs: skeleton lint fix, the namespace probe's suppression
Nov 26, 2026
43a84b4
codecs: the error test without its empty namespace, the config test's…
Nov 26, 2026
790eab6
codecs: the format contract, its concepts and refusal, the sizes and …
Nov 26, 2026
7191614
codecs: the format contract lint fix
Nov 26, 2026
b33bb52
codecs: the format contract's review fixes: text inputs of any char r…
Nov 26, 2026
a1b7a83
codecs: the contract's doc examples with two-word parameter names
Nov 26, 2026
cb0c010
codecs: text<N> and bytes<N>, the default results, and the typed deco…
Nov 26, 2026
4201fb3
codecs: the fixed results and typed decode lint fix
Nov 26, 2026
eb6a7ea
codecs: the fixed results and typed decode lint fix, the duplicate si…
Nov 26, 2026
42afea0
codecs: the fixed results lint fix, the conversions' suppressions and…
Nov 26, 2026
0719964
codecs: Task 3's review fixes: heap results hold what was written, th…
Nov 26, 2026
69b97e3
codecs: tokens, Boost.URL's and codecs' own, with allocators, the are…
Nov 26, 2026
36179ea
codecs: tokens lint fix
Nov 26, 2026
449a66f
codecs: tokens lint fix, the allocators' suppressions and the nodisca…
Nov 26, 2026
8dd9547
codecs: tokens fix round 1: bookkeeping blocks left out of the arena …
Nov 26, 2026
6796695
codecs: tokens lint fix, the restoring hooks of the tokens may throw …
Nov 26, 2026
6f23f5a
codecs: the reference builds again: one-sentence briefs, every @tpara…
Nov 26, 2026
62e6c71
codecs: the secret results, in place and on the heap with any allocat…
Nov 26, 2026
f9ff288
codecs: the secret results lint fix, the allocator by value and the m…
Nov 26, 2026
a6e2268
codecs: the secret results lint fix, the allocator by reference as th…
Nov 26, 2026
368565e
codecs: Task 5's review minors: the heap secret types' default constr…
Nov 26, 2026
afa9024
codecs: the heap secret types' default constructor only for an alloca…
Nov 26, 2026
a94424b
codecs: secret operations, by the value's type, the value codec, the …
Nov 26, 2026
7b05d8a
codecs: assign_to leaves its string or vector as it was when the oper…
Nov 26, 2026
c4a1fec
codecs: the reference builds: a @tparam for each is_secret specializa…
Nov 26, 2026
4840798
codecs: secret operations lint fix, the test types of internal linkag…
Nov 26, 2026
a715dba
codecs: secret operations lint fix, no fluent chains, the DIT check r…
Nov 26, 2026
3881bb3
codecs: a codec's overload that takes secret_tag first and returns an…
Nov 26, 2026
0ff7376
codecs: every token the core makes wipes what the caller does not get…
Nov 26, 2026
518e8d3
codecs: secret operations fix round lint fix, the in-place bound by o…
Nov 26, 2026
4731eb4
codecs: Task 6's review minors: a secret_tag overload whose parameter…
Nov 26, 2026
69ebea4
codecs: over, a format of two links, its intermediate in place or fro…
Nov 26, 2026
f8ba6e7
codecs: over lint fix, the trait helpers not noexcept, the move and s…
Nov 26, 2026
34e334c
codecs: MSVC checkpoint 1 fixes: parameters that hid a program's glob…
Nov 26, 2026
36575c5
codecs: over lint fix
Nov 26, 2026
c51bd5b
codecs: over lint fix
Nov 26, 2026
bf761b3
codecs: over lint fix
Nov 26, 2026
e0d39b5
codecs: a value codec's secret_tag overloads run in every secret oper…
Nov 26, 2026
ea07828
codecs: a codec's functions take D3's span types, which the bounded v…
Nov 26, 2026
10cdbef
codecs: the codec's parameter types each in one inline span, as the r…
Nov 26, 2026
dc334a8
codecs: fix round lint fix, the contract test's formats of internal l…
Nov 26, 2026
70bafb7
codecs: over's Doc Comment rewrapped, its ragged line joined
Nov 26, 2026
c7621fa
codecs: the conversion contract, one-shot and stream transformers of …
Nov 26, 2026
76ca042
codecs: transformer contract lint fix, designated initializers of ste…
Nov 26, 2026
2a80c93
codecs: transformer contract lint fix, the packet arrays of typed ele…
Nov 26, 2026
375b279
codecs: the transformer test without the unused <string>
Nov 26, 2026
ea97d4b
codecs: pipe and drain, composed by element types alone, in place, wi…
Nov 26, 2026
e9bd522
codecs: pipe and drain lint fix, a result's value read unchecked afte…
Nov 26, 2026
4392fdf
codecs: pipe and drain lint fix, the results of the pipe's calls and …
Nov 26, 2026
f3c7001
codecs: pipe's review minors, an errored pipe movable, piped checking…
Nov 26, 2026
557eeca
codecs: each and buffered, a one-shot transformer as a stream per ite…
Nov 26, 2026
ff76e3e
codecs: each and buffered lint fix, the noexcept of transform as a re…
Nov 26, 2026
56a79fa
codecs: each and buffered fix round 1, construction noexcept for ever…
Nov 26, 2026
cf63ce3
codecs: each and buffered fix round 1 lint fix
Nov 26, 2026
9c9d247
codecs: each and buffered fix round 1 doc fix
Nov 26, 2026
271c4a7
codecs: the noexcept test's element of a throwing default constructor…
Nov 26, 2026
1581e17
codecs: encoder and decoder, a format's one-shot transformer always a…
Nov 26, 2026
2f04e2f
codecs: encoder and decoder lint fix, the format taken by value, the …
Nov 26, 2026
f3c4639
codecs: a fault of the format's configuration through codec's optiona…
Nov 26, 2026
449f927
codecs: decoder(format, capacity<0>) refused, a hold being 1 or more …
Nov 26, 2026
8c1ae0a
codecs: the chunkings' three-chunk splits exhaustive up to 128 elemen…
Nov 26, 2026
8f22c9a
codecs: the noexcept and allocation tests of a fault of the format's …
Nov 26, 2026
bed0202
codecs: configuration fault doc fix, the over stream's brief one sent…
Nov 26, 2026
25c7ce8
codecs: configuration fault lint fix, the one-shot check split into e…
Nov 26, 2026
edfd616
codecs: Task 11's minors, encoded_size 0 for a format whose configura…
Nov 26, 2026
2d9500e
codecs: Task 11's minors gcc fix, the faulted chains' loop by referen…
Nov 26, 2026
d8a1a94
codecs: secret streams, move-only, a guard in every call nesting with…
Nov 26, 2026
7b12736
codecs: secret streams doc fix, is_secret's Doc Comment names the tra…
Nov 26, 2026
7a8cc44
codecs: secret streams lint fix, the trailing commas of two lists, th…
Nov 26, 2026
7250429
codecs: MSVC fix, configuration_probe's fault one return a branch (C4…
Nov 26, 2026
f816f4c
codecs: secret streams test prints whether DIT applies, so that a lan…
Nov 26, 2026
d818c57
codecs: Task 12 fix round 1, the heap output's wipe before it outgrow…
Nov 26, 2026
725a221
codecs: Task 12 fix round 1, the new message cases name the requireme…
Nov 26, 2026
9aad042
codecs: Task 12 fix round 1 lint fix, requires without redundant pare…
Nov 27, 2026
0662312
codecs: hex, constant time, its stream, RFC 4648's base16 vectors
Nov 27, 2026
878e1b5
codecs: hex lint fix, the masks in unsigned words, the results nodisc…
Nov 27, 2026
93ac1c6
codecs: hex lint fix, the fluent chains of the tests bound to names, …
Nov 27, 2026
42c92ef
codecs: hex lint fix, an empty secret result read by empty()
Nov 27, 2026
b94c067
codecs: the tests' shared helpers in test/support once, the include b…
Nov 27, 2026
4b86c97
codecs: the tests' random bytes and chunk sizes drawn from the engine…
Nov 27, 2026
92c1576
codecs: the constant-time lane, memcheck, MemorySanitizer and dudect …
Nov 27, 2026
a80d884
codecs: the fuzz lane, libFuzzer on Linux and a replay on every lane,…
Nov 27, 2026
0c2ff78
codecs: the fuzz lane lint fix, the report's prints discarded by a ca…
Nov 27, 2026
8d64484
codecs: the fuzz lane lint fix, the sanitizer's hooks installed by a …
Nov 27, 2026
b123079
codecs: the fuzz lane's review fixes, the stream's splits drawn from …
Nov 27, 2026
f16d8c1
codecs: the fuzz lane's review fixes lint fix, the sanitizer's test b…
Nov 27, 2026
fbbb521
codecs: the fuzz lane's encode check named for any bytes, the input's…
Nov 27, 2026
133fe9d
codecs: the planted dudect leak an early exit over hex's 64 character…
Nov 27, 2026
7cce4d6
codecs: the fuzz lane's arena poisons a released block over its whole…
Nov 27, 2026
ac826f3
codecs: base64 and base64url, constant time, canonical, their streams
Nov 27, 2026
ff17f34
codecs: base64 lint fix, the nested conditional and the casts, the CR…
Nov 27, 2026
0d8eae2
codecs: base64 lint fix, the CRTP's note on its constructor, the aren…
Nov 27, 2026
aae1f8a
codecs: base64 lint fix, the CRTP's suppression on the line it flags
Nov 27, 2026
9588e9b
codecs: base64 lint fix, the constant-time paths' names by if constex…
Nov 27, 2026
81fd8ac
codecs: base64 doc fix, the brief of formats::padding in one sentence
Nov 27, 2026
2ba6263
codecs: base64 decode keeps where the = of a text are secret, the cou…
Nov 27, 2026
8340b25
codecs: formats::padding's rule for a value of neither enumerator, re…
Nov 27, 2026
a7c5c1a
codecs: base64's invalid-text paths named by configuration, the base6…
Nov 27, 2026
8a31b66
codecs: base64's stream codec and stream test say what the padded dec…
Nov 27, 2026
91858ae
codecs: base64 lint fix, the exact-room test split per text
Nov 27, 2026
62d64a3
codecs: base64's buffer decode into a larger buffer leaves the tail p…
Nov 27, 2026
e37e477
codecs: the stream tests' counts of the wipes inside an object in tes…
Nov 27, 2026
828ba2c
codecs: bech32 and bech32m as a template over the variant, the maximu…
Nov 27, 2026
036ab48
codecs: bech32 lint fix, the parts of a text by remove_prefix and rem…
Nov 27, 2026
26be971
codecs: bech32 lint fix, the generator's words on two lines, each wit…
Nov 27, 2026
08dce03
codecs: Task 17's review minors, the stream tests' wipe counts from t…
Nov 27, 2026
e7f145c
codecs: base32 and base32hex, constant time, their streams
Nov 27, 2026
b0599ee
codecs: base32 lint fix, the padding option's base takes whether it i…
Nov 27, 2026
6afbbc2
codecs: a hold above the format's maximum is refused by codecs::decod…
Nov 27, 2026
7d77d1a
codecs: base32 fix round 1, the padding runs and lengths stated in th…
Nov 27, 2026
16a79dd
codecs: the stream tests' remaining step helpers from test/support/st…
Nov 27, 2026
aa867b5
codecs: base58 as a template over its bound, alphabet and checksum, B…
Nov 27, 2026
e9d57d0
codecs: base58 lint fix, the trailing commas of multi-line initialise…
Nov 27, 2026
d2c67d3
codecs: base58 lint fix, the constant-time lane's invalid base58 text…
Nov 27, 2026
48ce252
codecs: buffered in place refuses a capacity past the transformer's b…
Nov 27, 2026
df9807c
codecs: base58 fix round 1, the shared test helpers once, the exact g…
Nov 27, 2026
d194bfc
codecs: base58 fix round 1 lint fix, reversed_alphabet with internal …
Nov 27, 2026
6c16f07
codecs: percent, an adapter over Boost.URL's percent-encoding with an…
Nov 29, 2026
ad79408
codecs: percent lint fix, the trailing commas, unsigned shifts, unche…
Nov 29, 2026
338d4c7
codecs: percent doc fix, the call operator's template parameter docum…
Nov 29, 2026
5209bdb
codecs: percent fix round 1, secret temporaries wiped, no byte after …
Nov 29, 2026
82ac1bd
codecs: percent fix round 1 lint fix
Nov 29, 2026
58b4c77
codecs: armor, RFC 7468's strict textual encoding, constant time over…
Nov 30, 2026
25824cf
codecs: armor lint fix, no exception from substr, the delivery's memb…
Nov 30, 2026
f95ba63
codecs: armor lint fix, the test's initializer lists
Nov 30, 2026
167954b
codecs: MSVC fix, the first guard's function read as MSVC spells a te…
Nov 30, 2026
0c50a98
codecs: MSVC fix, allocator_throw_test's size constant no longer name…
Nov 30, 2026
392559d
codecs: armor fix round 1, OpenSSL's armor of no bytes compared whole…
Nov 30, 2026
7d38127
codecs: the page, one section per format, tokens, secrecy, streams, a…
Nov 30, 2026
50b074a
codecs: page lint fix, the Jamfile comment's width
Nov 30, 2026
a35b7c4
codecs: page fix round 1, over's heap intermediate qualified, results…
Nov 30, 2026
93a955c
codecs: tokens scratch, the NOLINT dropped now the assertion states t…
Nov 30, 2026
ba2a08c
codecs: overview names /webcpp//throw_exception for a program that re…
Nov 30, 2026
5c31224
codecs: an encode a format refuses is refused before prepare (encode_…
Nov 30, 2026
789eec8
codecs: over's construction and assignments, and the tokens' shrink_t…
Nov 30, 2026
1e4232f
codecs: buffered and each report a format transformer's configuration…
Nov 30, 2026
8d5fe88
codecs: the armor's label private with label(), and the parts types s…
Nov 30, 2026
e8dded8
codecs: format_encoder and format_decoder state over's move window
Nov 30, 2026
a606843
codecs: the wipe rule of a one-shot's few bytes of state, restated
Nov 30, 2026
952bf58
codecs: the core's message for a hold above maximum_hold names no format
Nov 30, 2026
b3c394e
codecs: percent no longer claims to decode into the text's own storage
Nov 30, 2026
b216d9c
codecs: AGENTS.md says codecs keeps no secret value type or wipe prim…
Nov 30, 2026
015da4f
codecs: every header survives a bare <windows.h>, with the windows_h …
Nov 30, 2026
e19edeb
codecs: the tests' shared helpers live once in test/support
Nov 30, 2026
e88acf7
codecs: hex_stream_test streams 1000 random inputs, as its header says
Nov 30, 2026
e0842fb
codecs: the fuzz targets stream through the secret decoders, and over…
Nov 30, 2026
8302c2b
codecs: comments that say what the code does, and the changelog's for…
Nov 30, 2026
9fe9ce0
codecs: the streams chapter's over{...} written as inline code that A…
Nov 30, 2026
f139899
codecs: final fix wave lint fix
Nov 30, 2026
ce770c9
codecs: final fix wave lint fix 2
Nov 30, 2026
43a0ffa
codecs: final fix wave lint fix 3
Nov 30, 2026
9748826
codecs: bech32's mixed-case mask names no <windows.h> macro
Nov 30, 2026
bb8d0f6
codecs: a size the core reads as the sentinel is input_too_long, not …
Nov 30, 2026
4848c23
codecs: encode_fault's brief is one sentence (the doc-check's rule)
Nov 30, 2026
9e1baee
codecs: own_format's value_codec encode names its span destination (M…
Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
* text=auto eol=lf
*.bat text eol=crlf
# The fuzz corpora are inputs byte for byte: no line ending of theirs is converted.
test/fuzz/corpus/** -text
# The armor's vectors are compared byte for byte: no line ending of theirs is converted.
test/data/armor/** -text
48 changes: 48 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Working on codecs

webcpp's rules apply here: read the superproject's
[CODING-GUIDELINES.md](../../CODING-GUIDELINES.md)
(<https://github.com/webcpporg/webcpp/blob/main/CODING-GUIDELINES.md>) and its
[AGENTS.md](../../AGENTS.md)
(<https://github.com/webcpporg/webcpp/blob/main/AGENTS.md>) first. This file holds only what is
specific to codecs.

## What codecs is

- **webcpp's own library** (`"port-of": null`): one contract for converting bytes and typed
values to text and back, and any data through one-shot and stream transformers, with seven
formats (hex, base32, base58, base64, bech32, percent-encoding and RFC 7468's armor).
- **Header-only**, built on secure (`<library>/webcpp/secure//secure`) and config. percent alone
depends on Boost.URL, through the target `/webcpp/codecs//percent`.

## Cautions

- A test is declared through `codecs-run` (or `codecs-compile`) in `test/Jamfile`, which builds it
with exceptions and without.
- A test that defines a seam includes the seam's header first, before any header of codecs.
- The core (`codecs.hpp` and `detail/core/`) includes no format and no Boost.URL:
`meta/include-boundaries.json` checks it, and checks that no header names another webcpp
library but config and secure.
- Constant-time code uses secure's building blocks alone: codecs keeps no guard, no secret value
type and no wipe primitive of its own (`secure::timing_guard`, `secure::secret<N>`,
`secure::erase_secret`), and no constant-time primitive; its secret results (`secret_text`,
`secret_bytes` and the heap secret types) are built on them.
- `detail` is not API: another library's header never includes it.
- Every header survives a bare `<windows.h>` before it (CODING-GUIDELINES.md's rule): it writes
`(std::min)(...)`, `(std::max)(...)` and `(std::numeric_limits<T>::max)()`, and names none of
`<windows.h>`'s other macros; `test/windows_h_before_test.cpp` and
`test/windows_h_after_test.cpp` check it on the MSVC lanes.

## The page and the examples

- The page is `doc/codecs.adoc`, which includes one file for each chapter (`overview`, `formats`,
`tokens`, `results`, `secrecy`, `composition`, `streams`, `allocators`, `writing_a_format`,
`writing_a_transformer`) and the changelog. A chapter that states a behaviour states what the
headers' Doc Comments state: read them when a header changes, and change the chapter with it.
- Every C++ listing of the page is a tagged region of a program of `example/`, which
`example/Jamfile` builds and runs on every target, its output compared with the `.expected`
beside it. A new example is declared there and shown in a chapter (the doc build fails on one
that is not); the percent example links `/webcpp/codecs//percent`, and the allocator example
catches `std::bad_alloc`, so it is built with exceptions on.
- A change a user sees adds its line to `doc/changelog.adoc` under "Unreleased", at most ten lines
for the library.
22 changes: 22 additions & 0 deletions LICENSE-BITCOIN.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2009-2026 The Bitcoin Core developers
Copyright (c) 2009-2026 Bitcoin Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ wasip2, wasip3 and Emscripten. Over that contract it ships seven formats: hex, b
base64, bech32, percent-encoding and RFC 7468's armor, every name in `webcpp::codecs`. It is
header-only and builds on webcpp::secure for its secret and constant-time operations.

The library is being built; its design is the genesis of `libraries/codecs` in
Every format is a value (`codecs::formats::hex`), an operation a function of it
(`codecs::encode(format, bytes)`), and where a result goes a token, so that a digest is a text held in
place, a key a secret that wipes itself, and a file a stream. Errors are values, and codecs throws
nothing of its own. Its page, `doc/codecs.adoc`, teaches the formats, the tokens and results,
secrecy, composition, streams, allocators and how to write a format or a transformer, with a program
of `example/` for each; its design is the genesis of `libraries/codecs` in
[webcpporg/proposals](https://github.com/webcpporg/proposals).

## Build and test
Expand All @@ -26,6 +31,15 @@ From the superproject's root:
./b2 toolset=clang libs/codecs/test libs/codecs/example
```

## Documentation

The library's page is built with `./b2 libs/codecs/doc doc` and published with webcpp's
documentation, at <https://webcpp.org>.

## Licence

Distributed under the Boost Software License, Version 1.0 (`LICENSE_1_0.txt`).

base58's public conversion, in `include/webcpp/codecs/detail/formats/base58.hpp`, follows Bitcoin
Core's `EncodeBase58` and `DecodeBase58` (`src/base58.cpp`); codecs is BSL-1.0; base58's public
conversion derives from Bitcoin Core's, whose MIT notice is `LICENSE-BITCOIN.txt`.
25 changes: 25 additions & 0 deletions build.jam
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2026 WebCpp.org
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)

# codecs: one contract for converting bytes and values to text and back, and
# any data through streams; a program names /webcpp/codecs//codecs, and
# /webcpp/codecs//percent for percent-encoding:
#
# exe app : app.cpp /webcpp/codecs//codecs ;

import webcpp-target ;

project /webcpp/codecs ;

# tag::codecs[]
alias codecs : : : : <include>include <library>/boost//headers <library>/webcpp/config//config
<library>/webcpp/secure//secure ;
# end::codecs[]
# percent.hpp adapts Boost.URL's percent-encoding: a program that includes it
# names this target, which links Boost.URL built from Boost's sources.
# tag::percent[]
alias percent : : : : <library>codecs <library>/webcpp//boost_url ;
# end::percent[]
10 changes: 10 additions & 0 deletions doc/Jamfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2026 WebCpp.org
#
# Distributed under the Boost Software License, Version 1.0. (See
# accompanying file LICENSE_1_0.txt or copy at
# https://www.boost.org/LICENSE_1_0.txt)

import webcpp ;

webcpp.doc codecs : codecs.adoc ;
webcpp.reference codecs ;
110 changes: 110 additions & 0 deletions doc/allocators.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

[#codecs-allocators]
== Allocators

A program that cannot call the global `operator new`, a WASI component with an
arena, a server with a request pool, tells codecs which allocator to use, and
codecs allocates through it and through nothing else.

=== What allocates

[cols="3,2",options="header"]
|===
| Form | Allocates

| the buffer forms of `encode` and `decode`, the sizes
| nothing (and `noexcept`), except `over` with a heap intermediate, whose sizes and buffer forms allocate and are not `noexcept` (<<codecs-composition>>)

| `text<N>`, `bytes<N>`, `tokens::fixed<N>`, and the secret results in place
| nothing

| the conversion of every format, in every form: hex, base32, base58, base64, bech32, percent and the armor
| nothing: the scratch of each is in place; a result on the heap, as the default result of a run-time size or `armor_parts`, allocates through its own allocator

| `over` with a static bound
| nothing

| `over` with a bound that is not static
| its allocator, for the intermediate

| the stream transformers of the native formats, `pipe`, `drain`, and `each` and `buffered` with `codecs::capacity<N>`
| nothing, once constructed

| the default result of a run-time size, `return_string`, `append_to`, `assign_to`, `tokens::secret` with a heap result
| the allocator of the result or the container

| `each` and `buffered` with an allocator
| the allocator, for their storage
|===

base58 takes no allocator: its scratch is in place, sized by its template, so
that `buffered` over its encoder takes its storage from the allocator it is given and the
conversion itself allocates nothing. bech32's results, scratch and stream hold
are in place too, sized from `MaximumLength`.

=== The tokens with an allocator

`tokens::return_string(allocator)` gives a `std::basic_string` over the
allocator, which is used through `std::allocator_traits` and rebound to `char`;
`tokens::secret(allocator)` gives `basic_secret_string<A>` or
`basic_secret_byte_vector<A>` when the size is not known at compile time, and
the in-place result, ignoring the allocator, when it is; and `append_to` and
`assign_to` use the allocator of the container they are given, a
`std::pmr::string` among them. The decode's bytes go to a `std::vector<std::uint8_t, A>`
the same way.

The `std::pmr` aliases, in `codecs::pmr`, are `codecs::pmr::secret_string` and
`codecs::pmr::secret_byte_vector`, the secret heap types over
`std::pmr::polymorphic_allocator`, as the containers of `std::pmr` are over the
standard's allocators. Their `std::allocator` aliases are `codecs::secret_string` and
`codecs::secret_byte_vector`.

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

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

The arena in the program records every allocation, and the global `operator new`
sees none: codecs' tests check that for every form that takes an allocator, with
a recording memory resource and with allocators of their own that the
standard's rules are checked against.

=== An allocator that throws

An allocator that cannot give the memory throws, as `std::pmr::null_memory_resource`
does once the arena is full. That exception propagates unchanged out of the
allocating function, which is not `noexcept`, and codecs throws nothing of its
own (<<codecs-exceptions>>). What the program finds after it:

* a token's container still holds what it held: `append_to` is put back as it
was, `assign_to` gives the container nothing before the conversion succeeds,
and in the example the string still holds `kept`;
* every buffer of a secret operation that was allocated is wiped before it is
given back, and a secret heap type whose allocation throws keeps its value;
* `each` and `buffered` with an allocator: a `send` that throws accepts nothing,
and the stream converts the same input after the exception; a `receive`
that throws leaves its item pending; a `flush` that throws leaves the stream
as it was before the flush, valid and resettable.

Without exceptions the allocator's failure follows the build's handler: codecs
adds no handling.

=== Pitfalls

* The allocator of `over` is for its intermediate alone. The allocator of a
token is for its result alone. Neither is the other's.
* 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.
* A secret result over a pmr allocator is wiped before its memory goes back to
the resource, but the resource may keep the pages: that is the resource's.
29 changes: 29 additions & 0 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

[appendix]
[#codecs-changelog]
== Changelog

What changed in codecs in each version of webcpp, newest first, one line
per change. "Unreleased" is what the next version brings. The release notes
of every version are on webcpp's index page.

[#codecs-changelog-unreleased]
=== Unreleased

// tag::unreleased[]
* Added codecs.hpp and config.hpp: encode, decode, tokens, results, secrecy and over, errors as values.
* 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 the guide, with its examples built and run on every target.
// end::unreleased[]
68 changes: 68 additions & 0 deletions doc/codecs.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

= codecs: bytes and values to text and back, and streams of any data, for {cpp}
:toc: left
:toclevels: 2
:idprefix:
:sectanchors:
:example-caption!:
:attribute-missing: warn

codecs is the conversion library of
https://github.com/webcpporg/webcpp[webcpp], for a {cpp}20 program on every
target webcpp has: one contract for converting bytes and typed values to text
and back, and any data through one-shot and stream transformers, with hex,
base32, base58, base64, bech32, percent-encoding and RFC 7468's armor. It is
built on webcpp::secure, so that the conversions of secrets keep their timing
and their memory clean.

The page teaches the library in the order a program meets it. <<codecs-overview>>
says what codecs is and what it is not, <<codecs-formats>> has one section for
each format, with its example and its pitfalls, and the chapters after it teach
what every format shares: <<codecs-tokens>> (where a result goes),
<<codecs-results>> (the default and fixed results and the typed decode),
<<codecs-secrecy>> (what a secret operation is), <<codecs-composition>>
(`over`), <<codecs-streams>> (the two transformer concepts, `pipe`, `drain`,
`each` and `buffered`) and <<codecs-allocators>> (what allocates, and the
`codecs::pmr` aliases). <<codecs-writing-a-format>> and
<<codecs-writing-a-transformer>> are for the library that adds a format of its
own, and a transformer of data that is no text. Every program shown is in
`example/`, built and run on every target with the output it prints. The
<<reference,reference>> that closes the page lists every name the headers
declare.

include::overview.adoc[]

include::formats.adoc[]

include::tokens.adoc[]

include::results.adoc[]

include::secrecy.adoc[]

include::composition.adoc[]

include::streams.adoc[]

include::allocators.adoc[]

include::writing_a_format.adoc[]

include::writing_a_transformer.adoc[]

[#reference]
== Reference

Every name codecs declares, in the namespace `webcpp::codecs`, from the Doc
Comments of its headers: each class, function, type and enumerator with its
declaration, what it does, what it asks of its caller and how it fails. The
other sections teach the library; this one is where a name is looked up.

include::{reference}[leveloffset=+1]

include::changelog.adoc[]
Loading
Loading