codecs is the conversion library of webcpp, for a C++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, z-base-32, 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. What codecs is, and is not
says what codecs is and what it is not, The formats has one section for
each format, with its example and its pitfalls, and the chapters after it teach
what every format shares: Tokens: where a result goes (where a result goes),
Results: the default and the fixed ones, and the typed decode (the default and fixed results and the typed decode),
Secrecy: secret operations (what a secret operation is), Composition: over
(over), Streams and transformers (the two transformer concepts, pipe, drain,
each and buffered) and Allocators (what allocates, and the
codecs::pmr aliases). Writing a format and
Writing a transformer of other data 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 that closes the page lists every name the headers
declare.
What codecs is, and is not
A program converts bytes to text and back all the time: a digest as hex, a key
as base64, an address as base58, a URL’s segment as percent-encoding, a
certificate as a PEM file. codecs gives that one contract, for every format and
for every way of calling it. A format is a value, codecs::formats::hex; an
operation is a function of it, codecs::encode(format, bytes) and
codecs::decode(format, text); and where the result goes is a token, so that
the same call fills a std::string, a buffer on the stack, a std::pmr::string
or Boost.URL’s own string tokens. The same formats run as streams, a chunk at a
time, and the transformers that run them accept data of any type: codecs is
also the contract of a decoder of video packets, which no format here is.
// SHA-256 of "abc", 32 bytes whose size the type states.
std::array<std::uint8_t, 32> const digest{
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40,
0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17,
0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
};
// The size is known at compile time, so the result is a text<64>: in place, no allocation.
auto const text = codecs::encode(formats::hex, digest);
if (!text) {
return 1;
}
std::cout << "hex: " << text->view() << '\n';
// The case is an option of the format; decode takes either.
auto const upper = codecs::encode(formats::hex(formats::letter_case::upper), digest);
if (!upper) {
return 1;
}
std::cout << "upper: " << upper->view() << '\n';
// The typed decode: exactly 32 bytes, or an error.
auto const back = codecs::decode<std::array<std::uint8_t, 32>>(formats::hex, upper->view());
if (!back || *back != digest) {
return 1;
}
std::cout << "decoded " << back->size() << " bytes, the first is 0x" << std::hex
<< static_cast<unsigned>(back->front()) << ", the last is 0x"
<< static_cast<unsigned>(back->back()) << std::dec << '\n';
The digest’s size is part of its type, so the result is a text<64> held in
place: no allocation, and the text is a std::string_view when asked. The
typed decode gives the digest back as a std::array, and a fault is a value of
codecs::error, never an exception.
The formats
| Format | Header | Constant time | Streams natively | Decodes in place | See |
|---|---|---|---|---|---|
|
|
always |
yes |
yes |
|
|
|
always |
yes |
yes |
|
|
|
always |
yes |
yes |
|
|
|
always |
yes |
yes |
|
|
|
when the operation is secret |
through |
no |
|
|
|
always |
yes, holding its text until the checksum is checked |
no |
|
|
|
no |
yes |
no |
|
|
|
its payload, always; its structure is public |
yes |
no |
The core, <webcpp/codecs.hpp>, registers no format: a program includes the
header of each format it names, and a format named without its header is an
undeclared name. Every name is in webcpp::codecs, the formats in
webcpp::codecs::formats, the tokens in webcpp::codecs::tokens and the
std::pmr aliases of the secret types in webcpp::codecs::pmr;
webcpp::codecs::detail is not API, and no header of another library includes
a header of detail/.
A program names the target /webcpp/codecs//codecs in its Jamfile, as it names
any library of webcpp, and /webcpp/codecs//percent when it includes
<webcpp/codecs/percent.hpp>, which adapts Boost.URL and links its compiled
code. codecs is header-only, builds on webcpp’s config and secure and on
Boost’s headers, and nothing else is built for a program that does not use
percent-encoding.
exe app : app.cpp /webcpp/codecs//codecs ; exe url_app : url_app.cpp /webcpp/codecs//percent ;
Errors are values
Every function that can fail returns boost::system::result<T>, and the error
is a value of codecs::error in the category webcpp.codecs, in every build.
The values are fixed and never reused:
| Value | Name | When |
|---|---|---|
1 |
|
a character is outside the format’s alphabet (a byte of 128 or more included), or a word of bech32 is above 31 |
2 |
|
the length is one no encoding of the format has, or a typed decode into a |
3 |
|
the padding is missing, misplaced or not zero: base32 and base64’s |
4 |
|
the checksum of bech32 or of a base58 with a checksum is wrong |
5 |
|
the human-readable part or the label is not the format’s, or is a fault of the format’s configuration |
6 |
|
a bech32 text holds both cases |
7 |
|
the buffer or the token’s capacity is shorter than the result |
8 |
|
the input, or the result’s bound, is longer than the format, a value codec’s |
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, 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 (Composition: over). 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.
Exceptions
codecs throws nothing of its own, with exceptions on and off: data and
configuration errors are values (above), and WEBCPP_CODECS_NO_EXCEPTIONS is
defined when webcpp has no exceptions, or when a program defines it alone, and
changes nothing in what a function returns. What can throw is an allocator.
When a program gives codecs an allocator, an exception the allocator throws
reaches the caller unchanged, out of the functions that allocate, which are not
noexcept: the forms that return a std::string or a std::vector, the
tokens return_string, append_to, assign_to and secret with a heap
result, each and buffered with an allocator, and over with a heap
intermediate. Every other function is noexcept, the buffer forms, the in-place results and
the stream calls of the native formats among them. A token is untouched, and every secret buffer
wiped, when an allocation throws (Allocators).
Without exceptions the allocator’s failure follows the build’s handler, and
codecs adds no handling of its own. codecs’ own headers read a result with
unsafe_value() and never call value(); but Boost.System’s result is
checked on value(), on operator* and on operator->, so a program that
reads a result of codecs that way, with exceptions off, links
/webcpp//throw_exception, webcpp’s handler for boost::throw_exception, or
the link fails on that undefined symbol.
What codecs is not
-
It is not a cryptographic library. It converts, and keeps the conversion of a secret from leaking its timing or staying in memory (Secrecy: secret operations); it holds no algorithm.
-
It defines no checksum algorithm. base58’s checksum is a type a program gives, and webcpp::hash’s double SHA-256 is the one Bitcoin uses.
-
It applies no protocol’s rules: not segwit’s versions, program sizes or networks’ prefixes, nor Lightning’s fields (bech32 and bech32m), which a future webcpp::bitcoin owns.
-
It is not a text-processing library. A decode takes the format’s canonical text and nothing else: no whitespace, no other alphabet, no missing padding.
The formats
Each section says what the format is, shows a program, and ends with what
catches a program that has not read the section. Every format is a value in
webcpp::codecs::formats, copyable, with a name; a format with options is
configured by a call that gives another value (formats::hex(letter_case::upper)),
so that a format is a constant a program names and never a type it builds.
The sections that follow say what every format shares: the tokens, the results,
the secret operations and the streams.
A decode reads its whole text before it writes a byte, so that on every error
nothing is written; its buffer form leaves the bytes past the result as they
were. Which formats decode into the text’s own storage, which the table in
What codecs is, and is not lists, is a promise of the format’s page and not of the
core: hex, base32, z-base-32 and base64 write byte i after the characters it comes from
are read, and base58, bech32, the armor and percent ask that the input and the
output do not overlap (percent’s decode is Boost.URL’s, which promises nothing
of overlapping buffers).
hex
hex, or base16 (RFC 4648 section 8), writes each byte as two hex digits, its
high nibble first. formats::hex writes lower case, and
formats::hex(formats::letter_case::upper) upper case, as the RFC does.
Decode takes either case, mixed included, and refuses a text of an odd length
with invalid_length and any character that is no hex digit with
invalid_character, which wins when both are found. It is constant time on
every call, one-shot and streamed, and streams natively: the encoder holds the
low digit of a byte its output had no room for, and the decoder one digit of a
pair.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <string_view>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
int main() {
// SHA-256 of "abc", 32 bytes whose size the type states.
std::array<std::uint8_t, 32> const digest{
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40,
0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17,
0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
};
// The size is known at compile time, so the result is a text<64>: in place, no allocation.
auto const text = codecs::encode(formats::hex, digest);
if (!text) {
return 1;
}
std::cout << "hex: " << text->view() << '\n';
// The case is an option of the format; decode takes either.
auto const upper = codecs::encode(formats::hex(formats::letter_case::upper), digest);
if (!upper) {
return 1;
}
std::cout << "upper: " << upper->view() << '\n';
// The typed decode: exactly 32 bytes, or an error.
auto const back = codecs::decode<std::array<std::uint8_t, 32>>(formats::hex, upper->view());
if (!back || *back != digest) {
return 1;
}
std::cout << "decoded " << back->size() << " bytes, the first is 0x" << std::hex
<< static_cast<unsigned>(back->front()) << ", the last is 0x"
<< static_cast<unsigned>(back->back()) << std::dec << '\n';
// The buffer form decodes into the text's own storage: byte i is written after the characters
// 2i and 2i + 1 are read.
std::string buffer = "ba78";
std::span<std::uint8_t> const storage{reinterpret_cast<std::uint8_t*>(buffer.data()), 2};
auto const in_place = codecs::decode(formats::hex, std::string_view{buffer}, storage);
if (!in_place) {
return 1;
}
std::cout << "in place: ba78 -> " << *in_place << " bytes, 0x" << std::hex
<< static_cast<unsigned>(storage[0]) << " 0x" << static_cast<unsigned>(storage[1])
<< std::dec << '\n';
// A fault is a value, never an exception: 62 digits are no 32 bytes.
auto const short_text =
codecs::decode<std::array<std::uint8_t, 32>>(formats::hex, upper->view().substr(0, 62));
std::cout << "62 digits: " << short_text.error().message() << '\n';
auto const bad_digit = codecs::decode(formats::hex, std::string_view{"0z"});
std::cout << "a 'z': " << bad_digit.error().message() << '\n';
}
hex: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad upper: BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD decoded 32 bytes, the first is 0xba, the last is 0xad in place: ba78 -> 2 bytes, 0xba 0x78 62 digits: the length is one no encoding of the format has a 'z': a character is outside the format's alphabet
Pitfalls.
-
Decode takes digits and nothing else:
0xin front, a space between two bytes and a trailing line feed are eachinvalid_character. Trim the text before decoding it. -
A decode into a fixed type is exact.
decode<std::array<std::uint8_t, 32>>of 62 digits isinvalid_length, not a shorter array. -
Constant time covers the data. The length of the text, the length of the result and whether the call succeeded are public, as they are for every format of codecs (Secrecy: secret operations).
-
The bytes a stream decoder delivers before an error are no result: a caller discards them (Streams and transformers).
base32 and base32hex
formats::base32 is RFC 4648 section 6’s alphabet and formats::base32hex
section 7’s. Each writes upper case and its padding, =, by default, and takes
the padding as an option: formats::base32(formats::padding::omitted). Decode
is canonical. It takes the format’s own alphabet in either case, the padding
the option says, and nothing else: a character of the other alphabet or a line
break is invalid_character, a length no encoding has is invalid_length, and
padding against the option, a = out of its place and non-zero bits at the end
of the last group are invalid_padding.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base32.hpp>
#include <webcpp/codecs/base64.hpp>
#include <array>
#include <cstdint>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// A string literal's bytes, as the RFC's examples are written.
std::vector<std::uint8_t> bytes_of(std::string_view characters) {
return {characters.begin(), characters.end()};
}
} // namespace
int main() {
std::vector<std::uint8_t> const foobar = bytes_of("foobar");
std::vector<std::uint8_t> const fooba = bytes_of("fooba");
std::vector<std::uint8_t> const foob = bytes_of("foob");
std::cout << "base64 foobar: " << codecs::encode(formats::base64, foobar).value() << '\n';
std::cout << "base64 fooba: " << codecs::encode(formats::base64, fooba).value() << '\n';
std::cout << "base32 fooba: " << codecs::encode(formats::base32, fooba).value() << '\n';
std::cout << "base32 foob: " << codecs::encode(formats::base32, foob).value() << '\n';
std::cout << "base32hex foob: " << codecs::encode(formats::base32hex, foob).value() << '\n';
// The padding is an option of the format: base32 writes it by default, base64url does not.
std::cout << "base32 foob, no padding: "
<< codecs::encode(formats::base32(formats::padding::omitted), foob).value() << '\n';
// The two alphabets of base64 differ in two symbols.
std::array<std::uint8_t, 2> const two{0xfb, 0xff};
auto const standard = codecs::encode(formats::base64, two).value();
auto const url_safe = codecs::encode(formats::base64url, two).value();
auto const url_padded =
codecs::encode(formats::base64url(formats::padding::written), two).value();
std::cout << "base64 of fb ff: " << standard.view() << '\n';
std::cout << "base64url of fb ff: " << url_safe.view() << '\n';
std::cout << "base64url of fb ff, padded: " << url_padded.view() << '\n';
// base32 decode takes either case; the bytes are the default result's, a vector.
auto const lower = codecs::decode(formats::base32, std::string_view{"mzxw6yq="});
std::cout << "base32 lower case decodes: "
<< std::string{lower.value().begin(), lower.value().end()} << '\n';
// Canonical means the last group's unused bits are zero, and the padding is as the option says.
std::cout << "MZ======: "
<< codecs::decode(formats::base32, std::string_view{"MZ======"}).error().message()
<< '\n';
std::cout << "Zm9v with padding omitted: "
<< codecs::decode(formats::base64(formats::padding::omitted),
std::string_view{"Zm9v"})
.has_value()
<< '\n';
std::cout << "Zm9vYg with padding written: "
<< codecs::decode(formats::base64, std::string_view{"Zm9vYg"}).error().message()
<< '\n';
std::cout << "a line break: "
<< codecs::decode(formats::base64, std::string_view{"Zm9v\nYg=="}).error().message()
<< '\n';
}
base64 foobar: Zm9vYmFy base64 fooba: Zm9vYmE= base32 fooba: MZXW6YTB base32 foob: MZXW6YQ= base32hex foob: CPNMUOG= base32 foob, no padding: MZXW6YQ base64 of fb ff: +/8= base64url of fb ff: -_8 base64url of fb ff, padded: -_8= base32 lower case decodes: foob MZ======: the padding is missing, misplaced or not zero Zm9v with padding omitted: 1 Zm9vYg with padding written: the length is one no encoding of the format has a line break: a character is outside the format's alphabet
Pitfalls.
-
MZ======andMZXW6Y==have a valid length, so their error isinvalid_padding;MZXW6YQwith the padding written has none, and isinvalid_length. When a text has both, the lowest value wins. -
The two alphabets are not interchangeable:
base32hexhas the digits0,1,8and9, whichbase32refuses. -
A padded stream decoder holds the bytes that the characters of a group’s fourth, fifth, seventh and eighth places give, since those places are
=in the last group of a short input, until the next character shows that the group is not the last, or untilflush. A stream that has delivered less than the text seems to give is not stuck: it waits for the next character or forflush.
z-base-32
formats::zbase32 is z-base-32, Zooko O’Whielacronx’s human-oriented base-32
encoding: base32’s grouping of five bytes as eight symbols, over the alphabet
ybndrfg8ejkmcpqxot1uwisza345h769, in lower case and with no padding. pkarr
writes an Ed25519 public key in it, 32 bytes as the 52 characters of a name,
and iroh reaches pkarr’s names. It has no option. Encode writes the exact size,
so a 32-byte key is a text<52>, and decode is canonical: an upper-case
letter, a = and any other character that is no symbol are
invalid_character, a length no byte count has is invalid_length, and
non-zero bits past the last byte are invalid_padding. It is constant time on
every call and streams natively, by base32’s implementation over its own
alphabet.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/zbase32.hpp>
#include <array>
#include <cstdint>
#include <iostream>
#include <string_view>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// The public key of pkarr's own tests: 32 bytes, so its text is a text<52>, with no heap.
constexpr std::array<std::uint8_t, 32> public_key{
0x01, 0xb4, 0x67, 0xa3, 0xb7, 0x91, 0x3a, 0xb2, 0x7a, 0x04, 0xa8, 0xed, 0xf2, 0xf3, 0xfb, 0x07,
0x4c, 0xfe, 0x0e, 0xcf, 0x4b, 0xab, 0xe1, 0x08, 0xd6, 0x7b, 0xe3, 0x85, 0x3b, 0x0f, 0x26, 0xc5,
};
// What a decode says of a text.
void show(std::string_view label, std::string_view text) {
auto const key = codecs::decode<std::array<std::uint8_t, 32>>(formats::zbase32, text);
std::cout << label << ": " << (key ? "a key" : key.error().message()) << '\n';
}
} // namespace
int main() {
codecs::text<52> const name = codecs::encode(formats::zbase32, public_key).value();
std::cout << "pkarr name: " << name.view() << '\n';
// The name back to the key, into an array of exactly 32 bytes.
auto const key = codecs::decode<std::array<std::uint8_t, 32>>(formats::zbase32, name);
std::cout << "decodes back: " << (key && *key == public_key) << '\n';
// z-base-32 is lower case alone, has no padding, and its bits past the last byte are zero: a
// 52nd character other than `y` or `o` is no encoding of 32 bytes.
show("upper case", "YG4GXE7Z1R7MR6ORIDS9FH95Y7GXHDSXJQI6NNGSXXTAKQAXR5NO");
show("a trailing bit", "yg4gxe7z1r7mr6orids9fh95y7gxhdsxjqi6nngsxxtakqaxr5nt");
show("51 characters", "yg4gxe7z1r7mr6orids9fh95y7gxhdsxjqi6nngsxxtakqaxr5n");
// A valid text of another length is no key: decode into 32 bytes is exact.
codecs::text<7> const four_bytes =
codecs::encode(formats::zbase32, std::array<std::uint8_t, 4>{}).value();
show("4 bytes", four_bytes.view());
}
pkarr name: yg4gxe7z1r7mr6orids9fh95y7gxhdsxjqi6nngsxxtakqaxr5no decodes back: 1 upper case: a character is outside the format's alphabet a trailing bit: the padding is missing, misplaced or not zero 51 characters: the length is one no encoding of the format has 4 bytes: the length is one no encoding of the format has
Pitfalls.
-
z-base-32 is lower case alone. A name that went through a system that changes case (a DNS label is compared without case) is lowered by the program before it is decoded.
-
pkarr’s decoder is more lenient than this one: it ignores the bits past the last byte and truncates a length no byte count has. A key’s 52nd character is
yoro; a text that pkarr takes and codecs refuses is no text a z-base-32 encoder writes. -
The document’s bit-length mode, a length in bits known to both sides, is not codecs’: the format converts bytes.
-
codecs reads the text alone: a
pk:prefix, a key in a URL’s host and the check that the bytes are a point of the curve are the program’s, or pkarr’s.
base64 and base64url
formats::base64 is RFC 4648 section 4’s alphabet with its padding written;
formats::base64url is section 5’s, with - and _ and its padding omitted
by default, as JOSE and URLs write it. Each takes the other padding by option,
formats::base64url(formats::padding::written). Decode is canonical, as base32’s
is: only the format’s alphabet, the padding of the option, and zero bits at the
end of the last group. Zh== is invalid_padding since Zg== is the
encoding of f, and a text with a line break or a space is invalid_character. Both
formats are constant time on every call, stream natively, and decode in place.
The program of the base32 section shows both alphabets of base64 beside
base32’s: the default padding of each, the two symbols in which the alphabets
differ (+/8= and -_8 for the bytes fb ff) and the canonical refusals. The
next program is the secret use, a key as base64.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base64.hpp>
#include <webcpp/secure/constant_time_equal.hpp>
#include <webcpp/secure/secret.hpp>
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <string>
#include <string_view>
#include <type_traits>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace secure = webcpp::secure;
int main() {
secure::secret<32> key;
std::iota(key.writable().begin(), key.writable().end(), std::uint8_t{0});
// A secret input gives a secret_text<44>: the characters in place, wiped when it is destroyed.
auto const text = codecs::encode(formats::base64, key);
if (!text) {
return 1;
}
static_assert(std::is_same_v<std::remove_cvref_t<decltype(*text)>, codecs::secret_text<44>>);
std::cout << "base64: " << text->view() << '\n';
// base64url writes no padding by default.
auto const url_text = codecs::encode(formats::base64url, key);
if (!url_text) {
return 1;
}
std::cout << "base64url: " << url_text->view() << '\n';
// The typed decode into a secure::secret<32> is secret too; the two keys compare in constant
// time.
auto const back = codecs::decode<secure::secret<32>>(formats::base64, text->view());
if (!back) {
return 1;
}
std::cout << "round trip equal: " << (secure::constant_time_equal(*back, key) ? "yes" : "no")
<< '\n';
// A token asks for the result it wants; a secret input into return_string is a std::string,
// as the caller asked, and it is the caller's to erase.
auto const as_string = codecs::encode(formats::base64, key, codecs::tokens::return_string);
if (!as_string) {
return 1;
}
std::cout << "as a std::string: " << as_string->size() << " characters\n";
// A secret result is not copied by accident: clone() asks for it by name.
codecs::secret_text<44> const copy = text->clone();
std::cout << "clone: " << (copy.view() == text->view() ? "same" : "different") << '\n';
// The padding is checked: "Zh==" has non-zero bits after its one byte.
auto const bad = codecs::decode(formats::base64, std::string_view{"Zh=="});
std::cout << "Zh==: " << bad.error().message() << '\n';
}
base64: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8= base64url: AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8 round trip equal: yes as a std::string: 44 characters clone: same Zh==: the padding is missing, misplaced or not zero
Pitfalls.
-
PEM and MIME wrap base64 in lines;
formats::base64refuses the line breaks. PEM’s own format isformats::armor(armor). -
A padded stream decoder holds the bytes that the characters of a group’s third and fourth places give, which are
=in the last group of a short input, until the next character orflush, as base32’s does. -
A secret key goes through a
secure::secret, which makes the operation secret and the result asecret_text; the same call with astd::vectoris a public operation (Secrecy: secret operations).
base58
base58 writes the bytes as one number in base 58, its digits in an alphabet of
58 characters and each leading zero byte as the alphabet’s first character, as
Bitcoin Core’s EncodeBase58 does. The format is
formats::basic_base58<MaximumBytes, Alphabet, Checksum>, and formats::base58
is the one a program names for Bitcoin: 100 bytes of payload, Bitcoin’s
alphabet, no checksum. The program shows each of the three parameters, and the
stream.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base58.hpp>
#include <webcpp/secure/secret.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace secure = webcpp::secure;
namespace {
// An alphabet is a type with its 58 characters, digit 0 first; basic_base58 checks that they are
// 58 distinct characters. This one is Bitcoin's read backwards.
struct reversed_alphabet {
static constexpr std::string_view characters =
"zyxwvutsrqponmkjihgfedcbaZYXWVUTSRQPNMLKJHGFEDCBA987654321";
};
// A checksum is a type with its size and a constant-time compute, which runs on secrets. This is a
// toy of 4 bytes: use webcpp::hash's double SHA-256 for Bitcoin's.
struct rotate_xor_checksum {
static constexpr std::size_t size = 4;
static void compute(std::span<std::uint8_t const> payload,
std::span<std::uint8_t, size> out) noexcept {
std::ranges::fill(out, std::uint8_t{0});
for (std::size_t index = 0; index < payload.size(); ++index) {
// Rotate the byte of the checksum this payload byte falls on, then mix the byte in.
unsigned const held = out[index % size];
auto const rotated = static_cast<std::uint8_t>(((held << 1U) | (held >> 7U)) & 0xffU);
out[index % size] = static_cast<std::uint8_t>(rotated ^ payload[index]);
}
}
};
// A format of the program's own: its alphabet, its checksum, its bound of 100 bytes.
using reversed_base58 = formats::basic_base58<100, reversed_alphabet>;
using checked_base58 = formats::basic_base58<100, formats::bitcoin_alphabet, rotate_xor_checksum>;
} // namespace
int main() {
// A P2PKH address's 25 bytes: the version, 20 bytes of a hash and 4 bytes of checksum.
std::array<std::uint8_t, 25> const address_bytes{
0x00, 0x77, 0xbf, 0xf2, 0x0c, 0x60, 0xe5, 0x22, 0xdf, 0xaa, 0x33, 0x50, 0xc3,
0x9b, 0x03, 0x0a, 0x5d, 0x00, 0x4e, 0x83, 0x9a, 0xf4, 0x15, 0x76, 0x6b,
};
auto const address = codecs::encode(formats::base58, address_bytes);
if (!address) {
return 1;
}
std::cout << "address: " << address->view() << '\n';
auto const decoded = codecs::decode(formats::base58, address->view());
if (!decoded) {
return 1;
}
std::cout << "decoded: " << decoded->size() << " bytes, version byte "
<< static_cast<unsigned>(decoded->front()) << '\n';
// formats::base58 holds 100 bytes; its scratch is on the stack, sized by the bound, and the
// conversion is quadratic in the length. A larger instance names its bound.
std::vector<std::uint8_t> big(101);
std::iota(big.begin(), big.end(), std::uint8_t{1});
auto const refused = codecs::encode(formats::base58, big);
std::cout << "101 bytes with formats::base58: " << refused.error().message() << '\n';
auto const larger =
codecs::encode(formats::basic_base58<1024, formats::bitcoin_alphabet>{}, big);
if (!larger) {
return 1;
}
std::cout << "101 bytes with basic_base58<1024>: " << larger->size() << " characters\n";
// The version byte and the hash, 21 bytes, in an alphabet and with a checksum of the program's
// own.
std::span<std::uint8_t const> const payload = std::span{address_bytes}.first(21);
auto const reversed = codecs::encode(reversed_base58{}, payload);
if (!reversed) {
return 1;
}
std::cout << "alphabet of the program's own: " << *reversed << '\n';
auto const checked = codecs::encode(checked_base58{}, payload);
if (!checked) {
return 1;
}
std::cout << "with a checksum: " << *checked << '\n';
auto const payload_back = codecs::decode(checked_base58{}, *checked);
if (!payload_back) {
return 1;
}
std::cout << "checksum round trip: "
<< (std::ranges::equal(*payload_back, payload) ? "yes" : "no") << ", payload of "
<< payload_back->size() << " bytes\n";
std::string damaged = *checked;
damaged[5] = damaged[5] == 'E' ? 'F' : 'E';
std::cout << "a changed character: "
<< codecs::decode(checked_base58{}, damaged).error().message() << '\n';
// A secret input runs the constant-time conversion and gives a secret text of the bound's size.
secure::secret<32> key;
std::iota(key.writable().begin(), key.writable().end(), std::uint8_t{0});
auto const secret_text = codecs::encode(formats::base58, key);
if (!secret_text) {
return 1;
}
std::cout << "a secret key: secret text of " << secret_text->size() << " characters\n";
// base58 has no stream codec of its own: buffered accumulates the input and converts at flush.
auto stream = codecs::buffered(codecs::encoder(formats::base58), codecs::capacity<100>);
std::string streamed;
auto const collect = [&streamed](std::span<char const> piece) {
streamed.append(piece.data(), piece.size());
};
if (!stream.send(std::span{address_bytes}.first(10)) ||
!stream.send(std::span{address_bytes}.subspan(10)) || !stream.flush() ||
!codecs::drain(stream, collect)) {
return 1;
}
std::cout << "buffered: " << streamed << '\n';
}
address: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 decoded: 25 bytes, version byte 0 101 bytes with formats::base58: the input is longer than the format or the buffer allows 101 bytes with basic_base58<1024>: 137 characters alphabet of the program's own: zyLEnZqkQbpxSKsq8i8mmWc5zSZat with a checksum: 1BvBMSEYstWetqTFn5Au4m4GFg7xCo4TdZ checksum round trip: yes, payload of 21 bytes a changed character: the checksum does not match a secret key: secret text of 42 characters buffered: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
The cost is quadratic, so the bound caps it. Every digit depends on the whole
number, so the work grows with the square of the input’s length; there is no
streaming form and no way around it. MaximumBytes is the payload’s bound
without the checksum, 100 for formats::base58, and an input longer than it
and a text longer than maximum_characters (137 for 100 bytes) are
input_too_long by their length, before any read. A program that needs more
names a larger instance, formats::basic_base58<1024, formats::bitcoin_alphabet>{};
a decode whose payload would be longer than maximum_bytes is
input_too_long too.
The scratch is in place, on the stack. Every instance converts in an array
sized by its template, about one and a third bytes for each byte of the bound.
Nothing allocates, every size is exact, and the functions are noexcept: the
price is the stack, which a larger bound makes larger (about 1.4 KiB for 1024),
in every frame that converts. A secret conversion runs in the same scratch and
wipes it.
An alphabet of the program’s own is a type. It has a
static constexpr std::string_view characters of 58 characters, digit 0 first,
from which the tables are built at compile time. basic_base58 stops the build
with a message that says an alphabet is 58 distinct characters when they are
not. The ones of the library are bitcoin_alphabet, ripple_alphabet and
flickr_alphabet, and the formats base58_bitcoin, base58_ripple and
base58_flickr, whose bound is 100 bytes.
The checksum is a parameter. With no_checksum, the default, the payload is
the whole number. With a checksum type of the program’s own, a
static constexpr std::size_t size and a static void compute(payload, out)
that is noexcept, encode appends compute(payload) to the payload before the
conversion, and decode splits the last size bytes off, recomputes the checksum
of the rest, compares the two with secure::constant_time_equal and gives the
payload without it. A mismatch is checksum_mismatch, and fewer decoded bytes
than the checksum’s size are invalid_length. codecs defines no checksum
algorithm: webcpp::hash’s base58_with_checksum, a format over its double
SHA-256, is what Bitcoin calls Base58Check, and the checksum of the program
above is a toy. A checksum’s compute runs on secrets in a secret operation,
so it must be constant time, which the concept cannot check.
It is constant time only when the operation is secret. A public operation
runs Bitcoin Core’s conversion, with its early exits (codec<F>::constant_time
is false). A secret one, with a secure::secret or a secret_bytes as the
input or a secret token as the destination, runs a conversion whose operations
depend on the length of the input alone, the alphabet read by
secure::constant_time::lookup, and the checksum compared inside the engaged
timing guard (constant_time_when_secret is true for every instance). The
length of the text and the success of the call are public.
Pitfalls.
-
formats::base58refuses 101 bytes. It is a bound and not a bug; name the larger instance. -
A secret input’s result is a
secret_text<N>withNthe bound for the input’s length, so that the text of a 32-byte key is held in 44 characters, 42 of them here. -
A drain of
codecs::encoder(formats::base58)does not compile: base58 has no native stream, and the message namescodecs::buffered. The program streams throughbuffered(encoder(format), codecs::capacity<100>), which accumulates the input in place and converts atflush; an input past the capacity is accepted and reported atflushasinput_too_long. -
Input and output must not overlap.
bech32 and bech32m
bech32 (BIP-173) and bech32m (BIP-350) write a human-readable part, the
separator 1, the data in 5-bit groups and a checksum of six characters over
both, in an alphabet of 32 characters. formats::bech32 and formats::bech32m
are the instances of 90 characters over bytes, and the human-readable part is
configured by a call and held in the format value: formats::bech32("npub").
A format with none decodes any part, and encodes nothing:
codecs::decode<formats::bech32_t::parts_type>(formats::bech32, text) gives
the part and the data of any text. Encode writes lower case; decode takes
either, not both (mixed_case).
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/bech32.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string_view>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// A Nostr public key: 32 bytes, held in place, so the text is a text<63> with no heap.
constexpr std::array<std::uint8_t, 32> public_key{
0x3b, 0xf0, 0xc6, 0x3f, 0xcb, 0x93, 0x46, 0x34, 0x07, 0xaf, 0x97, 0xa5, 0xe5, 0xee, 0x64, 0xfa,
0x88, 0x3d, 0x10, 0x7e, 0xf9, 0xe5, 0x58, 0x47, 0x2c, 0x4e, 0xb9, 0xaa, 0xae, 0xfa, 0x45, 0x9d,
};
// BIP-350's Taproot program: 32 bytes, x-only public key of the generator.
constexpr std::array<std::uint8_t, 32> program{
0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07,
0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98,
};
// BOLT 11's first example invoice, 304 characters, longer than formats::bech32's 90.
constexpr std::string_view invoice =
"lnbc1pvjluezsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygspp5qqqsyqcyq5rqwzqfqqqsyqcy"
"q5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxa"
"q9qrsgq357wnc5r2ueh7ck6q93dj32dlqnls087fxdwk8qakdyafkq3yap9us6v52vjjsrvywa6rt52cm9r9zqt8r2t7"
"mlcwspyetp5h2tztugp9lfyql";
} // namespace
int main() {
// The human-readable part is configured by a call and held in the format value.
auto const npub = formats::bech32("npub");
auto const text = codecs::encode(npub, public_key);
if (!text) {
return 1;
}
std::cout << "npub: " << text->view() << " (" << text->size() << " characters)\n";
auto const key = codecs::decode<codecs::bytes<32>>(npub, text->view());
if (!key) {
return 1;
}
std::cout << "decoded: " << key->size() << " bytes, the first is 0x" << std::hex
<< static_cast<unsigned>(key->view().front()) << std::dec << '\n';
// Another part is refused, whatever the checksum says; the format with none accepts any.
auto const wrong_part = codecs::decode(formats::bech32("nsec"), text->view());
std::cout << "nsec: " << wrong_part.error().message() << '\n';
auto const any = codecs::decode<formats::bech32_t::parts_type>(formats::bech32, text->view());
if (!any) {
return 1;
}
std::cout << "any part: " << any->human_readable_part.view() << ", " << any->data.size()
<< " bytes\n";
// A segwit version is a word, a 5-bit value, never a byte: words mode writes it as it is.
std::vector<std::uint8_t> words{1};
formats::append_words_from_bytes(words, program);
auto const taproot = codecs::encode(formats::bech32m("bc").words(), words);
if (!taproot) {
return 1;
}
std::cout << "taproot in words: " << *taproot << '\n';
auto const taproot_words = codecs::decode(formats::bech32m("bc").words(), *taproot);
if (!taproot_words) {
return 1;
}
std::array<std::uint8_t, 40> decoded_program{};
auto const program_size =
formats::bytes_from_words(std::span{*taproot_words}.subspan(1), std::span{decoded_program});
if (!program_size) {
return 1;
}
std::cout << "its version word is " << static_cast<unsigned>(taproot_words->front())
<< " and its program is " << *program_size << " bytes\n";
// The version as a byte is another text, and no address.
std::vector<std::uint8_t> version_and_program{1};
version_and_program.insert(version_and_program.end(), program.begin(), program.end());
auto const as_byte = codecs::encode(formats::bech32m("bc"), version_and_program);
if (!as_byte) {
return 1;
}
std::cout << "the version as a byte: " << *as_byte << '\n';
// A larger instance reads an invoice: its data are words, and the timestamp is the first seven.
auto const lightning = formats::basic_bech32<formats::bech32_variant::bech32, 2048>{}("lnbc");
auto const invoice_words = codecs::decode(lightning.words(), invoice);
if (!invoice_words) {
return 1;
}
unsigned long long timestamp = 0;
for (std::size_t index = 0; index < 7; ++index) {
timestamp = (timestamp * 32) + (*invoice_words)[index];
}
std::cout << "a Lightning invoice: " << invoice_words->size() << " words, the timestamp is "
<< timestamp << '\n';
auto const default_instance = codecs::decode(formats::bech32("lnbc").words(), invoice);
std::cout << "the default instance: " << default_instance.error().message() << '\n';
}
npub: npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 (63 characters) decoded: 32 bytes, the first is 0x3b nsec: the prefix or label is not the format's any part: npub, 32 bytes taproot in words: bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0 its version word is 1 and its program is 32 bytes the version as a byte: bc1q9umuen7l8wthtz45p3ftn58pvrs9xlumvkuu2xet8egzkcklqtesq0reqa a Lightning invoice: 293 words, the timestamp is 1496314658 the default instance: the input is longer than the format or the buffer allows
The maximum length is a template parameter. basic_bech32<Variant, MaximumLength, Data>
names the longest text, 90 by default, so that the scratch, the stream
decoder’s hold and the results of every form are in place, sized from it, and
nothing allocates. A text past it is input_too_long, before it is read. A
Lightning invoice, which has no length limit of BIP-173’s 90 characters, is
read by a larger instance (2048 in the program); formats::bech32 reports
input_too_long for it, and its stream decoder has delivered nothing. The
shortest text is 8 characters, and a smaller MaximumLength stops the build.
A word is a 5-bit value, not a machine word. In bytes mode, the default, the
data are bytes regrouped from 8 bits to 5 with zero padding, as BIP-173’s
convertbits does, and decode refuses more than 4 padding bits or a non-zero
one with invalid_padding. In words mode, format.words(), each element is one
value from 0 to 31 written and read as it is, and a value above 31 is refused
on encode with invalid_character. formats::append_words_from_bytes(words, bytes)
regroups bytes into words after a word the program has put first, and
formats::bytes_from_words(words, output) regroups words back into bytes, in
constant time as the format is.
A segwit version is a word, never a byte. This is the pitfall of the example:
BIP-350’s Taproot address is the version word 1 followed by the program’s
words, and the bytes mode of the same two values, the byte 0x01 and then the
program, is a different text, which is not the address. A program that builds
an address puts the version into a words-mode format first, bech32 for
version 0 and bech32m above, and the same program takes the version back from
the first word of the decoded words.
What it leaves to webcpp::bitcoin. codecs applies none of segwit’s rules, the versions, the sizes of the programs and the networks’ prefixes, and parses none of Lightning’s fields: a segwit decoder checks the version and the program’s size, and a Lightning one reads the invoice’s tagged fields from the words. A future webcpp::bitcoin owns both. What codecs checks is the format: the checksum, the case, the alphabet, the part, the length.
Pitfalls.
-
The human-readable part of the format is a configuration, and a fault of it (84 characters, or one outside 33 to 126) is
invalid_prefix, reported before any data is read, by the one-shot call and by the stream’s first call. -
A decode with a part other than the format’s is
invalid_prefixeven when the checksum is right; the format with no part is how a program reads any. -
The stream decoder holds the raw characters, up to the maximum length, and delivers nothing before
flushhas checked the checksum: a program that reads an invoice from a socket sees no byte until the last character. The hold iscodecs::decoder(format, codecs::capacity<N>), at most the format’s maximum length, which stops the build when it is more. -
The stream encoder writes the part and the data as it goes and the checksum at
flush.
percent
percent is percent-encoding (RFC 3986 section 2.1) over Boost.URL: each byte
outside a CharSet as % and two hex digits. formats::percent leaves the
unreserved characters as they are, and formats::percent(char_set, options)
takes any Boost.URL CharSet, boost::urls::pchars or a set of the program’s
own built with boost::urls::grammar::lut_chars, and a
boost::urls::encoding_opts, which chooses the case of the digits and writes a
space as a plus sign. The sizes, encode and decode are Boost.URL’s own, byte for
byte. It is the one header that includes Boost.URL, and a program that includes
it names /webcpp/codecs//percent, whose decode is compiled.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/percent.hpp>
#include <boost/url/encoding_opts.hpp>
#include <boost/url/grammar/string_token.hpp>
#include <boost/url/rfc/pchars.hpp>
#include <iostream>
#include <string>
#include <string_view>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace urls = boost::urls;
int main() {
// The last two bytes are the UTF-8 of an e with an acute accent.
std::string_view const segment = "tea & coffee/ caf\xC3\xA9";
// A path segment leaves the characters of RFC 3986's pchar as they are. Boost.URL's string
// token appends to the URL, which is how Boost.URL's own functions are given their results.
std::string url = "https://example.com/files/";
auto const path = formats::percent(urls::pchars);
if (!codecs::encode(path, segment, urls::string_token::append_to(url))) {
return 1;
}
std::cout << "url: " << url << '\n';
// The default format leaves the unreserved characters alone, and escapes the rest.
auto const unreserved = codecs::encode(formats::percent, segment);
if (!unreserved) {
return 1;
}
std::cout << "unreserved only: " << *unreserved << '\n';
// A query value writes a space as a plus sign, and a plus sign as %2B.
auto const query = formats::percent(urls::pchars, urls::encoding_opts{true});
auto const value = codecs::encode(query, std::string_view{"a b+c"});
if (!value) {
return 1;
}
std::cout << "query: q=" << *value << '\n';
// Decode is Boost.URL's, byte for byte; the default result is a vector of bytes.
auto const decoded = codecs::decode(path, std::string_view{"tea%20&%20coffee%2F%20caf%C3%A9"});
if (!decoded) {
return 1;
}
std::cout << "decoded: " << std::string{decoded->begin(), decoded->end()} << '\n';
auto const plus = codecs::decode(query, std::string_view{"a+b%2Bc"});
if (!plus) {
return 1;
}
std::cout << "a plus is a space: " << std::string{plus->begin(), plus->end()} << '\n';
// A truncated escape and a bad digit are errors of codecs, values.
std::cout << "%4: " << codecs::decode(path, std::string_view{"%4"}).error().message() << '\n';
std::cout << "%zz: " << codecs::decode(path, std::string_view{"%zz"}).error().message() << '\n';
}
url: https://example.com/files/tea%20&%20coffee%2F%20caf%C3%A9 unreserved only: tea%20%26%20coffee%2F%20caf%C3%A9 query: q=a+b%2Bc decoded: tea & coffee/ café a plus is a space: a b+c %4: the length is one no encoding of the format has %zz: a character is outside the format's alphabet
Pitfalls.
-
The
CharSetis the characters left as they are, and each piece of a URL has its own: a path segmentpchars, a query value the same withencoding_opts{true}for the plus sign, and a program that picks the defaultunreservedset escapes more than a URL needs and never less. -
The percent sign is never in the set: it is written
%25whatever the set holds. -
Decode does not check that the characters it takes as they are belong to the set. A text that holds a character the set would escape decodes to that character; checking the text against a grammar is Boost.URL’s parser’s job.
-
A
%followed by a character that is no hex digit isinvalid_character, and a text that ends inside an escape isinvalid_length;%gis both and gets the lower value,invalid_character. -
percent is not constant time. A secret that must not leak through time is written in a format that is.
armor
The armor is RFC 7468’s strict textual encoding, which OpenSSL writes as PEM:
-----BEGIN <label>-----, the padded base64 of the bytes in lines of 64
characters, the last shorter, and -----END <label>-----, each line ended by a
line feed. The label, of up to 64 characters, is configured by a call and held
in the format value, formats::armor("PUBLIC KEY"), whose label() gives it
back. A format with no label encodes nothing (invalid_prefix) and decodes any:
codecs::decode<formats::armor_parts>(formats::armor, text) gives the label and the
bytes. The payload is base64’s, in constant time; the structure (line endings,
the boundary lines and their positions, the label) is public, and the decoder
branches on it.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/armor.hpp>
#include <webcpp/codecs/hex.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// The label of a public key follows from what the bytes are: it is in a type of the program's own.
struct public_key_label {
static constexpr std::string_view value = "PUBLIC KEY";
};
// The 91 bytes of a P-256 public key's SubjectPublicKeyInfo: its fixed header, then the
// uncompressed point's tag and 64 bytes (here 1 to 64, so that the example needs no key).
std::array<std::uint8_t, 91> subject_public_key_info() {
constexpr std::array<std::uint8_t, 27> header{
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06,
0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04,
};
std::array<std::uint8_t, 91> der{};
std::ranges::copy(header, der.begin());
for (std::size_t index = 0; index < 64; ++index) {
der[header.size() + index] = static_cast<std::uint8_t>(index + 1);
}
return der;
}
} // namespace
int main() {
std::array<std::uint8_t, 91> const der = subject_public_key_info();
// The label is held in the format; the lines are 64 characters, each ended by a line feed.
auto const pem_format = formats::armor("PUBLIC KEY");
auto const pem = codecs::encode(pem_format, der);
if (!pem) {
return 1;
}
std::cout << pem->view();
// The default decode is a vector of bytes, as the text's size is not static.
std::string const text{pem->view()};
auto const bytes = codecs::decode(pem_format, text);
if (!bytes) {
return 1;
}
std::cout << "decoded: " << bytes->size()
<< " DER bytes, equal: " << (std::ranges::equal(*bytes, der) ? "yes" : "no") << '\n';
// When the label follows from what the bytes are, it is in the type: no value of the format
// holds another, and the text is the same.
auto const fixed_text = codecs::encode(formats::basic_armor<public_key_label>{}, der);
if (!fixed_text) {
return 1;
}
std::cout << fixed_text->view();
// A label other than the format's is refused; a format with no label takes any.
auto const certificate = codecs::decode(formats::armor("CERTIFICATE"), text);
std::cout << "CERTIFICATE: " << certificate.error().message() << '\n';
auto const parts = codecs::decode<formats::armor_parts>(formats::armor, text);
if (!parts) {
return 1;
}
std::cout << "any label: " << parts->label.view() << ", " << parts->data.size() << " bytes\n";
// Lines end by a line feed or by a carriage return and a line feed.
std::string crlf;
for (char const character : text) {
if (character == '\n') {
crlf += '\r';
}
crlf += character;
}
auto const from_windows = codecs::decode(pem_format, crlf);
std::cout << "CRLF line ends: " << from_windows.value().size() << " bytes\n";
// The strict form refuses explanatory text, a second armor, and whitespace inside a line.
auto const explained = codecs::decode(pem_format, "Subject: a key\n" + text);
std::cout << "text before BEGIN: " << explained.error().message() << '\n';
auto const twice = codecs::decode(pem_format, text + text);
std::cout << "two armors in a row: " << twice.error().message() << '\n';
std::string spaced = text;
spaced.insert(spaced.find('\n', 1) + 5, " ");
auto const with_space = codecs::decode(pem_format, spaced);
std::cout << "a space in a line: " << with_space.error().message() << '\n';
// The armor composes: it armors the output of any bytes format. Here hex's text, as bytes.
std::array<std::uint8_t, 5> const small{1, 2, 3, 4, 5};
auto const armored_hex =
codecs::encode(codecs::over{formats::armor("BLOB"), formats::hex}, small);
if (!armored_hex) {
return 1;
}
std::cout << "armor over hex: " << armored_hex->view();
}
-----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAQIDBAUGBwgJCgsMDQ4PEBESExQV FhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QA== -----END PUBLIC KEY----- decoded: 91 DER bytes, equal: yes -----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAQIDBAUGBwgJCgsMDQ4PEBESExQV FhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QA== -----END PUBLIC KEY----- CERTIFICATE: the prefix or label is not the format's any label: PUBLIC KEY, 91 bytes CRLF line ends: 91 bytes text before BEGIN: the prefix or label is not the format's two armors in a row: the length is one no encoding of the format has a space in a line: the length is one no encoding of the format has armor over hex: -----BEGIN BLOB----- MDEwMjAzMDQwNQ== -----END BLOB-----
The strict form. The decoder takes lines ended by a line feed or by a carriage return and a line feed, the last line ending optional, and refuses everything the lenient parsers of PEM tolerate. Exactly one armor is decoded: two back to back are one text whose last line is the second END boundary, with the first END and the second BEGIN among its payload lines. The errors, in the order of the checks:
| Error | What it says |
|---|---|
|
a boundary is at fault: the first line is not |
|
the lines are at fault: a line of the payload longer than 64 characters or shorter before the last, an empty line, RFC 1421’s headers and their empty line, or a space added to a line that makes it too long |
|
base64’s own, over the payload’s symbols, the lowest value first: a character that is no symbol (a space among them), a count of symbols that is not a multiple of 4, padding out of its place or non-zero bits at its end |
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.
// The label of a public key follows from what the bytes are: it is in a type of the program's own.
struct public_key_label {
static constexpr std::string_view value = "PUBLIC KEY";
};
// When the label follows from what the bytes are, it is in the type: no value of the format
// holds another, and the text is the same.
auto const fixed_text = codecs::encode(formats::basic_armor<public_key_label>{}, der);
if (!fixed_text) {
return 1;
}
std::cout << fixed_text->view();
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 (Composition: over).
Pitfalls.
-
A PEM file written by another tool with a header (
Proc-Type), a blank line or text before the boundary is refused: this is the strict form, and it is what RFC 7468 asks a producer to write. Strip what is not the armor first. -
armor_partsholds its bytes in astd::vector; a decode into it allocates. -
The label is part of the data’s identity:
CERTIFICATEis notPUBLIC KEYwhatever the bytes are, and the wrong one isinvalid_prefix. -
Input and output must not overlap.
Tokens: where a result goes
codecs::encode(format, input, token) and codecs::decode(format, text, token)
take a token that says where the result goes and what it is, and return
result<typename Token::result_type>. With no token the result is the default
one (Results: the default and the fixed ones, and the typed decode). The tokens are the model of Boost.URL’s string tokens,
so that the tokens of Boost.URL work unchanged, in both directions: for a
decode the bytes arrive as characters, or into a std::vector<std::uint8_t>.
| Token | What it does | Result |
|---|---|---|
|
the default token, what the call without one means |
the default result |
|
builds a string, of the allocator when one is given |
|
|
appends to a |
a reference to |
|
replaces the container’s content with the result, which is converted aside first, so that the input may be a part of the target |
a reference to |
|
holds up to |
|
|
makes the operation secret, whatever the input is (Secrecy: secret operations) |
|
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace tokens = webcpp::codecs::tokens;
namespace {
// ... own_token: shown in its own section of the page
} // namespace
int main() {
std::array<std::uint8_t, 16> identifier{};
std::iota(identifier.begin(), identifier.end(), std::uint8_t{0});
std::vector<std::uint8_t> const runtime(identifier.begin(), identifier.end());
// The default token: a text<32> for an input of a static size, a std::string otherwise.
auto const automatic = codecs::encode(formats::hex, identifier);
static_assert(std::is_same_v<std::remove_cvref_t<decltype(*automatic)>, codecs::text<32>>);
auto const dynamic = codecs::encode(formats::hex, runtime);
static_assert(std::is_same_v<std::remove_cvref_t<decltype(*dynamic)>, std::string>);
std::cout << "automatic: " << automatic.value().view() << '\n';
// return_string asks for a std::string, whatever the input's size is known.
auto const as_string = codecs::encode(formats::hex, identifier, tokens::return_string);
static_assert(std::is_same_v<std::remove_cvref_t<decltype(*as_string)>, std::string>);
std::cout << "return_string: " << as_string.value().size() << " characters\n";
// append_to adds to a string and gives it back by reference; assign_to replaces its content.
std::string line = "id=";
auto const appended = codecs::encode(formats::hex, identifier, tokens::append_to(line));
std::cout << "append_to: " << line << (&appended.value() == &line ? " (the same string)" : "")
<< '\n';
std::string slot = "old";
if (!codecs::encode(formats::hex, runtime, tokens::assign_to(slot))) {
return 1;
}
std::cout << "assign_to: " << slot << '\n';
// fixed<N> holds up to N characters in place; a result that does not fit is an error, and
// nothing is written.
auto const fixed = codecs::encode(formats::hex, runtime, tokens::fixed<40>{});
std::cout << "fixed<40>: " << fixed.value().size() << " of " << codecs::text<40>::capacity()
<< " characters\n";
auto const too_small = codecs::encode(formats::hex, runtime, tokens::fixed<16>{});
std::cout << "fixed<16>: " << too_small.error().message() << '\n';
// The bytes of a decode go to a vector the same way, and a text that does not decode leaves
// the vector as it was.
std::vector<std::uint8_t> received{0xaa};
if (!codecs::decode(formats::hex, std::string_view{"0102"}, tokens::append_to(received))) {
return 1;
}
std::cout << "decode append_to: " << received.size() << " bytes\n";
auto const refused =
codecs::decode(formats::hex, std::string_view{"01zz"}, tokens::append_to(received));
std::cout << "a bad text: " << refused.error().message() << ", still " << received.size()
<< " bytes\n";
// A token of the program's own.
auto const characters = codecs::encode(formats::hex, identifier, vector_token{});
std::cout << "own token: "
<< std::string_view{characters.value().data(), characters.value().size()} << '\n';
}
automatic: 000102030405060708090a0b0c0d0e0f return_string: 32 characters append_to: id=000102030405060708090a0b0c0d0e0f (the same string) assign_to: 000102030405060708090a0b0c0d0e0f fixed<40>: 32 of 40 characters fixed<16>: the output is shorter than the result decode append_to: 3 bytes a bad text: a character is outside the format's alphabet, still 3 bytes own token: 000102030405060708090a0b0c0d0e0f
The order of the checks
A call checks in a fixed order, which every token shares: a fault of the
format’s configuration first, then a fault the format’s encode has (bech32 with
no human-readable part, a text past its longest or a word above 31, the armor
with no label), whatever the input’s size, then every other check of the input
(an input whose result does not fit in std::size_t is input_too_long, a
text is checked whole), then the token’s capacity against the exact size
(output_too_small),
then one prepare with the exact size, the conversion, and one result. A
token is untouched when a check fails. A token of codecs’ is untouched, too, when
the conversion fails after prepare, which a value codec’s own error does:
append_to is put back as it was, assign_to converts into a scratch and copies
it into the container only on success (the scratch is in place when the bound is
known at compile time and at most 4096 elements, and the container’s allocator’s
otherwise), and return_string builds nothing the caller sees.
A token of the program’s own
A text token has result_type, prepare(n) returning char* for exactly n
characters, and result(); a byte token, for the bytes of a decode or of a
value codec of bytes, returns a pointer to a one-byte element from prepare.
codecs calls prepare at most once, with the exact size, after every check has
passed, then result once. A static constexpr std::size_t capacity is
compared before prepare, and a static constexpr bool secret set to true
makes the operation secret.
// A token of the program's own: result_type, prepare(size), which gives the room for exactly the
// result and is called once, after every check has passed, and result(), called once. This is
// Boost.URL's contract for a string token, so that Boost.URL's tokens work unchanged.
class vector_token {
public:
using result_type = std::vector<char>;
char* prepare(std::size_t size) {
characters_.resize(size);
return characters_.data();
}
result_type result() { return std::move(characters_); }
private:
std::vector<char> characters_;
};
Boost.URL’s tokens
Boost.URL’s string_token::return_string, append_to and assign_to of a
std::string are tokens as they are. A program that includes
<boost/url/grammar/string_token.hpp> and names /webcpp/codecs//percent, as the
percent example does (percent), appends a conversion to a URL under
construction with boost::urls::string_token::append_to(url), in the same call
Boost.URL’s own functions use. An invalid decode leaves the string unchanged.
Pitfalls
-
A token of codecs’ that the pair does not take stops the build with a message that names the token’s type:
append_toof astd::vectoris for decode, not encode. -
append_toandassign_totake the container by reference and give it back by reference: the result is valid as long as the container is. The input must not be a part of the container forappend_to. -
A token of the program’s own that receives a secret’s text keeps it, and wiping it is the program’s job; a token whose
secretis true makes the operation secret even when its input is public. A secret input intoreturn_stringgives astd::stringas asked, which the caller erases. -
A call with an allocator in its token allocates, and so it is not
noexcept(Allocators);fixed<N>and the in-placesecretare.
Results: the default and the fixed ones, and the typed decode
With no token, encode returns a text and decode returns bytes, and the type
follows what the program has told the compiler about the size.
| Call | When the size is known at compile time | Otherwise |
|---|---|---|
|
|
|
|
|
|
An input’s size is known when its type states it: a std::array of bytes, a
byte array, a std::span<T, N> of a static extent, text<N> and bytes<N>,
and a type with a static size() that converts to a fixed-extent span, as
secure::secret<N> does. A string literal is a text, not an array of bytes.
text<N> and bytes<N> hold their elements in place with an actual size,
size(), at most N, the capacity. They compare by content, and convert on an
lvalue to a std::string_view and a std::span<std::uint8_t const>; the
conversion of an rvalue is a compile-time error, so that no view outlives the
text it looks at. They are inputs too: a text<64> is a text to decode, and a
bytes<32> the bytes to encode.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base64.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
template <class T, class Expected>
constexpr bool is_a = std::is_same_v<std::remove_cvref_t<T>, Expected>;
} // namespace
int main() {
std::array<std::uint8_t, 4> const four{0xde, 0xad, 0xbe, 0xef};
std::vector<std::uint8_t> const many{0xde, 0xad, 0xbe, 0xef};
// An input of a size the type states: the result is in place, as large as the format's bound.
auto const fixed_text = codecs::encode(formats::base64, four);
static_assert(is_a<decltype(*fixed_text), codecs::text<8>>);
std::cout << "base64 of a std::array<4>: " << fixed_text.value().view() << ", capacity "
<< codecs::text<8>::capacity() << ", size " << fixed_text.value().size() << '\n';
// An input of a run-time size: a std::string.
auto const heap_text = codecs::encode(formats::base64, many);
static_assert(is_a<decltype(*heap_text), std::string>);
// Texts of a static size decode to bytes<N>, with an actual size; the others to a vector.
auto const fixed_bytes =
codecs::decode(formats::hex, codecs::encode(formats::hex, four).value());
static_assert(is_a<decltype(*fixed_bytes), codecs::bytes<4>>);
std::cout << "bytes<4>: size " << fixed_bytes.value().size() << '\n';
auto const heap_bytes = codecs::decode(formats::hex, std::string_view{"deadbeef"});
static_assert(is_a<decltype(*heap_bytes), std::vector<std::uint8_t>>);
// Both convert, on an lvalue, to what a function takes; they compare by content.
std::span<std::uint8_t const> const view = fixed_bytes.value();
std::cout << "the view has " << view.size() << " bytes; equal to the vector: "
<< (std::equal(view.begin(), view.end(), heap_bytes.value().begin()) ? "yes" : "no")
<< '\n';
// The typed decode: exactly 4 bytes in a std::array, or invalid_length.
auto const exact =
codecs::decode<std::array<std::uint8_t, 4>>(formats::hex, std::string_view{"deadbeef"});
std::cout << "decode<std::array<std::uint8_t, 4>>: " << (exact ? "ok" : "failed") << '\n';
auto const too_many =
codecs::decode<std::array<std::uint8_t, 4>>(formats::hex, std::string_view{"deadbeef00"});
std::cout << "five bytes into four: " << too_many.error().message() << '\n';
// bytes<N> takes up to N, and the vector and the string take any.
auto const up_to = codecs::decode<codecs::bytes<8>>(formats::hex, std::string_view{"deadbeef"});
std::cout << "decode<bytes<8>>: " << up_to.value().size() << " of "
<< codecs::bytes<8>::capacity() << " bytes\n";
auto const as_string = codecs::decode<std::string>(formats::hex, std::string_view{"6869"});
std::cout << "decode<std::string>: " << as_string.value() << '\n';
}
base64 of a std::array<4>: 3q2+7w==, capacity 8, size 8 bytes<4>: size 4 the view has 4 bytes; equal to the vector: yes decode<std::array<std::uint8_t, 4>>: ok five bytes into four: the length is one no encoding of the format has decode<bytes<8>>: 4 of 8 bytes decode<std::string>: hi
The typed decode
codecs::decode<Value>(format, input) returns result<Value> for every
Value the format and the core can build. The untyped overloads are never
chosen when a type argument is given.
Value |
What it gives |
|---|---|
|
exactly |
|
up to |
|
any number of bytes, as bytes or as characters |
|
exactly |
|
up to |
the type of a value codec |
the library’s own conversion, with its own errors (Writing a format) |
a type with |
exactly |
Decoding a pair that does not exist, decode<std::chrono::seconds>(formats::hex, text),
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. A type that declares its formats
is refused by its declaration instead (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
codecs::encoded_size(format, input) is the exact size of what encode writes,
and codecs::max_decoded_size(format, text) a bound on what decode writes,
from the text’s size alone; both are constant expressions where the format and the
input are. A bound that does not fit in std::size_t saturates at its maximum,
and every form refuses an input whose bound saturates with input_too_long
before it reads it: on a 32-bit target, where std::size_t is 32 bits, an
input of 3.3 GB never wraps into a small bound. encoded_size has no error
channel, and gives SIZE_MAX for an input every encode refuses for its size
and 0 for one refused for a fault of the format’s configuration or of the
encode (bech32 with no human-readable part, the armor with no label), the rule a
transformer’s output_size keeps too.
codecs::encode(format, input, std::span<char> output) and
codecs::decode(format, text, std::span<std::uint8_t> output) write into the
caller’s buffer and return the number of elements written; an output shorter
than the exact size is output_too_small, nothing is written on any error, and
they allocate nothing and are noexcept, except for over with a heap
intermediate (Composition: over).
Pitfalls
-
Every function that returns a
result<T>is[[nodiscard]]; an error is a value, andresult::value()throws when it is read on an error, as it does in Boost.System. Check it, or take the error fromerror(). -
A
text<N>is as large as the format’s bound for the input, not as the text: thebase64of four bytes is atext<8>, and that text decodes to abytes<6>that holds 4 bytes: the size is 4 and the capacity 6. Usesize(). -
A view of a result is valid as long as the result is: take it from a named
textand not from the call’s temporary, which the compiler refuses. -
The default result of a text that is a
std::string_viewis astd::vector<std::uint8_t>, which allocates; a program that wants no heap names a static size,std::span<char const, N>ortext<N>, or a token (Tokens: where a result goes).
Secrecy: secret operations
A key, a seed or a password converted to text should not leak through the time the conversion takes, nor stay in memory after it. codecs keeps both promises for an operation it calls secret, through webcpp::secure, and keeps no guard, wipe or constant-time primitive of its own. (The program of base64 and base64url is the example: a key as base64.)
When an operation is secret
An operation is secret when any of these holds:
-
the input’s type is secret:
codecs::is_secret_v<T>is true, which codecs specializes forsecure::secret<N>and for its own secret results, and a library specializes for its own secret types (Writing a format); -
the value codec states
static constexpr bool secret = true; -
the token’s
secretis true:tokens::secretandtokens::secret(allocator); -
the requested type of a typed decode is secret:
decode<secure::secret<32>>,decode<secret_bytes<32>>,decode<secret_byte_vector>; -
the transformer is made with
codecs::secret_operation, or is a pipe or an adapter with a secret part (Streams and transformers).
A public operation pays nothing for this: the guard is engaged only when the operation is secret.
What a secret operation does
-
It holds secure’s
timing_guard, engaged, in the function that runs it: on 64-bit ARM under Apple, Linux, Android and Windows the thread’s DIT bit is set for the operation and restored after it, nested in any order with the guards of a pipe’s parts. -
It returns the secret results (below), which are wiped when they are destroyed or moved from.
-
It wipes every buffer of the library’s that held its bytes, with
secure::erase_secret: the scratch of base58’s conversion, the intermediate ofover, a stream’s carries and error masks, the buffer ofdrain, the storage ofeachandbuffered, and what a token of codecs’ does not give back. This holds on the error paths and when an allocation throws. -
It runs the format’s secret arithmetic where the format has one: base58’s constant-time conversion, in place of Bitcoin Core’s conversion with its early exits.
The secret results are secret_text<N> and secret_bytes<N>, held in place when
the size is known at compile time, and secret_string and secret_byte_vector,
on the heap, otherwise (their std::pmr aliases are codecs::pmr::secret_string
and codecs::pmr::secret_byte_vector, and the allocator form is
basic_secret_string<Allocator>). Each is move-only, copied only by clone(),
has no operator==, and wipes every byte it held, by secure::erase_secret,
before its storage goes. A view of one, view(), is valid as long as it is,
and is not offered on a temporary.
What is constant time
The encode and decode of hex, base32, base32hex, zbase32, base64, base64url,
bech32, bech32m and the armor’s payload are constant time on every call, one-shot and
streamed, public or secret: they index no table by a data byte and branch on no
data byte, a decode accumulates its verdict over the whole input and reports it
once, and codec<F>::constant_time is true. base58’s is constant time when the
operation is secret (constant_time_when_secret). percent is not.
What is public, whatever the operation. The length of the input, the length
of the output, the format’s options, bech32’s human-readable part, the armor’s
structure (its line endings, the optional final line ending, the boundary lines
and their positions, and the label) and whether the call succeeded. The
verdict is passed through secure::declassify once, where it is branched on
by design, and the constant-time lane of the library’s tests, which runs the
formats under memcheck, MemorySanitizer and dudect with a planted leak that
must fail, checks nothing else is. A stream decoder reports a fault only after
flush (Streams and transformers), so that the time does not say where the text was
invalid.
Secret transformers
codecs::encoder(format, codecs::secret_operation) and
codecs::decoder(format, codecs::secret_operation) make a format’s transformer
secret: each call holds the engaged guard, the transformer is move-only, and
its own pending state (a carry, a hold, the error mask) is wiped on reset, on
destruction and in the moved-from object. A pipe or a drain of a secret
transformer is secret: its intermediate or its buffer is wiped. The one-shot form
of a secret encoder(format, secret_operation) inside buffered runs
the format’s secret arithmetic at flush, so that
buffered(encoder(formats::base58, secret_operation), capacity<100>) is base58’s
constant-time stream.
What it does not do
-
It does not make a secret of what the caller keeps. A
std::stringfromreturn_stringorappend_toholds the text, and the program erases it withsecure::erase_secret; the secret results exist so that a program has a type that does it for them. -
It does not lock memory: a page of a secret may be swapped, as secure’s
erase_secretdocuments. -
It does not hide the lengths (above). A program that must hide a length pads before it calls.
-
A format with a configuration (a human-readable part, a label) treats it as public.
Composition: over
codecs::over{outer, inner} is a format made of two. Encoding encodes with the
inner format and then encodes that output, as bytes, with the outer; decoding
decodes with the outer and then with the inner. Inner may be the format of a codec
or of a value codec, whose value over converts to bytes first
(Writing a format); Outer must be the format of a codec, since its input is
the inner’s output read as bytes. The armor over any bytes format is the usual
use (over{formats::armor("PUBLIC KEY"), inner}).
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base64.hpp>
#include <webcpp/codecs/hex.hpp>
#include <webcpp/secure/secret.hpp>
#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace secure = webcpp::secure;
int main() {
std::array<std::uint8_t, 16> bytes{};
std::iota(bytes.begin(), bytes.end(), std::uint8_t{0});
// The hex of the base64 of the bytes. The chain's name says which: the outer link first.
auto const chain = codecs::over{formats::hex, formats::base64};
std::cout << "name: " << decltype(chain)::name << '\n';
auto const text = codecs::encode(chain, bytes);
if (!text) {
return 1;
}
std::cout << "text: " << text->view() << '\n';
// Decode runs the other way: hex, then base64. The size is static, so the bytes are in place.
auto const back = codecs::decode(chain, *text);
if (!back) {
return 1;
}
std::cout << "back: " << back->size() << " bytes, equal: "
<< (std::equal(bytes.begin(), bytes.end(), back->view().begin()) ? "yes" : "no")
<< '\n';
// An error of either link is the chain's: here the outer link's, hex, finds an odd length.
auto const odd = codecs::decode(chain, std::string_view{"414"});
std::cout << "odd length: " << odd.error().message() << '\n';
// Any bytes format is an inner link; the outer reads the inner's text as bytes.
auto const url_safe = codecs::over{formats::base64url, formats::hex};
std::array<std::uint8_t, 4> const four{0, 1, 2, 3};
auto const url_text = codecs::encode(url_safe, four).value();
std::cout << "base64url over hex: " << url_text.view() << '\n';
// A chain is secret when the input is: the intermediate is wiped, and so is the result.
secure::secret<16> key;
std::ranges::copy(bytes, key.writable().begin());
auto const secret_text = codecs::encode(chain, key);
if (!secret_text) {
return 1;
}
static_assert(codecs::is_secret_v<decltype(*secret_text)>);
std::cout << "a secret chain: " << secret_text->size() << " characters, no heap\n";
}
name: hex over base64 text: 41414543417751464267634943516f4c4441304f44773d3d back: 16 bytes, equal: yes odd length: the length is one no encoding of the format has base64url over hex: MDAwMTAyMDM a secret chain: 48 characters, no heap
The name of the chain is the outer link’s name, " over " and the inner’s,
and the chain is constructed from values by class template argument deduction,
as over{formats::hex, formats::base64} shows. It is constant time when
every link is, and secret when any link’s operation is: the core runs the links’
secret arithmetic, and the intermediate is wiped by secure::erase_secret.
Where the intermediate lives
The intermediate, the bytes between the two links, is held:
-
in place, in the frame of each function of
over, when its bound is known at compile time: when the input’s type states its size (astd::array, astd::spanof a static extent, asecure::secret,text<N>,bytes<N>) or the value codec statesmax_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, 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 itsdecodeaccepts, and it is at most 4096 bytes: the decode of a value then holds its intermediate in place whatever the text’s type, astd::string_viewincluded, 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 withinput_too_longbefore 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 astd::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 ofoveris that allocator,std::allocator<std::uint8_t>by default, deduced fromover{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, astd::span<std::uint8_t const>or astd::string_view, unless a decode bound of at most 4096 bytes holds it in place.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/armor.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <string_view>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// A format whose only job is to convert a record, and the record: 8 bytes.
struct record_t {
static constexpr std::string_view name = "record";
};
inline constexpr record_t record_format{};
struct record {
std::array<std::uint8_t, 8> bytes{};
};
// Version 1 writes 12 bytes: the prefix 30 0a 02 00 and the record. Version 2 is 16 bytes: the
// prefix 30 0e 02 01, the record and 4 bytes of an extension that decode ignores.
constexpr std::size_t version_1_size = 12;
constexpr std::size_t version_2_size = 16;
} // namespace
namespace webcpp::codecs {
template <>
struct value_codec<record_t, record> {
static constexpr output_kind output = output_kind::bytes;
// The longest the encode writes: the default result is a bytes<12> in place.
static constexpr std::size_t max_encoded_size = version_1_size;
// The longest input decode accepts, which the core enforces on every path: a longer input is
// input_too_long, and decode is not called. It is never below max_encoded_size, and it is
// what sizes the intermediate of over, in place.
static constexpr std::size_t max_decode_input_size = version_2_size;
static std::size_t encoded_size(record_t const& /*format*/, record const& /*value*/) noexcept {
return version_1_size;
}
static result<std::size_t> encode(record_t const& /*format*/, record const& value,
std::span<std::uint8_t> buffer) noexcept {
if (buffer.size() < version_1_size) {
return error::output_too_small;
}
constexpr std::array<std::uint8_t, 4> prefix{0x30, 0x0a, 0x02, 0x00};
std::ranges::copy(prefix, buffer.begin());
std::ranges::copy(value.bytes, buffer.begin() + 4);
return version_1_size;
}
static result<record> decode(record_t const& /*format*/,
std::span<std::uint8_t const> input) noexcept {
if (input.size() != version_1_size && input.size() != version_2_size) {
return error::invalid_length;
}
constexpr std::array<std::uint8_t, 4> prefix_1{0x30, 0x0a, 0x02, 0x00};
constexpr std::array<std::uint8_t, 4> prefix_2{0x30, 0x0e, 0x02, 0x01};
auto const& prefix = input.size() == version_1_size ? prefix_1 : prefix_2;
if (!std::ranges::equal(input.first(prefix.size()), prefix)) {
return error::invalid_prefix;
}
record decoded;
std::ranges::copy(input.subspan(prefix.size(), 8), decoded.bytes.begin());
return decoded;
}
};
} // namespace webcpp::codecs
int main() {
// The armor of the record's 12 bytes.
auto const chain = codecs::over{formats::armor("RECORD"), record_format};
record const value{{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}};
auto const text = codecs::encode(chain, value);
if (!text) {
return 1;
}
std::cout << text->view();
// The decode from a std::string: the text's size is not static, and the intermediate is
// still in place, sized by max_decode_input_size, so that nothing is allocated.
std::string const armor_text{text->view()};
auto const decoded = codecs::decode<record>(chain, armor_text);
if (!decoded) {
return 1;
}
std::cout << "decoded: " << (decoded->bytes == value.bytes ? "equal" : "different") << '\n';
// The 16-byte form, the largest the value codec accepts, decodes as well.
std::array<std::uint8_t, version_2_size> version_2{0x30, 0x0e, 0x02, 0x01};
std::ranges::copy(value.bytes, version_2.begin() + 4);
auto const version_2_text = codecs::encode(formats::armor("RECORD"), version_2);
if (!version_2_text) {
return 1;
}
auto const from_version_2 = codecs::decode<record>(chain, version_2_text->view());
std::cout << "16 bytes: " << (from_version_2 ? "decoded" : "refused") << '\n';
// A payload of 17 bytes is past the bound: input_too_long, before the intermediate is made
// and before the value codec is called.
std::array<std::uint8_t, version_2_size + 1> const too_long{};
auto const too_long_text = codecs::encode(formats::armor("RECORD"), too_long);
if (!too_long_text) {
return 1;
}
auto const refused = codecs::decode<record>(chain, too_long_text->view());
std::cout << "17 bytes: " << refused.error().message() << '\n';
// The decode of a text of a dynamic size is noexcept: it makes no allocation.
std::cout << "decoded with no heap: "
<< (noexcept(codecs::decode<record>(chain, std::string_view{})) ? "yes" : "no")
<< '\n';
}
-----BEGIN RECORD----- MAoCABAREhMUFRYX -----END RECORD----- decoded: equal 16 bytes: decoded 17 bytes: the input is longer than the format or the buffer allows decoded with no heap: yes
The allocator of a result or a token is not the intermediate’s, and the
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
before it goes back. With a bound known at compile time they are noexcept and
allocate nothing, which the allocation test checks.
One-shot, with a stream of links
over is a format of the one-shot operations. Its transformers,
codecs::encoder(chain) and codecs::decoder(chain), stream through a pipe of
the links’ streams when both links stream natively (Streams and transformers), and
are one-shot otherwise: a chain with base58 in it streams through buffered.
Errors
A fault of a link’s configuration is the chain’s, the outer link’s first, and
every form reports it before it reads any data, in either link: a chain with
formats::bech32 configured with a human-readable part of 84 characters
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
intermediate when the intermediate is in place, which the chain finds by running
the inner link into it. With a heap intermediate the outer link’s is found by
its encode, after prepare: codecs’ tokens are put back or untouched, and a
token of the program’s own is left as prepare made it, as for a value codec’s
own error.
Pitfalls
-
The intermediate on the stack grows with the input’s static size, and a chain of chains has one in each level’s frame. A program that puts a large array through
overpasses 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
overitself 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 armor, armors the hex text; a program that wants the armor of the bytes themselves uses the armor alone.
Streams and transformers
A file, a socket or a decoder of video does not give its input in one piece.
codecs has two concepts for converting a whole input at once and a stream, over
elements of any type: a byte, a character, a compressed packet, a decoded frame.
codecs::encoder(format) and codecs::decoder(format) give a format’s
transformer: a one-shot transformer always, and a stream transformer where the
format’s header says it streams natively.
The two concepts
A codecs::one_shot_transformer is movable, has input_type and output_type
that are cv-unqualified object types, and has
transform(std::span<input_type const>, std::span<output_type>) returning
result<std::size_t>. It writes all of its output or nothing, and a short output
is output_too_small. It may state, and the compositions read, a static
max_output_size(std::size_t) (a bound, constexpr where it can be) and
output_size(input) (the exact size), and static constexpr bool constant_time,
read through codecs::is_constant_time_v.
A codecs::stream_transformer has the same types and send, receive, flush
and a noexcept reset. Neither concept requires bytes, characters, constant
time, secrecy, a category tag or a virtual function.
The flow
send and receive return a step, a count and a flow, and flush a
flow. The flow is the state of the stream after the call, never an error:
"receive again" and "send more" are the normal course of a stream.
flow |
What the caller does |
|---|---|
|
everything accepted is processed: send more, or |
|
output is waiting: |
|
flushed and every output received: |
A stream starts in needs_input. send accepts input only in needs_input,
and in another state returns {0, state}. receive writes at most the span’s
size and returns the count and the state, and an empty span returns
{0, state}. flush ends the input, returns output_pending while output
remains and finished when none does, and after it nothing is accepted until
reset. reset returns the stream to needs_input with nothing borrowed or
pending, and a moved-from transformer is in that state, so that the caller
converts a new input with it. A fault is an error of the result of a call, and
every later call returns it until reset.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstdint>
#include <iostream>
#include <span>
#include <string_view>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
char const* name_of(codecs::flow state) {
switch (state) {
case codecs::flow::needs_input: return "needs_input";
case codecs::flow::output_pending: return "output_pending";
case codecs::flow::finished: return "finished";
}
return "?";
}
} // namespace
int main() {
auto encoder = codecs::encoder(formats::hex);
std::array<std::uint8_t, 64> const first{};
std::array<std::uint8_t, 4> const second{1, 2, 3, 4};
// send accepts input only in needs_input, and borrows it until the stream says it is done.
auto sent = encoder.send(first);
std::cout << "send 64: accepted " << sent.value().count << ", " << name_of(sent.value().flow)
<< '\n';
sent = encoder.send(second);
std::cout << "send 4 more: accepted " << sent.value().count << ", "
<< name_of(sent.value().flow) << '\n';
// receive writes at most the span it is given, here 50 characters of the 128 waiting.
std::array<char, 50> output{};
int receives = 0;
codecs::step got{.count = 0, .flow = codecs::flow::needs_input};
do {
got = encoder.receive(output).value();
++receives;
} while (got.flow == codecs::flow::output_pending);
std::cout << "receives of 50 characters until needs_input: " << receives << '\n';
sent = encoder.send(second);
std::cout << "send 4 again: accepted " << sent.value().count << ", "
<< name_of(sent.value().flow) << '\n';
// flush ends the input; after the last receive the stream is finished.
auto flushed = encoder.flush();
std::cout << "flush: " << name_of(flushed.value()) << '\n';
got = encoder.receive(output).value();
std::cout << "receive: wrote " << got.count << ", " << name_of(got.flow) << '\n';
sent = encoder.send(second);
std::cout << "send after flush: accepted " << sent.value().count << ", "
<< name_of(sent.value().flow) << '\n';
// reset starts again.
encoder.reset();
sent = encoder.send(second);
std::cout << "send after reset: accepted " << sent.value().count << ", "
<< name_of(sent.value().flow) << '\n';
// A decoder's fault comes after flush; every call after it returns the same error.
auto decoder = codecs::decoder(formats::hex);
std::string_view const text = "0g12";
std::array<std::uint8_t, 4> bytes{};
auto const decoder_sent = decoder.send(std::span{text.data(), text.size()});
std::cout << "decoder send: " << name_of(decoder_sent.value().flow) << '\n';
auto const first_receive = decoder.receive(std::span{bytes}.first(1));
std::cout << "receive before flush: wrote " << first_receive.value().count << " byte, "
<< name_of(first_receive.value().flow) << '\n';
std::cout << "flush: " << name_of(decoder.flush().value()) << '\n';
auto const refused = decoder.receive(bytes);
std::cout << "receive after flush: " << refused.error().message() << '\n';
auto const again = decoder.receive(bytes);
std::cout << "receive again: " << again.error().message() << '\n';
}
send 64: accepted 64, output_pending send 4 more: accepted 0, output_pending receives of 50 characters until needs_input: 3 send 4 again: accepted 4, output_pending flush: output_pending receive: wrote 8, finished send after flush: accepted 0, finished send after reset: accepted 4, output_pending decoder send: output_pending receive before flush: wrote 1 byte, output_pending flush: output_pending receive after flush: a character is outside the format's alphabet receive again: a character is outside the format's alphabet
The input is borrowed
What send accepts stays the caller’s, alive and unchanged, until the
transformer next reports needs_input or finished, or is reset or
destroyed. The transformer reads it during receive, from the caller’s input
straight into the caller’s output, and does not copy it: a program that sends a
buffer, receives, and reuses the buffer before the stream says needs_input
reads garbage. The loop of a stream is send, receive until needs_input, send
again, and the end is flush, receive until finished.
Where the error is
A fault of the data is reported once, after flush, by the first call that has
processed the whole input: flush itself when nothing is still borrowed,
otherwise the receive that reaches the end. It is the error the one-shot form
gives for the same input, and the call that reports it writes nothing, the
verdict having run over everything still borrowed before the tail is written.
The bytes delivered before the error are not a result. A decoder delivers the
bytes of valid groups as it reads them, and the verdict comes after flush, so
that the time does not depend on where the text is invalid (the constant-time
formats report their fault only then). A caller that gets an error discards
everything the stream wrote: the last lines of the program above show a byte
delivered from 0g12, and the error that comes after flush. A decoder that must not
deliver a byte before the text is whole is bech32’s, which holds its characters
(bech32 and bech32m).
A fault of the format’s configuration is not a fault of the data: it is checked
when the transformer is made, and reported by the first call of the stream,
whatever it is, and by every call after, also after reset, before any data
and winning over every data error. A transformer of formats::bech32 configured
with a human-readable part of 84 characters, and the encoder of a bech32 or an
armor with none, fail at their first send.
A file through a stream
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/base64.hpp>
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <span>
#include <sstream>
#include <string>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// Sends `input` in chunks of `chunk_size`, draining after each send and after flush, and gives
// everything the transformer wrote, or its first error. What was delivered before an error is not
// returned: a caller discards it, and `delivered` says how much of it the sink had received.
template <codecs::stream_transformer Transformer>
codecs::result<std::vector<typename Transformer::output_type>> convert(
Transformer& transformer, std::span<typename Transformer::input_type const> input,
std::size_t chunk_size, std::size_t& delivered) {
std::vector<typename Transformer::output_type> output;
delivered = 0;
auto const sink = [&output,
&delivered](std::span<typename Transformer::output_type const> piece) {
output.insert(output.end(), piece.begin(), piece.end());
delivered = output.size();
};
for (std::size_t offset = 0; offset < input.size(); offset += chunk_size) {
auto const sent =
transformer.send(input.subspan(offset, std::min(chunk_size, input.size() - offset)));
if (!sent) {
return sent.error();
}
// The input is borrowed until the transformer reports needs_input again: drain first.
auto const drained = codecs::drain(transformer, sink);
if (!drained) {
return drained.error();
}
}
auto const flushed = transformer.flush();
if (!flushed) {
return flushed.error();
}
auto const drained = codecs::drain(transformer, sink);
if (!drained) {
return drained.error();
}
return output;
}
// Reads a std::istream in chunks, as a program reads a file.
std::vector<std::uint8_t> read_all(std::istream& file, std::size_t chunk_size,
std::size_t& chunks) {
std::vector<std::uint8_t> content;
std::vector<char> chunk(chunk_size);
while (file.read(chunk.data(), static_cast<std::streamsize>(chunk.size())) ||
file.gcount() > 0) {
content.insert(content.end(), chunk.begin(), chunk.begin() + file.gcount());
++chunks;
}
return content;
}
} // namespace
int main() {
// A file of 3000 bytes.
std::string file_content(3000, '\0');
for (std::size_t index = 0; index < file_content.size(); ++index) {
file_content[index] = static_cast<char>(index % 251);
}
std::istringstream file{file_content};
std::size_t chunks = 0;
std::vector<std::uint8_t> const content = read_all(file, 700, chunks);
std::cout << "read " << content.size() << " bytes in " << chunks << " chunks of at most 700\n";
std::size_t delivered = 0;
// base64 streams natively: the encoder holds at most two bytes between sends.
auto encoder = codecs::encoder(formats::base64);
auto const text = convert(encoder, std::span<std::uint8_t const>{content}, 700, delivered);
if (!text) {
return 1;
}
std::cout << "encoded: " << text->size() << " characters\n";
// Chunks of 997 characters end inside a group of four: the decoder holds the rest.
auto decoder = codecs::decoder(formats::base64);
auto const back =
convert(decoder, std::span<char const>{text->data(), text->size()}, 997, delivered);
if (!back) {
return 1;
}
std::cout << "decoded: " << back->size() << " bytes in " << (text->size() + 996) / 997
<< " chunks, equal to the input: " << (*back == content ? "yes" : "no") << '\n';
// A fault is reported after flush; the bytes the decoder delivered before are not kept.
decoder.reset();
std::vector<char> corrupted(text->begin(), text->end());
corrupted[1500] = '*';
auto const refused = convert(decoder, std::span<char const>{corrupted}, 997, delivered);
std::cout << "one character changed: "
<< (refused.error() == codecs::error::invalid_character ? "invalid_character" : "?")
<< " after flush, " << delivered << " bytes had reached the sink, none kept\n";
// A text cut inside a group has no encoding: the error is the one-shot form's.
decoder.reset();
corrupted.assign(text->begin(), text->end() - 1);
auto const cut = convert(decoder, std::span<char const>{corrupted}, 997, delivered);
std::cout << "a text cut inside a group: "
<< (cut.error() == codecs::error::invalid_length ? "invalid_length" : "?")
<< " after flush\n";
}
read 3000 bytes in 5 chunks of at most 700 encoded: 4000 characters decoded: 3000 bytes in 5 chunks, equal to the input: yes one character changed: invalid_character after flush, 2998 bytes had reached the sink, none kept a text cut inside a group: invalid_length after flush
drain(transformer, sink) is the loop of the receives: it calls
transformer.receive into a buffer in place until the stream says it
needs input or is finished, and calls sink(std::span<output_type const>) with
each non-empty piece. The sink returns void, or a result<void> whose error
stops the drain. It returns the state the drain stopped at or the first error,
the transformer’s or the sink’s, and output_too_small when output is pending
and the buffer takes none of it. The buffer is codecs::default_capacity_v of
the output’s elements, 512 bytes; drain(transformer, sink, codecs::capacity<N>)
sets another size, and drain(transformer, sink, span) uses the caller’s span,
which the caller wipes. Of a secret transformer, a drain wipes its own buffer
before it returns, by every path.
Which formats stream natively
| Format | Its stream |
|---|---|
|
an encoder that holds the low digit of a byte, a decoder that holds one digit of a pair |
|
an encoder that holds the bytes of a group not yet whole, a decoder that holds the bits of a group; a padded decoder holds the bytes of the group’s last places until the next character or |
|
an encoder that holds up to two characters of an escape, a decoder that holds the escape it has read |
|
an encoder that writes the BEGIN line with the first input and the END line at |
|
an encoder that writes the part and the data as it goes and the checksum at |
base58 has no stream of its own: codecs::buffered(codecs::encoder(format), capacity)
accumulates the input and converts at flush. A drain of encoder(formats::base58)
does not compile, and says so. The hold of a bech32 decoder is
codecs::decoder(format, codecs::capacity<N>), at most the format’s maximum
length, which a larger N makes a compile-time error before the decoder type is
named; a format whose decoder holds nothing stops the build when a hold is named.
pipe
codecs::pipe(first, second) is a stream transformer that sends its input
through first and then through second, with an intermediate in place of
codecs::default_capacity_v elements of the output of first, 512 bytes, or the
N of a codecs::capacity<N> third argument. pipe(a, b, c) is
pipe(pipe(a, b), c). It compiles only when both are stream transformers and
the first’s output_type is the second’s input_type, or both are one-byte
types (char, std::uint8_t, std::byte); pipe(encoder(hex), packets_to_frames)
stops the build with a message that names both element types. A one-shot
transformer is made a stream first, by each or buffered.
The pipe allocates nothing. It is constant time when both parts are, and each
call is noexcept when the parts’ calls are. It is secret when either part is:
each call, reset included, holds an engaged timing guard, and the intermediate
is wiped. The first error of either part is the pipe’s, and a receive that has
written output when it meets the error returns the output, and the next call the
error, so that the call that reports an error writes nothing.
A pipe is not copyable, and it must not be moved in one window. second may
borrow the intermediate, so that a pipe must not be moved between a receive
that reports output_pending and the next call that reports needs_input or
finished, unless it has reported an error (it calls second no more until
reset). A move takes the parts and the intermediate’s elements second has
not taken, and leaves the moved-from pipe as reset does. The stream of an
over chain, encoder(over{...}) and decoder(over{...}), is such a pipe of
its links’ streams, and keeps the same window: a transformer of a chain is not
moved between a receive that reports output_pending and the next call that
reports needs_input or finished, unless it has reported an error.
each and buffered
codecs::each(transformer) makes a stream of a one-shot transformer that
converts each input element on its own, as a whole unit: a decoded video frame
to an image, the stream of frames a stream of images, with nothing accumulated.
send accepts one element, receive transforms it straight into the caller’s
span when the transformer states a static max_output_size(1) and the span has
the room, and otherwise into its own storage, which it delivers over as many
receives as the spans need. completed_items() counts the items fully
delivered, so that a caller whose output is bytes sees each item’s boundary. An
item’s error is reported with that item, by the receive that transforms it.
codecs::buffered(transformer) accumulates the whole input and converts it at
flush: a conversion that cannot stream has the whole input as its minimal
state. send copies what it accepts, receive before flush gives nothing,
and a fault, the transformer’s or the input’s length, is reported by flush.
A fault of the configuration of a format’s transformer they hold,
buffered(encoder(formats::armor(label))) with a label outside RFC 7468’s
grammar, is not a fault of the data: both report it from their first call, as
the transformer itself does, and keep it after reset.
Both take their storage in place or from an allocator:
each(transformer, codecs::capacity<N>) and buffered(transformer, codecs::capacity<N>)
hold N elements in place, which needs the transformer’s max_output_size as a
constant expression and allocates nothing (an input past the N of buffered is
reported at flush as input_too_long); each(transformer, allocator) and
buffered(transformer, allocator) take the storage from the allocator, grown to
the exact output_size when the transformer states one, else to its static
bound, else by doubling while transform says output_too_small
(Allocators). Without either argument the allocator is
std::allocator. A secret transformer makes a secret adapter, which wipes its
storage.
Pitfalls
-
Drain before you send again. A
sendwhile output is pending accepts nothing, which a loop that ignores the count sends again forever. -
The error of a decoder is not at the character that caused it, and the bytes before it are not a result.
-
A stream of a configured format carries the configuration:
encoder(formats::armor("X"))writes the label of the value it was made from, andresetkeeps it.
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
| Form | Allocates |
|---|---|
the buffer forms of |
nothing (and |
|
nothing |
the conversion of every format, in every form: hex, base32, z-base-32, 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 |
|
nothing |
|
its allocator, for the intermediate |
the stream transformers of the native formats, |
nothing, once constructed |
the default result of a run-time size, |
the allocator of the result or the container |
|
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.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <memory_resource>
#include <new>
#include <numeric>
#include <span>
#include <string>
#include <type_traits>
#include <vector>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace tokens = webcpp::codecs::tokens;
int main() {
// 1 KiB on the stack, and no other memory behind it: past it, the resource throws.
std::array<std::byte, 1024> storage{};
std::pmr::monotonic_buffer_resource arena{storage.data(), storage.size(),
std::pmr::null_memory_resource()};
std::pmr::polymorphic_allocator<char> const allocator{&arena};
std::vector<std::uint8_t> input(100);
std::iota(input.begin(), input.end(), std::uint8_t{0});
// return_string with an allocator gives a std::string over it; the heap is not touched.
auto const text = codecs::encode(formats::hex, input, tokens::return_string(allocator));
static_assert(std::is_same_v<std::remove_cvref_t<decltype(*text)>, std::pmr::string>);
if (!text) {
return 1;
}
std::cout << "pmr::string: " << text->size() << " characters, from the arena: "
<< (text->get_allocator().resource() == &arena ? "yes" : "no") << '\n';
// A secret operation gives the secret heap type over the allocator: moved, never copied, and
// wiped before its memory goes back.
auto const secret = codecs::encode(formats::hex, input, tokens::secret(allocator));
static_assert(
std::is_same_v<std::remove_cvref_t<decltype(*secret)>, codecs::pmr::secret_string>);
if (!secret) {
return 1;
}
std::cout << "codecs::pmr::secret_string: " << secret->size() << " characters\n";
// A container with its own allocator is a token too: append_to uses that container's.
std::pmr::string line{"id=", allocator};
if (!codecs::encode(formats::hex, std::span{input}.first(4), tokens::append_to(line))) {
return 1;
}
std::cout << "append_to a pmr::string: " << line << '\n';
// The arena holds 1 KiB, and 400 of it is gone: 500 bytes need 1000 characters. The allocator
// throws std::bad_alloc, the call is not noexcept, and the exception reaches the caller as it
// is. The token's container is as it was.
std::vector<std::uint8_t> const big(500);
std::pmr::string kept{"kept", allocator};
try {
auto const result = codecs::encode(formats::hex, big, tokens::append_to(kept));
std::cout << "no throw: " << result.has_value() << '\n';
} catch (std::bad_alloc const&) {
std::cout << "std::bad_alloc reached the caller; the string still holds " << kept << '\n';
}
}
pmr::string: 200 characters, from the arena: yes codecs::pmr::secret_string: 200 characters append_to a pmr::string: id=00010203 std::bad_alloc reached the caller; the string still holds kept
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 (Exceptions). What the program finds after it:
-
a token’s container still holds what it held:
append_tois put back as it was,assign_togives the container nothing before the conversion succeeds, and in the example the string still holdskept; -
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;
-
eachandbufferedwith an allocator: asendthat throws accepts nothing, and the stream converts the same input after the exception; areceivethat throws leaves its item pending; aflushthat 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
overis for its intermediate alone. The allocator of a token is for its result alone. Neither is the other’s. -
The allocator of
overis not used for a decode whose value codec states amax_decode_input_sizeof at most 4096 bytes: its intermediate is in place, whatever the text’s type, and an input past the bound isinput_too_longbefore anything is made. A bound above 4096 bytes takes the intermediate, of the exact size written, from the allocator. -
A
std::pmr::monotonic_buffer_resourcenever 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.
Writing a format
A library that owns a format registers it in a header of its own, with no change
to codecs, and every operation, token and over then work with it as with
codecs’ own formats. A format is four things a library may give, each
independent: a codec for bytes and text, a value_codec for a typed value, the
secrecy of a type (is_secret, fixed_byte_storage), and a stream_codec for
the stream. The program below is one of each, for a format that writes each byte
as two letters, nibbles; the sections after it teach each piece, and the
program is built and run in every lane.
#include <webcpp/codecs.hpp>
#include <webcpp/secure/erase_secret.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
namespace codecs = webcpp::codecs;
namespace secure = webcpp::secure;
// ... format: shown in its own section of the page
namespace webcpp::codecs {
// ... codec: shown in its own section of the page
// ... stream_codec: shown in its own section of the page
// ... value_codec: shown in its own section of the page
} // namespace webcpp::codecs
// ... secret_type: shown in its own section of the page
static_assert(codecs::format<nibbles_t>);
static_assert(codecs::stream_transformer<decltype(codecs::encoder(nibbles))>);
static_assert(codecs::stream_transformer<decltype(codecs::decoder(nibbles))>);
int main() {
// The core's operations work with the format as with a format of the library's.
std::array<std::uint8_t, 3> const bytes{0x01, 0x02, 0xff};
auto const text = codecs::encode(nibbles, bytes);
if (!text) {
return 1;
}
std::cout << "encode: " << text->view() << '\n';
auto const back = codecs::decode<std::array<std::uint8_t, 3>>(nibbles, text->view());
if (!back) {
return 1;
}
std::cout << "decode: " << back->size() << " bytes, the last is "
<< static_cast<unsigned>(back->back()) << '\n';
// The value codec: a temperature as two bytes, in place; and over chains it with the format.
auto const raw = codecs::encode(big_endian, temperature{215});
if (!raw) {
return 1;
}
auto const value = codecs::decode<temperature>(big_endian, *raw);
if (!value) {
return 1;
}
std::cout << "a temperature: " << raw->size() << " bytes -> " << value->tenths << " tenths\n";
auto const chained = codecs::encode(codecs::over{nibbles, big_endian}, temperature{215});
if (!chained) {
return 1;
}
std::cout << "over: " << chained->view() << '\n';
// A secret type of the program's own: the result is a secret text, wiped when it is destroyed.
session_key key;
for (std::size_t index = 0; index < session_key::size(); ++index) {
key.writable()[index] = static_cast<std::uint8_t>(index + 1);
}
auto const secret_text = codecs::encode(nibbles, key);
if (!secret_text) {
return 1;
}
static_assert(
std::is_same_v<std::remove_cvref_t<decltype(*secret_text)>, codecs::secret_text<32>>);
std::cout << "session key: " << secret_text->view() << '\n';
auto const key_back = codecs::decode<session_key>(nibbles, secret_text->view());
std::cout << "typed decode of a secret type: " << (key_back ? "ok" : "failed") << '\n';
// The stream: one character a receive, so that the low letter of a byte waits.
auto encoder = codecs::encoder(nibbles);
std::string streamed;
if (!encoder.send(bytes)) {
return 1;
}
std::array<char, 1> one{};
for (;;) {
auto const got = encoder.receive(one);
if (!got) {
return 1;
}
streamed.append(one.data(), got->count);
if (got->flow != codecs::flow::output_pending) {
break;
}
}
std::cout << "stream, one character a receive: " << streamed << '\n';
// A fault of the data is reported after flush, by the receive that reaches the end: nothing is
// written by it, and what came before is for the caller to discard.
auto decoder = codecs::decoder(nibbles);
std::string_view const bad = "abxb";
if (!decoder.send(std::span{bad.data(), bad.size()})) {
return 1;
}
auto const flushed = decoder.flush();
std::array<std::uint8_t, 8> out{};
auto const refused = decoder.receive(out);
std::cout << "flush: " << (flushed ? "no error yet" : "error")
<< ", receive: " << refused.error().message() << '\n';
}
encode: abacpp decode: 3 bytes, the last is 255 a temperature: 2 bytes -> 215 tenths over: aanh session key: abacadaeafagahaiajakalamanaoapba typed decode of a secret type: ok stream, one character a receive: abacpp flush: no error yet, receive: a character is outside the format's alphabet
The format
A format is a copyable type with a static constexpr name that converts to a
std::string_view: the concept codecs::format. It is passed by value as the first
argument of every operation, and its options, if it has any, are its members and
a call that gives another value, as formats::hex(letter_case::upper) does.
namespace {
// A format is a copyable type with a constant name. Its options, if any, are its members.
struct nibbles_t {
static constexpr std::string_view name = "nibbles";
};
inline constexpr nibbles_t nibbles{};
// A format whose only job is to convert a typed value to bytes: it has no codec, so it has no
// transformer, and a value codec below gives it its values.
struct big_endian_t {
static constexpr std::string_view name = "big_endian";
};
inline constexpr big_endian_t big_endian{};
// The values it converts.
struct temperature {
std::uint16_t tenths;
};
} // namespace
A format that exists for a value codec alone, as big_endian_t does, has no
codec and so no transformer: typed values are converted whole.
codec
codecs::codec<Format> is declared and never defined by the core, and the
format’s header specializes it. It has one constant and six functions, each
noexcept, and every public operation of codecs is written over them alone.
// The codec: one constant, two bounds, and four functions, each noexcept, over the span types the
// contract names. It declares its constant_time truthfully: nibbles branches on its data.
template <>
struct codec<nibbles_t> {
// Whether encode and decode run in a time that does not depend on the data. Secret operations,
// encoder() and decoder() read it; this program runs none of them, so the compiler's warning of
// an unused constant is silenced.
[[maybe_unused]] static constexpr bool constant_time = false;
// A bound that holds for every option of the format; SIZE_MAX says "does not fit".
static constexpr std::size_t max_encoded_size(std::size_t input_size) noexcept {
// The parentheses around max keep <windows.h>'s macro max from expanding it.
// NOLINTNEXTLINE(readability-redundant-parentheses): they stop <windows.h>'s macro max
constexpr std::size_t largest = (std::numeric_limits<std::size_t>::max)();
return input_size > largest / 2 ? largest : input_size * 2;
}
static constexpr std::size_t max_decoded_size(std::size_t text_size) noexcept {
return text_size / 2;
}
// The exact size of the text of the bytes.
static constexpr std::size_t encoded_size(nibbles_t const& /*format*/,
std::span<std::uint8_t const> input) noexcept {
return max_encoded_size(input.size());
}
// The exact size of the bytes of the text, the whole text checked: the lowest error wins.
static result<std::size_t> decoded_size(nibbles_t const& /*format*/,
std::string_view text) noexcept {
for (char const character : text) {
// Read as an unsigned byte first: char may be signed.
auto const value = static_cast<std::uint8_t>(character);
if (value < 'a' || value > 'p') {
return error::invalid_character;
}
}
if (text.size() % 2 != 0) {
return error::invalid_length;
}
return text.size() / 2;
}
// Writes the text, or nothing and output_too_small.
static result<std::size_t> encode(nibbles_t const& format, std::span<std::uint8_t const> input,
std::span<char> output) noexcept {
std::size_t const size = encoded_size(format, input);
if (output.size() < size) {
return error::output_too_small;
}
for (std::size_t index = 0; index < input.size(); ++index) {
output[2 * index] = static_cast<char>('a' + (input[index] >> 4U));
output[(2 * index) + 1] = static_cast<char>('a' + (input[index] & 15U));
}
return size;
}
// Writes the bytes after the whole text is found valid, or nothing.
static result<std::size_t> decode(nibbles_t const& format, std::string_view text,
std::span<std::uint8_t> output) noexcept {
result<std::size_t> const size = decoded_size(format, text);
if (!size) {
return size;
}
// Read unchecked: the error was returned above.
std::size_t const byte_count = size.unsafe_value();
if (output.size() < byte_count) {
return error::output_too_small;
}
for (std::size_t index = 0; index < byte_count; ++index) {
auto const high = static_cast<unsigned>(text[2 * index] - 'a');
auto const low = static_cast<unsigned>(text[(2 * index) + 1] - 'a');
output[index] = static_cast<std::uint8_t>((high << 4U) | low);
}
return byte_count;
}
};
-
constant_timeis stated honestly. A format that is not constant time says false, and the library’sis_constant_time_vand the secret transformers read it. -
max_encoded_sizeandmax_decoded_sizeare constexpr bounds that hold for every option of the format, and saturate atSIZE_MAXwhen the answer does not fit instd::size_t: an input whose bound saturates is refused withinput_too_longbefore it is read.encoded_sizeanddecoded_sizeare exact;decoded_sizechecks the whole text and reports the error with the lowest value. -
encodeanddecodewrite at the start of the output, or write nothing and returnoutput_too_small;decodechecks the whole text before it writes. -
Every function takes the span types of the contract and not a deduced parameter:
std::span<std::uint8_t const>for the bytes read,std::string_viewfor the text read,std::span<char>andstd::span<std::uint8_t>for the output. The core gives the bytes of an input whose type states its size as a view that converts to those types implicitly andnoexcept, so that the codec’snoexceptreaches the operation; a function template that deduced its parameter would get the view and could not read it. -
A function of another signature, another parameter, another result, not
noexceptor notstatic, stops the build.
A configuration. A format that has one, a human-readable part, a label or an
option that can be wrong, adds
static constexpr std::optional<error> configuration_fault(Format const&) noexcept
to its codec. The core calls it first in every form, before any size check and
any data, and returns its error unchanged, so that a fault of the
configuration wins over every data error; a stream transformer asks it when it is
made and reports the error from its first call, whatever it is, and from every
call after, giving the stream codec nothing. The other functions of the codec are
called only for a configuration with no fault and check nothing of it.
An encode that refuses. A format whose encode refuses an input that its decode
has nothing to say of, as bech32 with no human-readable part, a text past its
longest or a word above 31, and the armor with no label, adds
static constexpr std::optional<error> encode_fault(Format const&, std::span<std::uint8_t const>) noexcept
to its codec. The core calls it in every encode form after configuration_fault
and before its own size check, so that the fault wins over the size’s whatever
the input’s size, and before any token is prepared or any result made. It may
read the input: one that does checks the input’s size first, and reads secret
bytes in constant time, the verdict declassified once. A function of another
signature stops the build.
The sizes of a refused input. A size without an error channel, the codec’s
encoded_size, codecs::encoded_size and a transformer’s output_size, keeps
one rule for an input the encode refuses: SIZE_MAX when it is refused for its
size, 0 when it is refused for a fault of the configuration or of the encode.
A secret arithmetic that differs. A format whose secret operation must do the
work another way, as base58’s constant-time conversion does, also has overloads
of encoded_size, decoded_size, encode or decode whose first parameter is
a detail::secret_tag. This is the one name of detail a format’s header
names: the core calls the overload in a secret operation when it exists and the
function without the tag otherwise, and an overload with another result type
than the function without it stops the build. A value codec’s functions take
it alike. A format whose arithmetic is already constant time has none of them.
value_codec
codecs::value_codec<Format, Value> is declared and never defined, and the
library that owns the type or the format specializes it, in encoding only,
decoding only, or both. It states what the encoding is made of,
output_kind::bytes or output_kind::text, optionally secret, which
makes every operation on a value secret, and a static max_encoded_size, which
makes the default result a bytes<M> or text<M> in place. Its encode writes a
std::span<std::uint8_t> (a std::span<char> for a text), and its decode
returns result<Value> from std::span<std::uint8_t const> (or a
std::string_view). Its errors reach the caller unchanged, whatever their
category.
// The value codec: a library that owns a type converts it to the bytes or the text of a format.
// Its output is bytes, its encoding is two bytes at most (so that the default result is a
// bytes<2>, in place), and it converts both ways.
template <>
struct value_codec<big_endian_t, temperature> {
static constexpr output_kind output = output_kind::bytes;
static constexpr std::size_t max_encoded_size = 2;
static constexpr std::size_t encoded_size(big_endian_t const& /*format*/,
temperature const& /*value*/) noexcept {
return 2;
}
static result<std::size_t> encode(big_endian_t const& /*format*/, temperature const& value,
std::span<std::uint8_t> destination) noexcept {
if (destination.size() < 2) {
return error::output_too_small;
}
destination[0] = static_cast<std::uint8_t>(value.tenths >> 8U);
destination[1] = static_cast<std::uint8_t>(value.tenths & 0xffU);
return std::size_t{2};
}
static result<temperature> decode(big_endian_t const& /*format*/,
std::span<std::uint8_t const> input) noexcept {
if (input.size() != 2) {
return error::invalid_length;
}
return temperature{static_cast<std::uint16_t>((unsigned{input[0]} << 8U) | input[1])};
}
};
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
Composition: over 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:
// The declaration is the point's whole list of formats, and the place of the library's reasons.
template <>
struct value_formats<example::point> {
// Required: the formats the point has, which a refusal prints. der has a value codec and is
// not listed, so that no verb converts a point in der.
using formats = format_list<example::raw_t, example::spki_t>;
// Optional, together: whether a pair has a reason of its own, and the library's sentence, a
// static_assert that is false for those pairs alone. A point's armor is its own, not the
// armor over its spki: any verb that meets the pair stops the build with this sentence.
template <class Format, direction Direction>
static constexpr bool has_reason = example::is_armored_spki<Format>;
template <class Format, direction Direction>
static constexpr void refuse() noexcept {
static_assert(!has_reason<Format, Direction>, "point: a point's armor is its own");
}
};
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.
namespace {
using example::der_t;
using example::point;
using example::raw;
using example::raw_t;
using example::spki;
using example::spki_t;
// The bytes of an encoding, as hex.
template <class Bytes>
void print_hex(std::string_view label, Bytes const& encoded) {
auto const text = codecs::encode(formats::hex, encoded).value();
std::cout << label << ": " << text.view() << '\n';
}
} // namespace
int main() {
point const value{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}};
// The two formats the point has, encoded and decoded.
auto const raw_bytes = codecs::encode(raw, value);
auto const spki_bytes = codecs::encode(spki, value);
if (!raw_bytes || !spki_bytes) {
return 1;
}
print_hex("raw", *raw_bytes);
print_hex("spki", *spki_bytes);
auto const from_raw = codecs::decode<point>(raw, *raw_bytes);
auto const from_spki = codecs::decode<point>(spki, *spki_bytes);
if (!from_raw || !from_spki) {
return 1;
}
std::cout << "decoded: "
<< (from_raw->bytes == value.bytes && from_spki->bytes == value.bytes ? "equal"
: "different")
<< '\n';
// codecs::encodable and decodable say, for a pair, whether the verb builds: true exactly
// where it does. The others are refused at build time with one error, which the program
// cannot show: the sentence of the library's reason, or the list of the point's formats.
auto const say = [](std::string_view pair, bool converts) {
std::cout << pair << ": " << (converts ? "encodable" : "refused") << '\n';
};
say("point in raw", codecs::encodable<point, raw_t>);
say("point in der", codecs::encodable<point, der_t>);
say("point in armor over spki",
codecs::encodable<point, codecs::over<formats::armor_t, spki_t>>);
// A composition is the point's when its inner link is: the armor over raw is.
say("point in armor over raw", codecs::encodable<point, codecs::over<formats::armor_t, raw_t>>);
}
raw: 0102030405060708 spki: 300c03000102030405060708 decoded: equal point in raw: encodable point in der: refused point in armor over spki: refused point in armor over raw: encodable
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
specializes it for its own secret types, and every operation on a value of the
type is then secret (Secrecy: secret operations): the result is a secret type, the timing
guard is held, and the core wipes its temporaries. A type that is a byte input
of a known size, as secure::secret<N> is, has a static constexpr size() and
converts to std::span<std::uint8_t const, size()>.
codecs::fixed_byte_storage<T> lets a library’s fixed type be the target of a
typed decode: it has static constexpr std::size_t size and
static std::span<std::uint8_t, size> writable(T&) noexcept, and
decode<T> fills exactly size bytes. The core specializes both for
secure::secret<N>. The type that wipes itself, and a move that leaves the
source zero, are the type’s job.
namespace {
// A secret type of the program's own: it wipes itself, it states its size and it converts to the
// span of its bytes, so that it is a byte input of a known size.
class session_key {
public:
session_key() = default;
session_key(session_key const&) = delete;
session_key& operator=(session_key const&) = delete;
session_key(session_key&& other) noexcept : bytes_(other.bytes_) {
secure::erase_secret(other.bytes_);
}
session_key& operator=(session_key&& other) noexcept {
if (this != &other) {
bytes_ = other.bytes_;
secure::erase_secret(other.bytes_);
}
return *this;
}
~session_key() { secure::erase_secret(bytes_); }
static constexpr std::size_t size() noexcept { return 16; }
// The conversion must be implicit: that is what makes the type a byte input of a known size.
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions,misc-explicit-constructor)
operator std::span<std::uint8_t const, 16>() const noexcept { return bytes_; }
std::span<std::uint8_t, 16> writable() noexcept { return bytes_; }
private:
std::array<std::uint8_t, 16> bytes_{};
};
} // namespace
namespace webcpp::codecs {
// Every operation on a session_key is secret: the result is wiped, the timing guard is held.
template <>
struct is_secret<session_key> : std::true_type {};
// The target of a typed decode: exactly 16 bytes, written through writable().
template <>
struct fixed_byte_storage<session_key> {
static constexpr std::size_t size = 16;
static std::span<std::uint8_t, 16> writable(session_key& key) noexcept {
return key.writable();
}
};
} // namespace webcpp::codecs
stream_codec
codecs::stream_codec<Format> is declared and never defined, and the format’s
header specializes it when the format streams natively. It has two class
templates over the stream’s options, encoder<stream_options Options> of
std::uint8_t to char and decoder<stream_options Options> of char to
std::uint8_t, each a stream_transformer constructed from the format’s value,
every call noexcept. They keep the minimal state the format needs and nothing
else, and the protocol of Streams and transformers:
-
sendborrows what it accepts and accepts nothing outsideneeds_input;receivewrites into the caller’s span; -
a fault of the data is reported after
flush, by the first call that has processed the whole input, and is the error the one-shot form gives for the same input; that call writes nothing, the verdict having run over everything still borrowed, and every call after it returns the error untilreset; -
a fault of the configuration is not the stream codec’s to find: the core asks
configuration_faultand never builds the stream with it; -
a moved-from encoder or decoder is in the state
resetleaves; -
with
Options.secret, the stream wipes its own pending state bysecure::erase_secretonreset, on destruction and in the moved-from object, and need not be copyable. The core’s class holds the engaged guard around each call and runs the format’s secret arithmetic in the one-shot form.
A decoder that holds its input until its verdict, as bech32’s does, declares
static constexpr bool holds = true and holds Options.capacity elements, or
its default when that is 0; decoder(format, codecs::capacity<N>) of a format
that does not hold stops the build. The stream codec may state
static constexpr std::size_t maximum_hold, the longest hold: a larger N
stops the build before the decoder type is named. A decoder that gives a part of
its input after a successful flush has human_readable_part() or label(),
which the core’s decoder forwards.
// The stream codec: an encoder and a decoder, each a class template over the stream's options.
// Each keeps the protocol (it borrows what send accepts, writes into the caller's span, ends at
// flush, and is in reset's state when moved from), holds only the state it needs, and wipes it
// by secure::erase_secret when Options.secret says the stream is secret.
template <>
struct stream_codec<nibbles_t> {
template <stream_options Options>
class encoder {
public:
using input_type = std::uint8_t;
using output_type = char;
explicit encoder(nibbles_t const& /*format*/) noexcept {}
encoder(encoder const&) = delete;
encoder& operator=(encoder const&) = delete;
encoder(encoder&& other) noexcept : state_(other.state_) { other.reset(); }
encoder& operator=(encoder&& other) noexcept {
if (this != &other) {
state_ = other.state_;
other.reset();
}
return *this;
}
~encoder() { wipe(); }
// Borrows all of the input in needs_input, and accepts nothing in another state.
result<step> send(std::span<std::uint8_t const> input) noexcept {
if (flow_state() != flow::needs_input) {
return step{.count = 0, .flow = flow_state()};
}
state_.borrowed = input;
state_.position = 0;
return step{.count = input.size(), .flow = flow_state()};
}
// Writes two letters a borrowed byte; the low letter of a byte whose high letter filled
// the span waits for the next receive.
result<step> receive(std::span<char> output) noexcept {
std::size_t written = 0;
if (state_.has_pending && written < output.size()) {
output[written++] = state_.pending;
state_.has_pending = false;
}
while (state_.position < state_.borrowed.size() && written < output.size()) {
std::uint8_t const byte = state_.borrowed[state_.position++];
output[written++] = static_cast<char>('a' + (byte >> 4U));
auto const low = static_cast<char>('a' + (byte & 15U));
if (written < output.size()) {
output[written++] = low;
} else {
state_.pending = low;
state_.has_pending = true;
}
}
if (state_.position == state_.borrowed.size()) {
state_.borrowed = {};
state_.position = 0;
}
return step{.count = written, .flow = flow_state()};
}
// Ends the input; this format has no fault of the data to find in bytes.
result<flow> flush() noexcept {
state_.flushed = true;
return flow_state();
}
void reset() noexcept {
wipe();
state_ = {};
}
private:
// What the encoder holds: trivially copyable, so that one erase_secret wipes it all.
struct state {
std::span<std::uint8_t const> borrowed;
std::size_t position = 0;
char pending = 0;
bool has_pending = false;
bool flushed = false;
};
void wipe() noexcept {
if constexpr (Options.secret) {
secure::erase_secret(std::span<state, 1>{&state_, 1});
}
}
[[nodiscard]] flow flow_state() const noexcept {
if (state_.has_pending || state_.position < state_.borrowed.size()) {
return flow::output_pending;
}
return state_.flushed ? flow::finished : flow::needs_input;
}
state state_;
};
template <stream_options Options>
class decoder {
public:
using input_type = char;
using output_type = std::uint8_t;
explicit decoder(nibbles_t const& /*format*/) noexcept {}
decoder(decoder const&) = delete;
decoder& operator=(decoder const&) = delete;
decoder(decoder&& other) noexcept : state_(other.state_) { other.reset(); }
decoder& operator=(decoder&& other) noexcept {
if (this != &other) {
state_ = other.state_;
other.reset();
}
return *this;
}
~decoder() { wipe(); }
// After an error every call returns it, until reset.
result<step> send(std::span<char const> input) noexcept {
if (state_.fault) {
return *state_.fault;
}
if (flow_state() != flow::needs_input) {
return step{.count = 0, .flow = flow_state()};
}
state_.borrowed = input;
state_.position = 0;
return step{.count = input.size(), .flow = flow_state()};
}
// Writes a byte a pair of letters. The first call after flush that reaches the end of the
// input runs the verdict over everything still borrowed and, when it fails, returns the
// error and writes nothing: the one-shot form's error.
result<step> receive(std::span<std::uint8_t> output) noexcept {
if (state_.fault) {
return *state_.fault;
}
if (state_.flushed && !state_.verdict_passed) {
if (auto const fault = pass_verdict()) {
return *fault;
}
}
std::size_t written = 0;
while (written < output.size() && state_.position < state_.borrowed.size()) {
std::uint8_t const value = read(state_.borrowed[state_.position++]);
if (!state_.has_held) {
state_.held = value;
state_.has_held = true;
} else {
output[written++] =
static_cast<std::uint8_t>((unsigned{state_.held} << 4U) | value);
state_.has_held = false;
}
}
if (state_.position == state_.borrowed.size()) {
state_.borrowed = {};
state_.position = 0;
}
return step{.count = written, .flow = flow_state()};
}
// With nothing borrowed, flush runs the verdict and reports its error itself.
result<flow> flush() noexcept {
if (state_.fault) {
return *state_.fault;
}
if (!state_.flushed) {
state_.flushed = true;
if (state_.position == state_.borrowed.size()) {
if (auto const fault = pass_verdict()) {
return *fault;
}
}
}
return flow_state();
}
void reset() noexcept {
wipe();
state_ = {};
}
private:
struct state {
std::span<char const> borrowed;
std::size_t position = 0;
std::uint8_t held = 0;
bool has_held = false;
bool invalid = false;
bool flushed = false;
bool verdict_passed = false;
std::optional<error> fault;
};
void wipe() noexcept {
if constexpr (Options.secret) {
secure::erase_secret(std::span<state, 1>{&state_, 1});
}
}
// The value of a letter; a letter outside `a` to `p` is remembered, not reported yet.
std::uint8_t read(char letter) noexcept {
auto const value = static_cast<std::uint8_t>(letter);
if (value < 'a' || value > 'p') {
state_.invalid = true;
return 0;
}
return static_cast<std::uint8_t>(value - 'a');
}
// The whole input's verdict: the lowest error, as decoded_size gives it; none when valid.
std::optional<error> pass_verdict() noexcept {
std::size_t letters = state_.has_held ? 1 : 0;
for (char const letter : state_.borrowed.subspan(state_.position)) {
static_cast<void>(read(letter));
++letters;
}
if (state_.invalid) {
state_.fault = error::invalid_character;
} else if (letters % 2 != 0) {
state_.fault = error::invalid_length;
}
state_.verdict_passed = !state_.fault;
return state_.fault;
}
[[nodiscard]] flow flow_state() const noexcept {
if (state_.position < state_.borrowed.size()) {
return flow::output_pending;
}
return state_.flushed ? flow::finished : flow::needs_input;
}
state state_;
};
};
Checklist
-
The codec, the value codec and the stream codec are specialized in
webcpp::codecs, in the header that defines the format, and a program that does not include that header does not see the name. -
Every function that can fail returns
result; none throws. -
Test the format as codecs tests its own: every byte value as a character, with
charsigned (the alphabet’s neighbours and the bytes from0x80up eachinvalid_character); sizes that overflowstd::size_ton a 32-bit target; the empty input in every form; a stream equal to the one-shot form for every chunking; a moved-from stream used again. -
A format that claims
constant_timeindexes no table by a data byte and branches on none: use the blocks ofsecure::constant_timeand declassify the verdict once.
Writing a transformer of other data
The two transformer concepts (Streams and transformers) are about any data, and
pipe, drain, each and buffered take any transformer that satisfies
them: a decoder of video packets, a resampler of audio, a parser that turns bytes
into records. The program below is a toy of that kind, with elements that are
neither bytes nor characters: a packet becomes a frame through a stream
transformer, a frame becomes bytes through a one-shot transformer, and the
bytes become hex through the library’s own encoder.
#include <webcpp/codecs.hpp>
#include <webcpp/codecs/hex.hpp>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <span>
#include <string>
#include <utility>
namespace codecs = webcpp::codecs;
namespace formats = webcpp::codecs::formats;
namespace {
// The elements: a compressed packet and a decoded frame. Neither is a byte.
struct packet {
std::uint32_t index;
};
struct frame {
std::uint32_t index;
std::array<std::uint16_t, 2> pixels;
};
// ... stream: shown in its own section of the page
// ... one_shot: shown in its own section of the page
} // namespace
static_assert(codecs::stream_transformer<packets_to_frames>);
static_assert(codecs::one_shot_transformer<frame_to_bytes>);
int main() {
std::array<packet, 4> const packets{packet{0}, packet{1}, packet{2}, packet{3}};
// The stream by hand: a frame comes out one packet late, and the last one at flush.
packets_to_frames decoder;
auto const print = [](std::span<frame const> frames) {
for (frame const& item : frames) {
std::cout << "frame " << item.index << ": " << item.pixels[0] << ' ' << item.pixels[1]
<< '\n';
}
};
for (packet const& item : packets) {
if (!decoder.send(std::span{&item, 1})) {
return 1;
}
if (!codecs::drain(decoder, print)) {
return 1;
}
}
if (!decoder.flush() || !codecs::drain(decoder, print)) {
return 1;
}
// The pipeline: each turns the one-shot transformer into a stream (one frame in place, six
// bytes), and the pipe joins three streams by their element types alone.
decoder.reset();
auto pipeline =
codecs::pipe(std::move(decoder), codecs::each(frame_to_bytes{}, codecs::capacity<6>),
codecs::encoder(formats::hex));
std::string hex_text;
auto const collect = [&hex_text](std::span<char const> piece) {
hex_text.append(piece.data(), piece.size());
};
for (packet const& item : packets) {
if (!pipeline.send(std::span{&item, 1}) || !codecs::drain(pipeline, collect)) {
return 1;
}
}
if (!pipeline.flush() || !codecs::drain(pipeline, collect)) {
return 1;
}
std::cout << "hex of the frames: " << hex_text << '\n';
}
frame 0: 0 1 frame 1: 10 11 frame 2: 20 21 frame 3: 30 31 hex of the frames: 0000000000010001000a000b0002001400150003001e001f
A stream transformer
packets_to_frames has input_type, output_type, and the four calls. It
holds each frame back until the next packet, as a decoder that reorders frames
does, so that a frame comes out one packet late and the last one comes out at
flush.
// A stream transformer of packets to frames. Each send accepts one packet, copies what it needs
// and holds its frame back: the frame of the previous packet is released, and the last one at
// flush.
class packets_to_frames {
public:
using input_type = packet;
using output_type = frame;
packets_to_frames() noexcept = default;
packets_to_frames(packets_to_frames const&) = delete;
packets_to_frames& operator=(packets_to_frames const&) = delete;
~packets_to_frames() = default;
// A moved-from transformer is in the state reset leaves, so that it converts a new input.
packets_to_frames(packets_to_frames&& other) noexcept
: state_(std::exchange(other.state_, {})) {}
packets_to_frames& operator=(packets_to_frames&& other) noexcept {
state_ = std::exchange(other.state_, {});
return *this;
}
// Accepts the first packet in needs_input, and nothing in another state.
codecs::result<codecs::step> send(std::span<packet const> input) noexcept {
if (flow_state() != codecs::flow::needs_input || input.empty()) {
return codecs::step{.count = 0, .flow = flow_state()};
}
state_.ready = state_.held;
state_.has_ready = state_.has_held;
std::uint32_t const index = input.front().index;
auto const first_pixel = static_cast<std::uint16_t>(index * 10);
auto const second_pixel = static_cast<std::uint16_t>(first_pixel + 1);
state_.held = frame{.index = index, .pixels = {first_pixel, second_pixel}};
state_.has_held = true;
return codecs::step{.count = 1, .flow = flow_state()};
}
// Writes the frame that is ready, if the span has room.
codecs::result<codecs::step> receive(std::span<frame> output) noexcept {
if (!state_.has_ready || output.empty()) {
return codecs::step{.count = 0, .flow = flow_state()};
}
output.front() = state_.ready;
state_.has_ready = false;
return codecs::step{.count = 1, .flow = flow_state()};
}
// Ends the input, which releases the frame held back.
codecs::result<codecs::flow> flush() noexcept {
state_.flushed = true;
state_.ready = state_.held;
state_.has_ready = state_.has_held;
state_.has_held = false;
return flow_state();
}
// Back to needs_input with nothing held.
void reset() noexcept { state_ = {}; }
private:
struct state {
frame held{};
frame ready{};
bool has_held = false;
bool has_ready = false;
bool flushed = false;
};
[[nodiscard]] codecs::flow flow_state() const noexcept {
if (state_.has_ready) {
return codecs::flow::output_pending;
}
return state_.flushed ? codecs::flow::finished : codecs::flow::needs_input;
}
state state_;
};
What the protocol asks of a transformer, which the concept cannot check:
-
sendaccepts input only inneeds_input, and borrows what it accepts: the caller keeps it alive and unchanged until the transformer reportsneeds_inputorfinished. A transformer may copy what it needs and free the input at once, as this one does. -
receivewrites at most the span’s size, and returns the count and the state. -
flushends the input; after it nothing is accepted untilreset. -
A fault of the data is reported once, after
flush, by the first call that has processed the whole input, and then by every call untilreset. This toy has none; a decoder of corrupt data returns its error fromflushor from thereceivethat reaches the end, writes nothing in that call, and expects the caller to discard what it delivered before. -
resetisnoexceptand returns the transformer toneeds_inputwith nothing borrowed or pending. -
A moved-from transformer is in the state
resetleaves, which the move operations here make explicit; a defaulted move of a transformer that holds state would leave the old state in the source, andpipe,eachandbufferedmove their transformers. -
A secret transformer, one whose elements are secret, specializes
codecs::is_secretand wipes its state bysecure::erase_secret, as the formats’ streams do (Writing a format).
A one-shot transformer
frame_to_bytes converts a whole input at once: it writes all of its output or
nothing, and a short output is output_too_small.
// A one-shot transformer of frames to bytes: six bytes a frame, the index's low 16 bits and the two
// pixels, big endian. It writes all its output or nothing.
struct frame_to_bytes {
using input_type = frame;
using output_type = std::uint8_t;
// A bound on the output, a constant expression, so that each can hold one frame's output in
// place.
static constexpr std::size_t max_output_size(std::size_t frames) noexcept { return frames * 6; }
static codecs::result<std::size_t> transform(std::span<frame const> input,
std::span<std::uint8_t> output) noexcept {
if (output.size() < max_output_size(input.size())) {
return codecs::error::output_too_small;
}
std::size_t written = 0;
for (frame const& item : input) {
for (std::uint32_t const value :
{item.index, std::uint32_t{item.pixels[0]}, std::uint32_t{item.pixels[1]}}) {
output[written++] = static_cast<std::uint8_t>(value >> 8U);
output[written++] = static_cast<std::uint8_t>(value);
}
}
return written;
}
};
A one-shot transformer may state max_output_size(n), a bound on the output of
n input elements, as a constant expression where it can, and output_size(input),
the exact size. each(transformer, codecs::capacity<N>) and
buffered(transformer, codecs::capacity<N>) hold their storage in place and need
the bound as a constant expression (without it the build stops, and only the
allocator form handles that case), where N counts the output elements of one
item for each and the elements held for buffered; a bound of the object’s own, a
non-static max_output_size, is not read, and such a transformer is sized by
doubling. It may state static constexpr bool constant_time, read by
codecs::is_constant_time_v.
Joining them
each(transformer) is a stream of a one-shot transformer that converts every
element of the input on its own; buffered(transformer) accumulates the whole
input and converts at flush. pipe joins streams whose element types agree:
the first’s output_type is the second’s input_type, or both are a byte or a
character type. The program’s pipeline is
pipe(packets_to_frames, each(frame_to_bytes{}, capacity<6>), encoder(formats::hex)),
and joining the wrong pair, pipe(encoder(formats::hex), packets_to_frames), stops
the build with a message that names char and packet and says that the first
transformer’s output is not the second’s input.
Pitfalls
-
A one-shot transformer that is not a stream cannot be piped or drained: pass it through
eachorbuffered, and the message of apipeordrainof a one-shot transformer names both. -
bufferedconverts atflushand reports an error there; a one-shot transformer whose input is huge wants an allocator, or a largercodecs::capacity<N>. -
A pipe must not be moved between a
receivethat reportsoutput_pendingand the nextneeds_inputorfinished, unless it has reported an error: the second part may borrow the intermediate (Streams and transformers).
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.
Macros
| Name | Description |
|---|---|
Defined when codecs is built without exceptions: when webcpp has none (the compiler has none, or the developer defined |
webcpp::codecs
Namespaces
| Name | Description |
|---|---|
The formats: each one is declared by its own header, and none by the core, so that a format named without its header is a name the namespace lacks. |
|
The secret heap types over |
|
The tags of the tokens that codecs turns into the concrete token of a direction (B6). |
Types
| Name | Description |
|---|---|
Secret bytes on the heap, of any allocator: the bytes of a secret decoding whose size is not known at compile time. |
|
A secret string on the heap, of any allocator: the text of a secret encoding whose size is not known at compile time. |
|
A stream transformer that accumulates its whole input and converts it at |
|
The fixed bytes result: |
|
The tag of a capacity in place of |
|
The conversion of a format between bytes and text: declared by the core, never defined, and specialized by each format’s header for its format’s type. |
|
A stream transformer that converts each input element on its own, as a whole unit, through the one-shot transformer |
|
Lets a library’s fixed type be the target of a typed decode. |
|
The transformer of a format’s decoding, text to bytes (D20): a one-shot transformer always, and a stream transformer when the format’s header specializes |
|
The transformer of a format’s encoding, bytes to text (D20): a one-shot transformer always, and a stream transformer when the format’s header specializes |
|
A list of formats, by type: what a |
|
Whether values of |
|
The composition of two formats: encoding encodes with |
|
A stream transformer that sends its input through |
|
The bytes of a secret decoding that fit |
|
The tag that makes a transformer of a format secret: |
|
The text of a secret encoding that fits |
|
What a stream transformer’s |
|
The stream conversion of a format between bytes and text: declared by the core, never defined, and specialized by a format’s header when the format streams natively, as |
|
The options of a format’s stream transformer, a structural type that |
|
The fixed text result: |
|
The conversion of a format between a typed value and its encoding: declared by the core, never defined, and specialized by the library that owns the format or the type, in the header that defines the pair. |
|
The formats a value type has, declared by the library that owns the type: declared by the core, never defined, as |
Type Aliases
| Name | Description |
|---|---|
The result of an operation of webcpp::codecs: a value or an error code. |
|
Secret bytes of |
|
A secret string of |
Enums
| Name | Description |
|---|---|
The direction of a conversion, for a reason of a |
|
Why a conversion of webcpp::codecs failed. |
|
The state of a stream transformer after a call, beside its result and never an error (D18). |
|
What a value codec’s encoding is made of. |
Functions
| Name | Description |
|---|---|
The category of every |
|
Checks, for a library’s own entry point that converts a value and is not one of codecs’ verbs (a decode that takes a memory resource), that the pair of |
|
|
|
|
|
|
|
|
|
The exact size of what |
|
|
|
Makes the |
|
A bound on the bytes |
|
|
|
|
|
Equality operators |
Variables
| Name | Description |
|---|---|
A capacity in place of |
|
The default capacity in place of a composition’s buffer of elements of type |
|
Whether a transformer of type |
|
Whether values of |
|
The tag that makes a transformer of a format secret, wiped and under secure’s timing guard. |
|
The size of an input of type |
Concepts
| Name | Description |
|---|---|
Whether a value of type |
|
Whether a value of type |
|
A format: a copyable type with a constant |
|
A transformer that converts a whole input at once: |
|
A transformer that converts a stream: |
webcpp::codecs::formats
The formats: each one is declared by its own header, and none by the core, so that a format named without its header is a name the namespace lacks.
Types
| Name | Description |
|---|---|
What a typed decode of the armor gives: the label, in place, and the bytes. |
|
The type of the format armor: RFC 7468’s strict textual encoding of bytes, with a label held in the value. |
|
The type of the format base32: RFC 4648 section 6’s alphabet, five bytes as eight symbols. |
|
The type of the format base32hex: RFC 4648 section 7’s alphabet, |
|
The type of the format base64: RFC 4648 section 4’s alphabet, three bytes as four symbols. |
|
The type of the format base64url: RFC 4648 section 5’s alphabet, |
|
RFC 7468’s armor with the label |
|
The type of the base58 formats: a payload of at most |
|
The type of the bech32 formats: a variant’s checksum, a longest text of |
|
The data mode of bytes, the default: the bytes regrouped from 8 bits to 5 with zero padding, as BIP-173’s |
|
What a typed decode of bech32 gives: the human-readable part, in small letters, and the data, each in place. |
|
The data mode of words: each element one 5-bit value, 0 to 31, written and read as it is, with no regrouping and no padding. |
|
Bitcoin’s alphabet: the digits and letters but |
|
Flickr’s alphabet: Bitcoin’s with the small letters before the capitals. |
|
The type of the format hex: base16, each byte as two hex digits, its high nibble first. |
|
No checksum: the payload is the whole number, the default of |
|
The type of the format percent: percent-encoding over Boost.URL, with the |
|
Ripple’s alphabet, of the XRP Ledger’s addresses. |
|
The type of the format z-base-32: bytes only, five bytes as eight symbols, the last group as short as its bytes make it (2, 4, 5 or 7 symbols) and its unused bits zero, no padding, no option. |
Type Aliases
| Name | Description |
|---|---|
The type of |
|
The type of |
|
The type of |
|
The type of |
|
The type of |
Enums
| Name | Description |
|---|---|
Which checksum a bech32 format computes: the constant its |
|
The case of the letters |
|
Whether a format writes its padding, |
Functions
| Name | Description |
|---|---|
Appends BIP-173’s |
|
Regroups 5-bit values into bytes, BIP-173’s |
|
Equality operators |
Variables
| Name | Description |
|---|---|
The format armor with no label: |
|
The format base32, writing its padding: |
|
The format base32hex, writing its padding: |
|
The default base58, |
|
base58 in Bitcoin’s alphabet, up to 100 bytes: Bitcoin’s addresses, WIF keys, BIP-32 keys. |
|
base58 in Flickr’s alphabet, up to 100 bytes. |
|
base58 in Ripple’s alphabet, up to 100 bytes. |
|
The format base64, writing its padding: |
|
The format base64url, omitting its padding: |
|
The format bech32 with no human-readable part: |
|
The format bech32m with no human-readable part: |
|
The format hex, writing lower case: |
|
The format percent, leaving the unreserved characters: |
|
The format z-base-32: |
Concepts
| Name | Description |
|---|---|
An alphabet of base58: a type whose |
|
A checksum of base58 (owner decision 26): |
webcpp::codecs::formats::base58_bitcoin_t
The type of formats::base58_bitcoin: 100 bytes in Bitcoin’s alphabet, no checksum.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
using base58_bitcoin_t = basic_base58<100, bitcoin_alphabet>;
webcpp::codecs::formats::base58_flickr_t
The type of formats::base58_flickr: 100 bytes in Flickr’s alphabet, no checksum.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
using base58_flickr_t = basic_base58<100, flickr_alphabet>;
webcpp::codecs::formats::base58_ripple_t
The type of formats::base58_ripple: 100 bytes in Ripple’s alphabet, no checksum.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
using base58_ripple_t = basic_base58<100, ripple_alphabet>;
webcpp::codecs::formats::bech32_t
The type of formats::bech32: BIP-173’s checksum, 90 characters, bytes.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
using bech32_t = basic_bech32<bech32_variant::bech32>;
webcpp::codecs::formats::bech32m_t
The type of formats::bech32m: BIP-350’s checksum, 90 characters, bytes.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
using bech32m_t = basic_bech32<bech32_variant::bech32m>;
webcpp::codecs::formats::armor_parts
What a typed decode of the armor gives: the label, in place, and the bytes.
Description
Its bytes are a public std::vector, never wiped, and it is no secret type: a secret payload (a PRIVATE KEY armor) is decoded into a secret type with the label in the format, codecs::decode<codecs::secret_byte_vector>(formats::armor("PRIVATE KEY"), text), or through the secret stream decoder, codecs::decoder(formats::armor, codecs::secret_operation), whose label() gives the label it read after a successful flush.
Data Members
Friends
| Name | Description |
|---|---|
Whether two parts hold the same label and the same bytes. |
webcpp::codecs::formats::armor_parts::data
The bytes of the payload.
webcpp::codecs::formats::armor_parts::label
The label of the BEGIN line, 1 to 64 characters.
webcpp::codecs::formats::armor_t
The type of the format armor: RFC 7468’s strict textual encoding of bytes, with a label held in the value.
Description
Encode writes -----BEGIN <label>-----, the padded base64 of the bytes in lines of 64 characters, the last shorter, and -----END <label>-----, each line ended by a line feed; the armor of no bytes is the two boundary lines. A format with no label encodes nothing: error::invalid_prefix in every form, whatever the input’s size, before any token is prepared (the codec’s encode_fault).
Decode takes lines ended by a line feed or by a carriage return and a line feed, the last line ending optional, and refuses, in this order: a fault of a boundary, error::invalid_prefix (a first line that is not -----BEGIN <label>-----, which explanatory text before it is; a last line that is not -----END <label>----- with the BEGIN line’s label, which explanatory text after it is; a label outside RFC 7468’s grammar, empty, or other than the format’s); then a fault of the lines, error::invalid_length (a line of the payload longer than 64 characters or shorter before the last, as RFC 1421’s headers and their empty line are, or as a space added to a line makes it, and an empty line); then base64’s own faults over the payload’s symbols, as formats::base64 reports them, the lowest value first (B23): a character that is no symbol, a space among them, error::invalid_character, a count of symbols that is not a multiple of 4, error::invalid_length, and padding out of its place or non-zero bits at its end, error::invalid_padding. The structure, which is public, comes before the payload. A label longer than 64 characters, or outside the grammar, given to the call is a fault of the configuration, error::invalid_prefix before anything is read. Input and output must not overlap.
Exactly one armor is decoded: two back to back are one text whose last line is the second END boundary, and the first END and the second BEGIN are lines of its payload, short or not symbols, error::invalid_length. The last line is taken as the END boundary, a structure, and branched on as such even when the last line of a malformed text holds payload (it is then error::invalid_prefix); the verdict that line gives is public.
Encode and decode, one-shot and streamed, index no table by a symbol’s or a byte’s value and branch on none (D12): the text’s length, its structure, its label, the result’s length and its success are public.
Member Functions
| Name | Description |
|---|---|
|
No label: it decodes any, and encodes nothing. |
The label the format holds, as it was given. |
|
The format with the label |
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
Friends
| Name | Description |
|---|---|
The stream codec of the armor (D20): an encoder that writes the BEGIN boundary with the first input, the base64 lines as it goes and the END boundary at |
|
The codec of the armor: its boundaries, and the base64 of the bytes in lines of 64, the payload in constant time. |
webcpp::codecs::formats::armor_t::label
The label the format holds, as it was given.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
constexpr
std::string_view
label() const noexcept;
Return Value
The label, valid while the format is; empty when it has none, or when the one given was longer than 64 characters.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::formats::armor_t::operator()
The format with the label chosen_label, held in the value: 1 to 64 characters of RFC 7468’s grammar (printable characters other than -, two of which a - or a space may separate); another is a fault of the configuration.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
constexpr
armor_t
operator()(std::string_view chosen_label) const noexcept;
Parameters
| Name | Description |
|---|---|
chosen_label |
The label, which the format does not borrow. |
webcpp::codecs::formats::armor_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
inline constexpr static
std::string_view name = "armor";
webcpp::codecs::formats::base32_t
The type of the format base32: RFC 4648 section 6’s alphabet, five bytes as eight symbols.
Description
Encode writes the padding = that completes the last group to eight characters unless the option is padding::omitted, and its symbols in upper case. Decode takes only the alphabet’s own symbols, in either case (a text with a line break, a space or one of base32hex’s 0, 1, 8 and 9 is error::invalid_character), refuses a length no encoding has with error::invalid_length (not a multiple of 8 with the padding written, a remainder of 1, 3 or 6 without it), and refuses padding against the option, a = out of its place (a run of other than 1, 3, 4 or 6 at the end of the text) and non-zero bits at the end of the last group with error::invalid_padding (MZ== is no text of f’s encoding, MY== is).
The two refusals are told apart by the rule of base64’s Z===: error::invalid_length is a text whose length no encoding has (with the padding written, a length that is not a multiple of 8, such as MZXW6YQ; without it, a remainder of 1, 3 or 6), and error::invalid_padding is a text of a length that has an encoding, a multiple of 8 with the padding written, whose = or bits are out of place. A trailing run of 2, 5, 7 or 8 = is therefore always error::invalid_padding, never error::invalid_length (MZXW6Y== has a length that is valid), and so is a = not at the end of the text, a run of 1, 3, 4 or 6 where the group’s characters do not fit it, and padding against the option (MZXW6=== with the padding omitted).
When a text has more than one fault, the lowest value of error is reported (B23): MZXW6YQ with the padding written is error::invalid_length. A text may be decoded into its own storage: byte i is written after the characters it comes from are read. Encode and decode, one-shot and streamed, index no table by a data byte and branch on none (D12); the text’s length, the result’s length and its success are public.
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::base32_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/base32.hpp>
inline constexpr static
std::string_view name = "base32";
webcpp::codecs::formats::base32hex_t
The type of the format base32hex: RFC 4648 section 7’s alphabet, 0 to 9 and A to V.
Description
It is base32’s format in everything but the alphabet and the order its texts keep: a text with W to Z is error::invalid_character, as one with 0, 1, 8 or 9 is in base32. Its padding is written by default, as base32’s.
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::base32hex_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/base32.hpp>
inline constexpr static
std::string_view name = "base32hex";
webcpp::codecs::formats::base64_t
The type of the format base64: RFC 4648 section 4’s alphabet, three bytes as four symbols.
Description
Encode writes the padding = that completes the last group to four characters unless the option is padding::omitted. Decode takes only the alphabet’s own symbols (a text with a line break, a space or one of base64url’s - and _ is error::invalid_character), refuses a length no encoding has with error::invalid_length (not a multiple of 4 with the padding written, 4k + 1 without it), and refuses padding against the option, a = out of its place and non-zero bits at the end of the last group with error::invalid_padding (Zh== is no text of f’s encoding, Zg== is). When a text has more than one fault, the lowest value of error is reported (B23). A text may be decoded into its own storage: byte i is written after the characters it comes from are read. Encode and decode, one-shot and streamed, index no table by a data byte and branch on none (D12); the text’s length, the result’s length and its success are public.
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::base64_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/base64.hpp>
inline constexpr static
std::string_view name = "base64";
webcpp::codecs::formats::base64url_t
The type of the format base64url: RFC 4648 section 5’s alphabet, - and _ for + and /, its padding omitted by default.
Description
It is base64’s format in everything but the alphabet and the default padding: a text with + or / is error::invalid_character.
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::base64url_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/base64.hpp>
inline constexpr static
std::string_view name = "base64url";
webcpp::codecs::formats::basic_armor
RFC 7468’s armor with the label Label::value, fixed by the type: no value of it holds another label (D11).
Description
It is the armor to name when the label follows from what the bytes are, as crypto’s PEM does: codecs::over<formats::basic_armor<Label>, Inner> writes and accepts that one label through every verb, with no label in a value to be wrong.
It encodes exactly what formats::armor(Label::value) encodes and decodes exactly what that armor accepts, another label refused with error::invalid_prefix; the typed decode into armor_parts gives Label::value; it streams, composes with over, is constant time and keeps secrets as armor_t does. It has no configuration and no encode fault: it always has its label. Its bound is its label’s: max_encoded_size(n) is the exact length of the armor of n bytes with Label::value, so that the default result of over{formats::basic_armor<Label>{}, inner} over a value codec of max_encoded_size M is exactly as long as the armor of M bytes (138 bytes under PRIVATE KEY: text<241>, where armor_t’s bound over every label gives text<347>).
Naming the type checks nothing; its codec checks the label where the format is used: a label that is empty, longer than 64 characters or outside RFC 7468’s grammar stops the build there, "an armor’s label is 1 to 64 characters of RFC 7468’s grammar".
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
Template Parameters
| Name | Description |
|---|---|
Label |
A type with |
webcpp::codecs::formats::basic_armor::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
inline constexpr static
std::string_view name = "armor";
webcpp::codecs::formats::basic_base58
The type of the base58 formats: a payload of at most MaximumBytes bytes, its checksum after it, as one number in base 58 written in Alphabet.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
template<
std::size_t MaximumBytes,
base58_alphabet Alphabet,
base58_checksum Checksum = no_checksum>
struct basic_base58;
Description
Encode writes each leading zero byte as the alphabet’s first character, then the number’s digits with no leading zero digit, as Bitcoin Core’s EncodeBase58; with a checksum, the checksum’s compute(payload) follows the payload in the number. Decode refuses a character outside the alphabet with error::invalid_character; with a checksum it splits the last checksum_size bytes off, refusing fewer with error::invalid_length, recomputes the checksum of the rest, compares the two with secure::constant_time_equal, refusing a mismatch with error::checksum_mismatch, and gives the payload alone. An input longer than maximum_bytes and a text longer than maximum_characters are error::input_too_long by their length, before any read, and then the only fault reported; a decode whose payload would be longer than maximum_bytes is error::input_too_long too, found after the conversion by the result’s length, which is public, and before the checksum is computed over it: a bound fault, reported after the text’s characters and length and before its checksum. Every operation works in a scratch in place, sized by the template for the larger of the two bounds, so that the sizes are exact, noexcept and allocation-free for every instance; the conversion is quadratic in the length, and the bound caps it. Input and output must not overlap.
The public path follows Bitcoin Core’s EncodeBase58 and DecodeBase58, with their early exits. A secret operation (a secret input, a secret token or a secret typed result) runs the constant-time conversion: every limb of the scratch’s bound for the input’s length is processed with no early exit, the leading zeros are counted by a mask scan, the alphabet is read by secure::constant_time::lookup and its inverse by masks, the checksum is compared inside the operation’s engaged timing guard and its verdict declassified, and the scratch and the checksums are wiped. The text’s length and the result’s success are public (D12).
Type Aliases
| Name | Description |
|---|---|
The alphabet. |
|
The checksum. |
Static Data Members
| Name | Description |
|---|---|
The checksum’s bytes: 0 for |
|
The longest payload, without the checksum. |
|
The longest text: the length of the longest encoding of |
|
The format’s name. |
Template Parameters
| Name | Description |
|---|---|
MaximumBytes |
The longest payload, without the checksum. |
Alphabet |
The alphabet, a type of |
Checksum |
|
webcpp::codecs::formats::basic_base58::alphabet_type
The alphabet.
webcpp::codecs::formats::basic_base58::checksum_type
The checksum.
webcpp::codecs::formats::basic_base58::checksum_size
The checksum’s bytes: 0 for no_checksum.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::size_t checksum_size = detail::base58_checksum_size<Checksum>;
webcpp::codecs::formats::basic_base58::maximum_bytes
The longest payload, without the checksum.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::size_t maximum_bytes = MaximumBytes;
webcpp::codecs::formats::basic_base58::maximum_characters
The longest text: the length of the longest encoding of maximum_bytes and the checksum, ceil(n * log(256) / log(58)) for n bytes, derived, never a parameter.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::size_t maximum_characters = detail::base58_encoded_length(MaximumBytes + checksum_size);
webcpp::codecs::formats::basic_base58::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::string_view name = "base58";
webcpp::codecs::formats::basic_bech32
The type of the bech32 formats: a variant’s checksum, a longest text of MaximumLength characters, a data mode, and a human-readable part held in the value.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
template<
bech32_variant Variant,
std::size_t MaximumLength = 90,
class Data = bech32_bytes>
class basic_bech32;
Description
Encode writes small letters: the human-readable part, 1, the data and the checksum; it refuses, in this order and in every form before any token is prepared, a format with no human-readable part with error::invalid_prefix whatever the input’s size, a text past MaximumLength with error::input_too_long and, in words mode, a word above 31 with error::invalid_character (the codec’s encode_fault). Decode takes either case, not both, and refuses, the lowest value of error winning when a text has several faults (B23): a character of the data outside the alphabet (error::invalid_character), a data part shorter than the checksum (error::invalid_length), over bytes more than 4 padding bits or a non-zero one (error::invalid_padding), a bad checksum (error::checksum_mismatch), a human-readable part other than the format’s, empty, longer than 83 characters, or holding a character outside 33 to 126, or no separator at all (error::invalid_prefix), and mixed case (error::mixed_case); a text past MaximumLength is error::input_too_long before it is read. A human-readable part of the format longer than 83 characters or outside 33 to 126 is a fault of its configuration, error::invalid_prefix before any data. The separator is the last 1 of a text. Input and output must not overlap. Encode and decode, one-shot and streamed, index no table by a data byte and branch on none (D12): the text’s length, its human-readable part, the result’s length and its success are public.
Type Aliases
| Name | Description |
|---|---|
The data mode. |
|
What a typed decode gives: the human-readable part and the data. |
Member Functions
| Name | Description |
|---|---|
|
No human-readable part: it decodes any, and encodes nothing. |
The human-readable part the format holds, as it was given. |
|
The format with the human-readable part |
|
The same format in words mode: each element one 5-bit value, as it is. |
Static Data Members
| Name | Description |
|---|---|
The longest text, in characters. |
|
The format’s name. |
Friends
| Name | Description |
|---|---|
The conversion of a format between bytes and text: declared by the core, never defined, and specialized by each format’s header for its format’s type. |
|
|
The type of the bech32 formats: a variant’s checksum, a longest text of |
Template Parameters
| Name | Description |
|---|---|
Variant |
The checksum’s variant. |
MaximumLength |
The longest text, at least 8 characters: the shortest text, a one-character part, the separator and the checksum. |
Data |
|
webcpp::codecs::formats::basic_bech32::data_type
The data mode.
webcpp::codecs::formats::basic_bech32::parts_type
What a typed decode gives: the human-readable part and the data.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
using parts_type = bech32_parts<Data, MaximumLength>;
webcpp::codecs::formats::basic_bech32::basic_bech32
No human-readable part: it decodes any, and encodes nothing.
webcpp::codecs::formats::basic_bech32::human_readable_part
The human-readable part the format holds, as it was given.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
[[nodiscard]]
constexpr
std::string_view
human_readable_part() const noexcept;
Return Value
The part, valid while the format is; empty when it has none, or when the one given was longer than 83 characters.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::formats::basic_bech32::operator()
The format with the human-readable part chosen_part, held in the value: 1 to 83 characters of 33 to 126, either case, its letters written small; another is a fault of the configuration.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
[[nodiscard]]
constexpr
basic_bech32
operator()(std::string_view chosen_part) const noexcept;
Parameters
| Name | Description |
|---|---|
chosen_part |
The human-readable part, which the format does not borrow. |
webcpp::codecs::formats::basic_bech32::words
The same format in words mode: each element one 5-bit value, as it is.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
[[nodiscard]]
constexpr
basic_bech32<Variant, MaximumLength, bech32_words>
words() const noexcept;
Return Value
The format over bech32_words, with this human-readable part.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::formats::basic_bech32::maximum_length
The longest text, in characters.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
inline constexpr static
std::size_t maximum_length = MaximumLength;
webcpp::codecs::formats::basic_bech32::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
inline constexpr static
std::string_view name = Variant == bech32_variant::bech32 ? "bech32" : "bech32m";
webcpp::codecs::formats::bech32_bytes
The data mode of bytes, the default: the bytes regrouped from 8 bits to 5 with zero padding, as BIP-173’s convertbits does, and the padding checked strictly on decode.
webcpp::codecs::formats::bech32_parts
What a typed decode of bech32 gives: the human-readable part, in small letters, and the data, each in place.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
template<
class Data,
std::size_t MaximumLength = 90>
struct bech32_parts;
Description
Its data are a public bytes<N>, never wiped, and it is no secret type: a secret payload (a Nostr nsec) is decoded into a secret type with the human-readable part in the format, codecs::decode<codecs::secret_bytes<32>>(formats::bech32("nsec"), text), or through the secret stream decoder, codecs::decoder(formats::bech32, codecs::secret_operation), whose human_readable_part() gives the part it read after a successful flush; a program that must learn the part first reads it from the format’s human_readable_part() it chose, or from that decoder.
Data Members
| Name | Description |
|---|---|
The data: the bytes, or the words, each 0 to 31. |
|
The human-readable part, 1 to 83 characters. |
Friends
| Name | Description |
|---|---|
Whether two parts hold the same human-readable part and the same data. |
Template Parameters
| Name | Description |
|---|---|
Data |
The data mode: bytes, or words. |
MaximumLength |
The instance’s longest text, which sizes the data. |
webcpp::codecs::formats::bech32_parts::data
The data: the bytes, or the words, each 0 to 31.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
webcpp::codecs::formats::bech32_parts::human_readable_part
The human-readable part, 1 to 83 characters.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
text<detail::bech32_longest_part> human_readable_part;
webcpp::codecs::formats::bech32_words
The data mode of words: each element one 5-bit value, 0 to 31, written and read as it is, with no regrouping and no padding.
Description
A word here is a 5-bit value, not a machine word.
webcpp::codecs::formats::bitcoin_alphabet
Bitcoin’s alphabet: the digits and letters but 0, O, I and l.
Static Data Members
| Name | Description |
|---|---|
The characters, digit 0 first. |
webcpp::codecs::formats::bitcoin_alphabet::characters
The characters, digit 0 first.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::string_view characters = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
webcpp::codecs::formats::flickr_alphabet
Flickr’s alphabet: Bitcoin’s with the small letters before the capitals.
Static Data Members
| Name | Description |
|---|---|
The characters, digit 0 first. |
webcpp::codecs::formats::flickr_alphabet::characters
The characters, digit 0 first.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::string_view characters = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
webcpp::codecs::formats::hex_t
The type of the format hex: base16, each byte as two hex digits, its high nibble first.
Description
Encode writes written_case; decode takes either case, mixed included, and refuses a text of an odd length with error::invalid_length and any character that is no hex digit with error::invalid_character, which wins when both are found. A text may be decoded into its own storage: byte i is written after characters 2i and 2i + 1 are read. Encode and decode, one-shot and streamed, index no table by a data byte and branch on none (D12); the text’s length and the result’s success are public.
Member Functions
| Name | Description |
|---|---|
The format writing letters in |
Data Members
| Name | Description |
|---|---|
The case of the letters encode writes. |
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::hex_t::operator()
The format writing letters in chosen case.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
constexpr
hex_t
operator()(letter_case chosen) const noexcept;
Parameters
| Name | Description |
|---|---|
chosen |
The case. |
webcpp::codecs::formats::no_checksum
No checksum: the payload is the whole number, the default of basic_base58.
webcpp::codecs::formats::percent_t
The type of the format percent: percent-encoding over Boost.URL, with the CharSet of the characters it leaves as they are and the options of Boost.URL’s encoding_opts.
Description
Encode writes a byte of char_set as it is and every other byte as % and two hex digits, in upper case unless options.lower_case; with options.space_as_plus a space is written as + and a plus sign always as %2B, as boost::urls::encode does. The percent sign is never a character of the set: it is written as %25 whatever char_set holds, as reserved_chars, which names it, would otherwise give a text no decode reads back.
Decode reads each escape, and a + as a space when options.space_as_plus. As boost::urls::decode, it does not check that the characters it takes as they are belong to the set: a text that holds a character the set would escape decodes to that character. It refuses a % followed by a character that is no hex digit with error::invalid_character, and a text that ends inside an escape with error::invalid_length; a text that does both, as "%g", gets error::invalid_character, the lowest value. options.disallow_null is Boost.URL’s, which neither its encode nor its decode reads. Input and output must not overlap: the decode is boost::urls::decode’s, which promises nothing of overlapping buffers.
Member Functions
| Name | Description |
|---|---|
The format leaving the characters of |
Data Members
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::percent_t::operator()
The format leaving the characters of chosen as they are and using chosen_options.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
template<class CharSet>
requires boost::urls::grammar::is_charset<CharSet>::value
[[nodiscard]]
constexpr
percent_t
operator()(
CharSet const& chosen,
boost::urls::encoding_opts chosen_options = {}) const noexcept;
Template Parameters
| Name | Description |
|---|---|
CharSet |
The type of a Boost.URL |
Parameters
| Name | Description |
|---|---|
chosen |
Any Boost.URL |
chosen_options |
The options of encode and decode. |
webcpp::codecs::formats::percent_t::char_set
The characters encode leaves as they are: the unreserved characters by default.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
boost::urls::grammar::lut_chars char_set = = boost::urls::unreserved_chars;
webcpp::codecs::formats::percent_t::options
Boost.URL’s options of encode and decode: none by default.
webcpp::codecs::formats::percent_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
inline constexpr static
std::string_view name = "percent";
webcpp::codecs::formats::ripple_alphabet
Ripple’s alphabet, of the XRP Ledger’s addresses.
Static Data Members
| Name | Description |
|---|---|
The characters, digit 0 first. |
webcpp::codecs::formats::ripple_alphabet::characters
The characters, digit 0 first.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr static
std::string_view characters = "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz";
webcpp::codecs::formats::zbase32_t
The type of the format z-base-32: bytes only, five bytes as eight symbols, the last group as short as its bytes make it (2, 4, 5 or 7 symbols) and its unused bits zero, no padding, no option.
Description
Encode writes lower case, and its exact size: 32 bytes are text<52>. Decode is canonical, one text for one byte string: a character that is no symbol of the alphabet, an upper-case letter and = among them (z-base-32 has no padding), is error::invalid_character; a length no byte count has (a remainder of 1, 3 or 6 characters modulo 8) is error::invalid_length; non-zero bits past the last byte are error::invalid_padding (yb is no text: one byte leaves two bits, and b is 1). When a text has more than one fault, the lowest value of error is reported (B23). pkarr’s decoder is more lenient on the last two (it truncates such a length and ignores those bits): a text it takes that this decode refuses is no z-base-32 its encoder writes.
The document’s bit-length mode, a length in bits known to both sides, is not this format’s: it converts bytes. A text may be decoded into its own storage. Encode and decode, one-shot and streamed, index no table by a data byte and branch on none (D12); the text’s length, the result’s length and its success are public.
Static Data Members
| Name | Description |
|---|---|
The format’s name. |
webcpp::codecs::formats::zbase32_t::name
The format’s name.
Synopsis
Declared in <webcpp/codecs/zbase32.hpp>
inline constexpr static
std::string_view name = "zbase32";
webcpp::codecs::formats::bech32_variant
Which checksum a bech32 format computes: the constant its polymod ends with.
Members
| Name | Description |
|---|---|
|
BIP-173’s bech32, whose constant is 1. |
|
BIP-350’s bech32m, whose constant is 0x2bc830a3. |
webcpp::codecs::formats::letter_case
The case of the letters a to f a format writes.
Members
| Name | Description |
|---|---|
|
|
|
|
webcpp::codecs::formats::padding
Whether a format writes its padding, =, which RFC 4648 section 3.2 completes the last group with.
Description
Decode takes the choice as the rule: a text with the padding the option does not give is refused with error::invalid_padding. A value of neither enumerator, cast from another integer (formats::padding{0}), is read as written, RFC 4648’s own form: a format omits its padding for padding::omitted alone, as each format that takes the option (base64’s, base32’s) does.
Members
| Name | Description |
|---|---|
|
The last group is completed with |
|
No |
webcpp::codecs::formats::append_words_from_bytes
Appends BIP-173’s convertbits of input_bytes from 8 bits to 5, the last group padded with zero bits, to words: the words of a segwit program after its version word, in words mode.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
template<class Words>
requires requires(Words& container, std::uint8_t element) { container.push_back(element); }
void
append_words_from_bytes(
Words& words,
std::span<uint8_t const> input_bytes);
Template Parameters
| Name | Description |
|---|---|
Words |
A container of bytes with |
Parameters
| Name | Description |
|---|---|
words |
The container appended to. |
input_bytes |
The bytes. |
webcpp::codecs::formats::bytes_from_words
Regroups 5-bit values into bytes, BIP-173’s convertbits from 5 to 8 with no padding added, in constant time as the format is; nothing is written on an error.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
[[nodiscard]]
result<std::size_t>
bytes_from_words(
std::span<uint8_t const> words,
std::span<uint8_t> output_bytes) noexcept;
Return Value
The bytes written, words.size() * 5 / 8, or error::invalid_character for a value above 31, else error::invalid_padding for more than 4 padding bits or a non-zero one, else error::output_too_small.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
words |
The values, which may be secret. |
output_bytes |
The buffer. |
webcpp::codecs::formats::operator==
Equality operators
Synopses
Declared in <webcpp/codecs/armor.hpp>
Whether two parts hold the same label and the same bytes.
constexpr
bool
operator==(
armor_parts const& first_parts,
armor_parts const& second_parts) = default;
Whether two parts hold the same human-readable part and the same data.
constexpr
bool
operator==(
bech32_parts const& first_parts,
bech32_parts const& second_parts) noexcept = default;
Return Value
Whether they are the same.
Parameters
| Name | Description |
|---|---|
first_parts |
Parts. |
second_parts |
Other parts. |
webcpp::codecs::formats::operator==
Whether two parts hold the same label and the same bytes.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
constexpr
bool
operator==(
armor_parts const& first_parts,
armor_parts const& second_parts) = default;
|
Note
|
This function is a hidden friend of armor_parts, declared only inside that class: it can be found only through argument-dependent lookup. |
Return Value
Whether they are the same.
Parameters
| Name | Description |
|---|---|
first_parts |
Parts. |
second_parts |
Other parts. |
webcpp::codecs::formats::operator==
Whether two parts hold the same human-readable part and the same data.
Synopsis
Declared in <webcpp/codecs/bech32.hpp>
constexpr
bool
operator==(
bech32_parts const& first_parts,
bech32_parts const& second_parts) noexcept = default;
|
Note
|
This function is a hidden friend of bech32_parts, declared only inside that class: it can be found only through argument-dependent lookup. |
Return Value
Whether they are the same.
Parameters
| Name | Description |
|---|---|
first_parts |
Parts. |
second_parts |
Other parts. |
webcpp::codecs::formats::armor
The format armor with no label: codecs::encode(codecs::formats::armor("PUBLIC KEY"), der).
webcpp::codecs::formats::base32
The format base32, writing its padding: codecs::encode(codecs::formats::base32, bytes).
webcpp::codecs::formats::base32hex
The format base32hex, writing its padding: codecs::encode(codecs::formats::base32hex, key).
webcpp::codecs::formats::base58
The default base58, base58_bitcoin: codecs::encode(formats::base58, address_bytes); a longer input names an instance, formats::basic_base58<1024, formats::bitcoin_alphabet>{}.
webcpp::codecs::formats::base58_bitcoin
base58 in Bitcoin’s alphabet, up to 100 bytes: Bitcoin’s addresses, WIF keys, BIP-32 keys.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr base58_bitcoin_t base58_bitcoin = {};
webcpp::codecs::formats::base58_flickr
base58 in Flickr’s alphabet, up to 100 bytes.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr base58_flickr_t base58_flickr = {};
webcpp::codecs::formats::base58_ripple
base58 in Ripple’s alphabet, up to 100 bytes.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
inline constexpr base58_ripple_t base58_ripple = {};
webcpp::codecs::formats::base64
The format base64, writing its padding: codecs::encode(codecs::formats::base64, bytes).
webcpp::codecs::formats::base64url
The format base64url, omitting its padding: codecs::encode(codecs::formats::base64url, key).
webcpp::codecs::formats::bech32
The format bech32 with no human-readable part: codecs::encode(formats::bech32("npub"), key).
webcpp::codecs::formats::bech32m
The format bech32m with no human-readable part: formats::bech32m("bc").words().
webcpp::codecs::formats::hex
The format hex, writing lower case: codecs::encode(formats::hex, digest).
webcpp::codecs::formats::percent
The format percent, leaving the unreserved characters: codecs::encode(formats::percent, text).
webcpp::codecs::formats::zbase32
The format z-base-32: codecs::encode(codecs::formats::zbase32, public_key).
webcpp::codecs::formats::base58_alphabet
An alphabet of base58: a type whose static constexpr std::string_view characters are its 58 characters, digit 0 first, from which its tables are built at compile time (owner decision 25).
Synopsis
Declared in <webcpp/codecs/base58.hpp>
template<class Alphabet>
concept base58_alphabet = std::same_as<decltype(Alphabet::characters), std::string_view const>;
Description
That they are 58 distinct characters is checked by basic_base58.
Template Parameters
| Name | Description |
|---|---|
Alphabet |
The type to check. |
webcpp::codecs::formats::base58_checksum
A checksum of base58 (owner decision 26): no_checksum, or a type with static constexpr std::size_t size, the checksum’s bytes, and `static void compute(std::span<std::uint8_t const> payload, std::span<std::uint8_t, size> out) noexcept`, which writes the checksum of the payload.
Synopsis
Declared in <webcpp/codecs/base58.hpp>
template<class Checksum>
concept base58_checksum = std::same_as<Checksum, no_checksum> ||
(std::same_as<decltype(Checksum::size), std::size_t const> &&
requires(std::span<std::uint8_t const> payload, std::span<std::uint8_t, Checksum::size> out) {
{ Checksum::compute(payload, out) } noexcept -> std::same_as<void>;
});
Description
It runs on secrets, so it must be constant time, which the concept cannot check. codecs defines no checksum algorithm: webcpp::hash’s double SHA-256 is one, in hash’s own header.
Template Parameters
| Name | Description |
|---|---|
Checksum |
The type to check. |
webcpp::codecs::pmr
The secret heap types over std::pmr::polymorphic_allocator, as std::pmr’s containers.
Type Aliases
| Name | Description |
|---|---|
Secret bytes of a memory resource. |
|
A secret string of a memory resource. |
webcpp::codecs::pmr::secret_byte_vector
Secret bytes of a memory resource.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
using secret_byte_vector = basic_secret_byte_vector<std::pmr::polymorphic_allocator<uint8_t>>;
webcpp::codecs::pmr::secret_string
A secret string of a memory resource.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
using secret_string = basic_secret_string<std::pmr::polymorphic_allocator<char>>;
webcpp::codecs::tokens
The tags of the tokens that codecs turns into the concrete token of a direction (B6).
Types
| Name | Description |
|---|---|
The default token (B7): the result of |
|
The tag that gives |
|
The tag that gives the result as a |
|
The tag that makes the operation secret (D10) and gives D9’s secret result: |
Variables
| Name | Description |
|---|---|
The tag |
|
The tag |
webcpp::codecs::tokens::automatic
The default token (B7): the result of encode and decode is the default result (D9).
webcpp::codecs::tokens::fixed
The tag that gives N elements in place: text<N> from encode, bytes<N> from decode.
Description
A value codec of bytes encodes into bytes<N>. A result that does not fit is error::output_too_small.
Static Data Members
| Name | Description |
|---|---|
The most elements. |
Template Parameters
| Name | Description |
|---|---|
N |
The most elements. |
webcpp::codecs::tokens::fixed::capacity
The most elements.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
inline constexpr static
std::size_t capacity = N;
webcpp::codecs::tokens::return_string_t
The tag that gives the result as a std::basic_string<char, std::char_traits<char>, A>, both ways (the bytes of a decode as characters), A the allocator rebound to char; also callable with an allocator that it keeps (B40).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Allocator = std::allocator<char>>
struct return_string_t;
Member Functions
| Name | Description |
|---|---|
A tag that gives the string over |
Data Members
| Name | Description |
|---|---|
The allocator the string is constructed with. |
Template Parameters
| Name | Description |
|---|---|
Allocator |
The allocator of the string, |
webcpp::codecs::tokens::return_string_t::operator()
A tag that gives the string over other, which is used through std::allocator_traits.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Other>
requires requires { typename std::allocator_traits<Other>::value_type; }
[[nodiscard]]
constexpr
return_string_t<Other>
operator()(Other const& other) const noexcept;
Template Parameters
| Name | Description |
|---|---|
Other |
The type of the allocator. |
Parameters
| Name | Description |
|---|---|
other |
The allocator. |
webcpp::codecs::tokens::return_string_t::allocator
The allocator the string is constructed with.
webcpp::codecs::tokens::secret_t
The tag that makes the operation secret (D10) and gives D9’s secret result: secret_text<N> from encode (secret_bytes<N> for a value codec of bytes) and secret_bytes<N> from decode when the bound is known at compile time, ignoring the allocator, and otherwise basic_secret_string (basic_secret_byte_vector for bytes), A the allocator rebound to the element; also callable with an allocator that it keeps (B40).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Allocator = std::allocator<char>>
struct secret_t;
Member Functions
| Name | Description |
|---|---|
A tag that gives a heap result over |
Data Members
| Name | Description |
|---|---|
The allocator a heap result is constructed with, rebound to its element. |
Static Data Members
| Name | Description |
|---|---|
The operation is secret (D8). |
Template Parameters
| Name | Description |
|---|---|
Allocator |
The allocator of a heap result, |
webcpp::codecs::tokens::secret_t::operator()
A tag that gives a heap result over other, which is used through std::allocator_traits.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Other>
requires requires { typename std::allocator_traits<Other>::value_type; }
[[nodiscard]]
constexpr
secret_t<Other>
operator()(Other const& other) const noexcept;
Template Parameters
| Name | Description |
|---|---|
Other |
The type of the allocator. |
Parameters
| Name | Description |
|---|---|
other |
The allocator. |
webcpp::codecs::tokens::secret_t::allocator
The allocator a heap result is constructed with, rebound to its element.
webcpp::codecs::tokens::secret_t::secret
The operation is secret (D8).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
inline constexpr static
bool secret = true;
webcpp::codecs::tokens::append_to
append_to overloads
Synopses
Declared in <webcpp/codecs/detail/core/tokens.hpp>
The tag that appends the bytes of a decode (or of a value codec of bytes) to target, a vector of any allocator.
template<class Allocator>
[[nodiscard]]
auto
append_to(std::vector<uint8_t, Allocator>& target) noexcept;
The tag that appends the result to target, a string of any traits and allocator.
template<
class Traits,
class Allocator>
[[nodiscard]]
auto
append_to(std::basic_string<char, Traits, Allocator>& target) noexcept;
Template Parameters
| Name | Description |
|---|---|
Allocator |
The vector’s allocator. |
Traits |
The string’s character traits. |
Parameters
| Name | Description |
|---|---|
target |
The vector to append to. |
webcpp::codecs::tokens::append_to
The tag that appends the bytes of a decode (or of a value codec of bytes) to target, a vector of any allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Allocator>
[[nodiscard]]
auto
append_to(std::vector<uint8_t, Allocator>& target) noexcept;
Description
The vector’s own allocator is used. The operation returns target by reference.
Template Parameters
| Name | Description |
|---|---|
Allocator |
The vector’s allocator. |
Parameters
| Name | Description |
|---|---|
target |
The vector to append to. |
webcpp::codecs::tokens::append_to
The tag that appends the result to target, a string of any traits and allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<
class Traits,
class Allocator>
[[nodiscard]]
auto
append_to(std::basic_string<char, Traits, Allocator>& target) noexcept;
Description
The string’s own allocator is used. The operation returns target by reference, as Boost.URL’s does; the bytes of a decode are appended as characters. The input must not be a part of target. In a secret operation the characters the string does not keep (all those appended when the operation fails) are wiped before it is cut.
Template Parameters
| Name | Description |
|---|---|
Traits |
The string’s character traits. |
Allocator |
The string’s allocator. |
Parameters
| Name | Description |
|---|---|
target |
The string to append to. |
webcpp::codecs::tokens::assign_to
assign_to overloads
Synopses
Declared in <webcpp/codecs/detail/core/tokens.hpp>
The tag that replaces the content of target, a vector of any allocator, with the bytes of a decode (or of a value codec of bytes).
template<class Allocator>
[[nodiscard]]
auto
assign_to(std::vector<uint8_t, Allocator>& target) noexcept;
The tag that replaces the content of target, a string of any traits and allocator, with the result.
template<
class Traits,
class Allocator>
[[nodiscard]]
auto
assign_to(std::basic_string<char, Traits, Allocator>& target) noexcept;
Template Parameters
| Name | Description |
|---|---|
Allocator |
The vector’s allocator. |
Traits |
The string’s character traits. |
Parameters
| Name | Description |
|---|---|
target |
The vector to assign to. |
webcpp::codecs::tokens::assign_to
The tag that replaces the content of target, a vector of any allocator, with the bytes of a decode (or of a value codec of bytes).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<class Allocator>
[[nodiscard]]
auto
assign_to(std::vector<uint8_t, Allocator>& target) noexcept;
Description
The vector’s own allocator is used. The operation returns target by reference, and leaves it as it was when it fails, as assign_to of a string does.
Template Parameters
| Name | Description |
|---|---|
Allocator |
The vector’s allocator. |
Parameters
| Name | Description |
|---|---|
target |
The vector to assign to. |
webcpp::codecs::tokens::assign_to
The tag that replaces the content of target, a string of any traits and allocator, with the result.
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
template<
class Traits,
class Allocator>
[[nodiscard]]
auto
assign_to(std::basic_string<char, Traits, Allocator>& target) noexcept;
Description
The string’s own allocator is used. The operation returns target by reference, and leaves it as it was when it fails, also after the conversion began (a value codec’s own error) and when an allocation throws: the conversion writes into a scratch, in place when the bound is known at compile time and at most 4096 characters, else of the string’s allocator (one allocation), and the string gets the result only on success, by one copy, so that the input may be a part of target. The string keeps its buffer when it holds the result. In a secret operation the scratch is wiped before it is given back.
Template Parameters
| Name | Description |
|---|---|
Traits |
The string’s character traits. |
Allocator |
The string’s allocator. |
Parameters
| Name | Description |
|---|---|
target |
The string to assign to. |
webcpp::codecs::tokens::return_string
The tag return_string: a std::string, or with an allocator return_string(allocator).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
inline constexpr return_string_t<> return_string = {};
webcpp::codecs::tokens::secret
The tag secret: a secret result, or with an allocator secret(allocator).
Synopsis
Declared in <webcpp/codecs/detail/core/tokens.hpp>
inline constexpr secret_t<> secret = {};
webcpp::codecs::result
The result of an operation of webcpp::codecs: a value or an error code.
Synopsis
Declared in <webcpp/codecs/detail/core/error.hpp>
template<class T>
using result = boost::system::result<T>;
Template Parameters
| Name | Description |
|---|---|
T |
The type of the value. |
webcpp::codecs::secret_byte_vector
Secret bytes of std::allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
using secret_byte_vector = basic_secret_byte_vector<>;
webcpp::codecs::secret_string
A secret string of std::allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
using secret_string = basic_secret_string<>;
webcpp::codecs::basic_secret_byte_vector
Secret bytes on the heap, of any allocator: the bytes of a secret decoding whose size is not known at compile time.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
template<class Allocator = std::allocator<uint8_t>>
class basic_secret_byte_vector;
Description
It is move-only: a copy is asked for by name, with clone(). Every buffer it held is wiped by secure::erase_secret, its whole capacity, before the allocator gets it back: on destruction, on shrink_to_fit, and the old buffer when it grows, with any allocator, an arena’s included. The allocator is used through std::allocator_traits and propagates as the standard library’s containers’ does; a move assignment between unequal allocators that do not propagate copies the bytes into the target’s memory and wipes the source’s. The allocating members may throw what the allocator throws, and then leave the value as it was; codecs throws nothing of its own. It has no operator==, whose time would tell where two secrets differ.
Type Aliases
| Name | Description |
|---|---|
The allocator type. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Wipes the buffer, its whole capacity, and gives it back. |
Assignment operators |
|
Appends |
|
The number of bytes the vector holds without allocating. |
|
Wipes the bytes and sets the size to 0; the buffer stays. |
|
A copy of the bytes in a buffer of their size, which the caller then owns, of the allocator |
|
The bytes, or null when there is no buffer. |
|
Whether there is no byte. |
|
The allocator. |
|
Makes room for |
|
Sets the size to |
|
Moves the bytes to a buffer of their size, the old one wiped and given back. |
|
The number of bytes. |
|
Exchanges the bytes and the buffers of these bytes and |
|
|
Friends
| Name | Description |
|---|---|
Exchanges the bytes of two byte vectors, as their member |
Template Parameters
| Name | Description |
|---|---|
Allocator |
An allocator of |
webcpp::codecs::basic_secret_byte_vector::allocator_type
The allocator type.
webcpp::codecs::basic_secret_byte_vector::basic_secret_byte_vector
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Constructs empty bytes of a default-constructed allocator, which allocate nothing until they hold a byte.
basic_secret_byte_vector() noexcept(/* see-below */)
requires std::default_initializable<Allocator>;
Not copyable: a copy is asked for by name, with clone.
basic_secret_byte_vector(basic_secret_byte_vector const&) = delete;
Takes the buffer and the allocator of moved_bytes, which are left empty.
basic_secret_byte_vector(basic_secret_byte_vector&& moved_bytes) noexcept = default;
Constructs empty bytes, which allocate nothing until they hold a byte.
explicit
basic_secret_byte_vector(Allocator const& allocator) noexcept;
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take the buffer of. |
allocator |
The allocator of their buffers. |
webcpp::codecs::basic_secret_byte_vector::basic_secret_byte_vector
Constructs empty bytes of a default-constructed allocator, which allocate nothing until they hold a byte.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_byte_vector() noexcept(/* see-below */)
requires std::default_initializable<Allocator>;
Description
It is not explicit, as the standard containers’ default constructor (LWG 2193), so that return {}; and a member initialized by {} make one; it exists when the allocator is default-constructible.
Exception specification
This function is potentially-throwing unless std::is_nothrow_default_constructible_v<Allocator>.
webcpp::codecs::basic_secret_byte_vector::basic_secret_byte_vector
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_byte_vector(basic_secret_byte_vector const&) = delete;
webcpp::codecs::basic_secret_byte_vector::basic_secret_byte_vector
Takes the buffer and the allocator of moved_bytes, which are left empty.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_byte_vector(basic_secret_byte_vector&& moved_bytes) noexcept = default;
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take the buffer of. |
webcpp::codecs::basic_secret_byte_vector::basic_secret_byte_vector
Constructs empty bytes, which allocate nothing until they hold a byte.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
explicit
basic_secret_byte_vector(Allocator const& allocator) noexcept;
Parameters
| Name | Description |
|---|---|
allocator |
The allocator of their buffers. |
webcpp::codecs::basic_secret_byte_vector::~basic_secret_byte_vector
Wipes the buffer, its whole capacity, and gives it back.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
~basic_secret_byte_vector() = default;
webcpp::codecs::basic_secret_byte_vector::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Not copyable: a copy is asked for by name, with clone.
basic_secret_byte_vector&
operator=(basic_secret_byte_vector const&) = delete;
Gives back this buffer, wiped, and takes moved_bytes’s, as std::allocator_traits says.
basic_secret_byte_vector&
operator=(basic_secret_byte_vector&& moved_bytes) = default;
Return Value
These bytes.
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::basic_secret_byte_vector::operator=
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_byte_vector&
operator=(basic_secret_byte_vector const&) = delete;
webcpp::codecs::basic_secret_byte_vector::operator=
Gives back this buffer, wiped, and takes moved_bytes’s, as std::allocator_traits says.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_byte_vector&
operator=(basic_secret_byte_vector&& moved_bytes) = default;
Description
It takes the allocator too when the allocator propagates on move assignment; between unequal allocators that do not, it copies the bytes into this vector’s memory and wipes moved_bytes’s. moved_bytes are left empty. The copy allocates, and may throw what the allocator throws, which leaves both as they were; it is noexcept for an allocator that propagates on move assignment or is always equal, std::allocator among them.
Return Value
These bytes.
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::basic_secret_byte_vector::append
Appends appended, which may be bytes of this vector.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
append(std::span<uint8_t const> appended);
Description
Past the capacity, a buffer at least twice as large is allocated, and the old one wiped and given back.
Parameters
| Name | Description |
|---|---|
appended |
The bytes. |
webcpp::codecs::basic_secret_byte_vector::capacity
The number of bytes the vector holds without allocating.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
capacity() const noexcept;
webcpp::codecs::basic_secret_byte_vector::clear
Wipes the bytes and sets the size to 0; the buffer stays.
webcpp::codecs::basic_secret_byte_vector::clone
A copy of the bytes in a buffer of their size, which the caller then owns, of the allocator std::allocator_traits gives a copy.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
basic_secret_byte_vector
clone() const;
webcpp::codecs::basic_secret_byte_vector::data
The bytes, or null when there is no buffer.
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The bytes, or null when there is no buffer.
[[nodiscard]]
uint8_t*
data() noexcept;
The bytes, or null when there is no buffer.
[[nodiscard]]
uint8_t const*
data() const noexcept;
webcpp::codecs::basic_secret_byte_vector::data
The bytes, or null when there is no buffer.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
uint8_t*
data() noexcept;
webcpp::codecs::basic_secret_byte_vector::data
The bytes, or null when there is no buffer.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
uint8_t const*
data() const noexcept;
webcpp::codecs::basic_secret_byte_vector::empty
Whether there is no byte.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
bool
empty() const noexcept;
webcpp::codecs::basic_secret_byte_vector::get_allocator
The allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
Allocator
get_allocator() const noexcept;
webcpp::codecs::basic_secret_byte_vector::reserve
Makes room for new_capacity bytes, in a new buffer, the old one wiped and given back; a smaller capacity changes nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
reserve(std::size_t new_capacity);
Parameters
| Name | Description |
|---|---|
new_capacity |
The bytes to hold without allocating. |
webcpp::codecs::basic_secret_byte_vector::resize_for_overwrite
Sets the size to new_size: the bytes past the old size are left for the caller to write through data(), and those cut off are wiped.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
resize_for_overwrite(std::size_t new_size);
Parameters
| Name | Description |
|---|---|
new_size |
The number of bytes. |
webcpp::codecs::basic_secret_byte_vector::shrink_to_fit
Moves the bytes to a buffer of their size, the old one wiped and given back.
webcpp::codecs::basic_secret_byte_vector::size
The number of bytes.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
size() const noexcept;
webcpp::codecs::basic_secret_byte_vector::swap
Exchanges the bytes and the buffers of these bytes and other_bytes.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
swap(basic_secret_byte_vector& other_bytes) noexcept(/* see-below */);
Description
The allocators are exchanged too when they propagate on swap (propagate_on_container_swap); allocators that do not must be equal, as the standard containers require. Nothing is copied, allocated or wiped.
Exception specification
This function is potentially-throwing unless noexcept(this->buffer_.swap(other_bytes.buffer_)).
Parameters
| Name | Description |
|---|---|
other_bytes |
The bytes to exchange with. |
webcpp::codecs::basic_secret_byte_vector::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The bytes, valid until the vector changes.
[[nodiscard]]
std::span<uint8_t const>
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
webcpp::codecs::basic_secret_byte_vector::view
The bytes, valid until the vector changes.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::span<uint8_t const>
view() const & noexcept;
webcpp::codecs::basic_secret_byte_vector::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::basic_secret_string
A secret string on the heap, of any allocator: the text of a secret encoding whose size is not known at compile time.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
template<class Allocator = std::allocator<char>>
class basic_secret_string;
Description
It is move-only: a copy is asked for by name, with clone(). Every buffer it held is wiped by secure::erase_secret, its whole capacity, before the allocator gets it back: on destruction, on shrink_to_fit, and the old buffer when it grows, with any allocator, an arena’s included. It is never a std::basic_string, whose small buffer no allocator can wipe. The allocator is used through std::allocator_traits and propagates as the standard library’s containers’ does; a move assignment between unequal allocators that do not propagate copies the characters into the target’s memory and wipes the source’s. The allocating members may throw what the allocator throws, and then leave the value as it was; codecs throws nothing of its own. It has no operator==, whose time would tell where two secrets differ.
Type Aliases
| Name | Description |
|---|---|
The allocator type. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Wipes the buffer, its whole capacity, and gives it back. |
Assignment operators |
|
Appends |
|
The number of characters the string holds without allocating. |
|
Wipes the characters and sets the size to 0; the buffer stays. |
|
A copy of the characters in a buffer of their size, which the caller then owns, of the allocator |
|
The characters, or null when there is no buffer. |
|
Whether there is no character. |
|
The allocator. |
|
Makes room for |
|
Sets the size to |
|
Moves the characters to a buffer of their size, the old one wiped and given back. |
|
The number of characters. |
|
Exchanges the characters and the buffers of this string and |
|
|
Friends
| Name | Description |
|---|---|
Exchanges the characters of two strings, as their member |
Template Parameters
| Name | Description |
|---|---|
Allocator |
An allocator of |
webcpp::codecs::basic_secret_string::allocator_type
The allocator type.
webcpp::codecs::basic_secret_string::basic_secret_string
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Constructs an empty string of a default-constructed allocator, which allocates nothing until it holds a character.
basic_secret_string() noexcept(/* see-below */)
requires std::default_initializable<Allocator>;
Not copyable: a copy is asked for by name, with clone.
basic_secret_string(basic_secret_string const&) = delete;
Takes the buffer and the allocator of moved_string, which is left empty.
basic_secret_string(basic_secret_string&& moved_string) noexcept = default;
Constructs an empty string, which allocates nothing until it holds a character.
explicit
basic_secret_string(Allocator const& allocator) noexcept;
Parameters
| Name | Description |
|---|---|
moved_string |
The string to take the buffer of. |
allocator |
The allocator of its buffers. |
webcpp::codecs::basic_secret_string::basic_secret_string
Constructs an empty string of a default-constructed allocator, which allocates nothing until it holds a character.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_string() noexcept(/* see-below */)
requires std::default_initializable<Allocator>;
Description
It is not explicit, as the standard containers’ default constructor (LWG 2193), so that return {}; and a member initialized by {} make one; it exists when the allocator is default-constructible.
Exception specification
This function is potentially-throwing unless std::is_nothrow_default_constructible_v<Allocator>.
webcpp::codecs::basic_secret_string::basic_secret_string
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_string(basic_secret_string const&) = delete;
webcpp::codecs::basic_secret_string::basic_secret_string
Takes the buffer and the allocator of moved_string, which is left empty.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_string(basic_secret_string&& moved_string) noexcept = default;
Parameters
| Name | Description |
|---|---|
moved_string |
The string to take the buffer of. |
webcpp::codecs::basic_secret_string::basic_secret_string
Constructs an empty string, which allocates nothing until it holds a character.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
explicit
basic_secret_string(Allocator const& allocator) noexcept;
Parameters
| Name | Description |
|---|---|
allocator |
The allocator of its buffers. |
webcpp::codecs::basic_secret_string::~basic_secret_string
Wipes the buffer, its whole capacity, and gives it back.
webcpp::codecs::basic_secret_string::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Not copyable: a copy is asked for by name, with clone.
basic_secret_string&
operator=(basic_secret_string const&) = delete;
Gives back this buffer, wiped, and takes moved_string’s, as std::allocator_traits says.
basic_secret_string&
operator=(basic_secret_string&& moved_string) = default;
Return Value
This string.
Parameters
| Name | Description |
|---|---|
moved_string |
The string to take the characters of. |
webcpp::codecs::basic_secret_string::operator=
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_string&
operator=(basic_secret_string const&) = delete;
webcpp::codecs::basic_secret_string::operator=
Gives back this buffer, wiped, and takes moved_string’s, as std::allocator_traits says.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
basic_secret_string&
operator=(basic_secret_string&& moved_string) = default;
Description
It takes the allocator too when the allocator propagates on move assignment; between unequal allocators that do not, it copies the characters into this string’s memory and wipes moved_string’s. moved_string is left empty. The copy allocates, and may throw what the allocator throws, which leaves both strings as they were; it is noexcept for an allocator that propagates on move assignment or is always equal, std::allocator among them.
Return Value
This string.
Parameters
| Name | Description |
|---|---|
moved_string |
The string to take the characters of. |
webcpp::codecs::basic_secret_string::append
Appends appended, which may be characters of this string.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
append(std::string_view appended);
Description
Past the capacity, a buffer at least twice as large is allocated, and the old one wiped and given back.
Parameters
| Name | Description |
|---|---|
appended |
The characters. |
webcpp::codecs::basic_secret_string::capacity
The number of characters the string holds without allocating.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
capacity() const noexcept;
webcpp::codecs::basic_secret_string::clear
Wipes the characters and sets the size to 0; the buffer stays.
webcpp::codecs::basic_secret_string::clone
A copy of the characters in a buffer of their size, which the caller then owns, of the allocator std::allocator_traits gives a copy.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
basic_secret_string
clone() const;
webcpp::codecs::basic_secret_string::data
The characters, or null when there is no buffer.
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The characters, or null when there is no buffer.
[[nodiscard]]
char*
data() noexcept;
The characters, or null when there is no buffer.
[[nodiscard]]
char const*
data() const noexcept;
Return Value
A pointer to the first character, or null.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::basic_secret_string::data
The characters, or null when there is no buffer.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
char*
data() noexcept;
Return Value
A pointer to the first character, or null.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::basic_secret_string::data
The characters, or null when there is no buffer.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
char const*
data() const noexcept;
Return Value
A pointer to the first character, or null.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::basic_secret_string::empty
Whether there is no character.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
bool
empty() const noexcept;
webcpp::codecs::basic_secret_string::get_allocator
The allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
Allocator
get_allocator() const noexcept;
webcpp::codecs::basic_secret_string::reserve
Makes room for new_capacity characters, in a new buffer, the old one wiped and given back; a smaller capacity changes nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
reserve(std::size_t new_capacity);
Parameters
| Name | Description |
|---|---|
new_capacity |
The characters to hold without allocating. |
webcpp::codecs::basic_secret_string::resize_for_overwrite
Sets the size to new_size: the characters past the old size are left for the caller to write through data(), and those cut off are wiped.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
resize_for_overwrite(std::size_t new_size);
Parameters
| Name | Description |
|---|---|
new_size |
The number of characters. |
webcpp::codecs::basic_secret_string::shrink_to_fit
Moves the characters to a buffer of their size, the old one wiped and given back.
webcpp::codecs::basic_secret_string::size
The number of characters.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
size() const noexcept;
webcpp::codecs::basic_secret_string::swap
Exchanges the characters and the buffers of this string and other_string.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
swap(basic_secret_string& other_string) noexcept(/* see-below */);
Description
The allocators are exchanged too when they propagate on swap (propagate_on_container_swap); allocators that do not must be equal, as the standard containers require. Nothing is copied, allocated or wiped.
Exception specification
This function is potentially-throwing unless noexcept(this->buffer_.swap(other_string.buffer_)).
Parameters
| Name | Description |
|---|---|
other_string |
The string to exchange with. |
webcpp::codecs::basic_secret_string::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The characters, valid until the string changes.
[[nodiscard]]
std::string_view
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::string_view
view() const && = delete;
webcpp::codecs::basic_secret_string::view
The characters, valid until the string changes.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::string_view
view() const & noexcept;
webcpp::codecs::basic_secret_string::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::string_view
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::buffered
A stream transformer that accumulates its whole input and converts it at flush through the one-shot transformer T (D19): a conversion that cannot stream, as base58’s, has the whole input as its minimal state.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
one_shot_transformer T,
class Storage = std::allocator<T::input_type>>
class buffered;
Description
It is made by codecs::buffered(transformer), codecs::buffered(transformer, codecs::capacity<N>) or codecs::buffered(transformer, allocator).
send copies what it accepts into its storage, so that it never borrows, and returns flow::needs_input; every receive before flush gives nothing. flush runs transform over the whole input into the output storage and returns flow::output_pending while output remains, flow::finished when none does; receive then delivers the output over as many receives as the caller’s spans need. A fault, T’s or the input’s length, is reported by flush, and every later call returns it until reset. A fault of T’s configuration (a format’s transformer’s, codecs::buffered(codecs::encoder(formats::armor(label))) with a bad label) is asked when the stream is made and reported by its first call, whatever it is, and by every call after, also after reset, before any input is accepted.
With codecs::capacity<N>, the storage holds N input elements and T::max_output_size(N) output elements in place, which T must state as a constant expression at N (a static_assert names the fix otherwise), and nothing is allocated; an input past N is accepted, counted, and reported at flush as error::input_too_long; every member is noexcept when T’s transform and the copies of its elements are. With an allocator, the storage comes from it, rebound through std::allocator_traits for each element type: the input grows as send accepts, and the output is sized at flush by T’s exact output_size(input) when it states one, else by its static max_output_size, else by doubling while transform reports output_too_small. A bound of the object’s own (a non-static max_output_size, as a configured format’s may be) is not read, and such a T is sized by doubling, up to the most the allocator holds. reset keeps that memory. Construction allocates nothing; send and flush may allocate and are not noexcept, and an allocator’s exception propagates: a send that throws accepts nothing and leaves the stream as it was, and a flush that throws leaves it as it was before the flush, valid and resettable. receive allocates nothing in either form.
It is constant time when T is. A move takes the input, the output and the state, and leaves the moved-from buffered in the state reset leaves, so that it converts a new input from the start, provided that a moved-from T still transforms (a requirement of one_shot_transformer), since it keeps calling the T the move left it.
It is secret when T is (codecs::is_secret_v, D21): then it is move-only, each of its calls, reset included, holds an engaged secure::timing_guard, which nests with T’s own, and its storage, the input and the output, whose elements must then be trivially copyable, is wiped by secure::erase_secret on reset, on destruction, in the moved-from stream on a move, in the stream a move assigns to before it takes the other’s, and, from an allocator, before the memory it outgrows goes back. Over a secret format’s encoder, its flush runs the format’s secret arithmetic (base58’s, ruling R7).
Type Aliases
| Name | Description |
|---|---|
The elements read: |
|
The elements written: |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input and converts it whole; a second call returns the state. |
|
The allocator of the storage: the heap form alone. |
|
Writes the output of the whole input into |
|
Returns to |
|
Copies all of |
Static Data Members
| Name | Description |
|---|---|
The stream runs in a time that does not depend on its data when |
Deduction Guides
| Name | Description |
|---|---|
Deduces |
|
Deduces |
|
Deduces |
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer. |
Storage |
|
webcpp::codecs::buffered::buffered
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
A copy holds what other holds; a secret stream is not copyable (D21).
Takes other’s transformer, input, output and state, and leaves other as reset does.
Makes a stream of transformer, in flow::needs_input, with a default Storage.
explicit
buffered(T transformer) noexcept(/* see-below */);
Makes a stream of transformer, in flow::needs_input.
buffered(
T transformer,
Storage const& storage) noexcept(nothrow_construction);
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
transformer |
The one-shot transformer. |
storage |
|
webcpp::codecs::buffered::buffered
A copy holds what other holds; a secret stream is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
buffered(buffered const& other)
requires (!secret) = default;
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::buffered::buffered
Takes other’s transformer, input, output and state, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
buffered(buffered&& other) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_constructible_v<input_storage> && std::is_nothrow_move_constructible_v<output_storage>.
Parameters
| Name | Description |
|---|---|
other |
The stream moved from. |
webcpp::codecs::buffered::buffered
Makes a stream of transformer, in flow::needs_input, with a default Storage.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
explicit
buffered(T transformer) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless nothrow_construction && std::is_nothrow_default_constructible_v<Storage>.
Parameters
| Name | Description |
|---|---|
transformer |
The one-shot transformer. |
webcpp::codecs::buffered::buffered
Makes a stream of transformer, in flow::needs_input.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
buffered(
T transformer,
Storage const& storage) noexcept(nothrow_construction);
Parameters
| Name | Description |
|---|---|
transformer |
The one-shot transformer. |
storage |
|
webcpp::codecs::buffered::~buffered
Destructors
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Destroys the transformer and the storage, wiped first: a secret stream’s.
~buffered()
requires secret;
Destroys the transformer and the storage; a public stream wipes nothing.
~buffered() = default;
webcpp::codecs::buffered::~buffered
Destroys the transformer and the storage, wiped first: a secret stream’s.
webcpp::codecs::buffered::~buffered
Destroys the transformer and the storage; a public stream wipes nothing.
webcpp::codecs::buffered::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
A copy holds what other holds; a secret stream is not copyable (D21).
Takes other’s transformer, input, output and state, and leaves other as reset does.
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::buffered::operator=
A copy holds what other holds; a secret stream is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::buffered::operator=
Takes other’s transformer, input, output and state, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_assignable_v<input_storage> && std::is_nothrow_move_assignable_v<output_storage>.
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream moved from. |
webcpp::codecs::buffered::flush
Ends the input and converts it whole; a second call returns the state.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<flow>
flush() noexcept(nothrow_flush);
Return Value
flow::output_pending while output remains, flow::finished when none does, or the stream’s error: T’s, or error::input_too_long for an input past the storage’s capacity.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::buffered::get_allocator
The allocator of the storage: the heap form alone.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
Storage
get_allocator() const noexcept
requires (!in_place);
webcpp::codecs::buffered::receive
Writes the output of the whole input into output, after flush; nothing before it.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<step>
receive(std::span<output_type> output) noexcept(nothrow_receive);
Return Value
The elements written and the state after, or the stream’s error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::buffered::reset
Returns to flow::needs_input with nothing held, pending or in error; the allocated storage is kept for the next stream, wiped when the stream is secret.
webcpp::codecs::buffered::send
Copies all of input into the storage in flow::needs_input, and accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<step>
send(std::span<input_type const> input) noexcept(nothrow_send);
Description
An input past the storage’s capacity is accepted and counted, and reported at flush.
Return Value
The elements accepted and flow::needs_input, {0, state}, or the stream’s error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The elements to convert, copied. |
webcpp::codecs::buffered::constant_time
The stream runs in a time that does not depend on its data when T does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
inline constexpr static
bool constant_time = is_constant_time_v<T>;
webcpp::codecs::bytes
The fixed bytes result: N bytes in place and a size (defined in results.hpp).
Member Functions
| Name | Description |
|---|---|
|
Constructs bytes of size 0 whose |
The bytes, |
|
The number of bytes, at most |
|
|
|
Conversion operators |
Static Member Functions
| Name | Description |
|---|---|
The most bytes it holds, |
Friends
| Name | Description |
|---|---|
Whether two values hold the same bytes. |
Template Parameters
| Name | Description |
|---|---|
N |
The most bytes it holds. |
webcpp::codecs::bytes::data
The bytes, N of them, those past size() zero.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
uint8_t const*
data() const noexcept;
webcpp::codecs::bytes::size
The number of bytes, at most N.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
std::size_t
size() const noexcept;
webcpp::codecs::bytes::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/results.hpp>
The first size() bytes, valid while these bytes are.
[[nodiscard]]
constexpr
std::span<uint8_t const>
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
webcpp::codecs::bytes::view
The first size() bytes, valid while these bytes are.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
std::span<uint8_t const>
view() const & noexcept;
webcpp::codecs::bytes::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::bytes::operator std::span<const uint8_t>
Conversion operators
Synopses
Declared in <webcpp/codecs/detail/core/results.hpp>
The first size() bytes; implicit, on an lvalue only (B8).
constexpr
operator std::span<uint8_t const>() const & noexcept;
Deleted on an rvalue: the view would dangle.
operator std::span<uint8_t const>() const && = delete;
Return Value
A view of the bytes.
webcpp::codecs::bytes::operator std::span<uint8_t const>
The first size() bytes; implicit, on an lvalue only (B8).
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
constexpr
operator std::span<uint8_t const>() const & noexcept;
Return Value
A view of the bytes.
webcpp::codecs::bytes::operator std::span<uint8_t const>
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
operator std::span<uint8_t const>() const && = delete;
webcpp::codecs::bytes::capacity
The most bytes it holds, N.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
static
std::size_t
capacity() noexcept;
webcpp::codecs::capacity_t
The tag of a capacity in place of N elements, which a composition takes instead of its default (pipe’s intermediate, drain’s buffer) or of an allocator (buffered, each).
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<std::size_t N>
struct capacity_t;
Static Data Members
| Name | Description |
|---|---|
The capacity, in elements. |
Template Parameters
| Name | Description |
|---|---|
N |
The capacity, in elements. |
webcpp::codecs::capacity_t::value
The capacity, in elements.
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
inline constexpr static
std::size_t value = N;
webcpp::codecs::codec
The conversion of a format between bytes and text: declared by the core, never defined, and specialized by each format’s header for its format’s type.
Description
A specialization has six functions and one constant, every function noexcept, and every public operation of codecs is written over them alone:
template <> struct codec<formats::hex_t> {
// Whether encode and decode run in a time that does not depend on the data.
static constexpr bool constant_time = true;
// A bound on the text of input_size bytes, over every option of the format,
// SIZE_MAX when it does not fit in std::size_t.
static constexpr std::size_t max_encoded_size(std::size_t input_size) noexcept;
// A bound on the bytes of text_size characters, SIZE_MAX when it does not fit.
static constexpr std::size_t max_decoded_size(std::size_t text_size) noexcept;
// The exact size of the text the format writes for input.
static constexpr std::size_t encoded_size(formats::hex_t const& format_value,
std::span<std::uint8_t const> input_bytes) noexcept;
// The exact size of the bytes text decodes to, the whole text checked.
static result<std::size_t> decoded_size(formats::hex_t const& format_value,
std::string_view text_value) noexcept;
static result<std::size_t> encode(formats::hex_t const& format_value,
std::span<std::uint8_t const> input_bytes,
std::span<char> output_buffer) noexcept;
static result<std::size_t> decode(formats::hex_t const& format_value,
std::string_view text_value,
std::span<std::uint8_t> output_buffer) noexcept;
};
The bounds saturate at SIZE_MAX, which means "does not fit": an input whose bound saturates is refused with error::input_too_long before it is read. When a data error is found, the one with the lowest value of error is reported. A size without an error channel (encoded_size here, the core’s codecs::encoded_size, a transformer’s output_size) keeps one rule for an input the encode refuses: SIZE_MAX when it is refused for its size, 0 when it is refused for a fault of the configuration or of the encode.
Three kinds of function are optional. A format whose arithmetic differs when the operation is secret (base58’s) also has overloads of encoded_size, decoded_size, encode or decode that take detail::secret_tag first, which the core calls in a secret operation (ruling R7). A format that has a configuration (a human-readable part, a label, an option) also has the function that checks it:
// The fault of format_value's configuration, std::nullopt when it has none.
static constexpr std::optional<error> configuration_fault(
formats::bech32_t const& format_value) noexcept;
The core calls it first in every form, before any size check and any data, and returns its error unchanged, so that a fault of the configuration wins over every data error; a stream transformer reports it from its first call, whatever it is, and from every call after, and gives its links nothing. The other functions of the codec are called only for a format whose configuration has no fault, and check nothing of it. A codec without the function is of a format that has no configuration. One of another signature (another parameter, another result, not noexcept, not static) stops the build.
A format whose encode refuses an input that its decode has nothing to say of (bech32’s missing human-readable part, its text past the instance’s longest and a word above 31 in words mode, the armor’s missing label) also has the function that finds it, so that a token is never prepared nor a result made for an encode that then fails:
// The fault an encode of input_bytes has, std::nullopt when it has none.
static constexpr std::optional<error> encode_fault(
formats::bech32_t const& format_value, std::span<std::uint8_t const> input_bytes) noexcept;
The core calls it in every encode form after configuration_fault and before its own size check and any prepare, and returns its error unchanged: a fault of the format that its encode alone has thus wins over the size fault whatever the input’s size. It may read the input, of any size: one that reads it checks the size first (bech32 refuses a text past its longest before it reads a word), and one that reads secret bytes does so in constant time, the verdict declassified once. The codec’s encode is then called only for an input without such a fault, and may check it again. One of another signature stops the build, as for configuration_fault.
Each function takes the parameter types written above, which D3 names: std::span<std::uint8_t const> for the bytes read, std::string_view for the text read, std::span<char> and std::span<std::uint8_t> for the output, never a deduced template parameter. The core gives the bytes or the text of an input whose type states its size (std::array, text<N>) as a detail::bounded_bytes<N> or a detail::bounded_text<N>, a view that converts to those types implicitly and noexcept, so that a codec’s noexcept reaches the operation; the view is no range, and a function template that deduced its parameter would get the view and could not read it. over is the one codec that takes the views, to read the bound they state.
Specializations
| Name | Description |
|---|---|
The codec of the armor: its boundaries, and the base64 of the bytes in lines of 64, the payload in constant time. |
|
The codec of hex: two digits a byte, in constant time. |
|
The codec of percent: Boost.URL’s sizes, encode and decode, with its errors as codecs’. |
|
The codec of |
Template Parameters
| Name | Description |
|---|---|
Format |
The format’s type. |
webcpp::codecs::codec<formats::armor_t>
The codec of the armor: its boundaries, and the base64 of the bytes in lines of 64, the payload in constant time.
Static Member Functions
| Name | Description |
|---|---|
The fault of the format’s configuration: a label longer than 64 characters, or outside RFC 7468’s grammar. |
|
Writes the bytes of |
|
The exact size of the bytes of |
|
Writes the armor of |
|
The fault an encode has, which the core asks before its size check and before any token is prepared: a format with no label, |
|
The exact size of the armor of |
|
A bound on the bytes of |
|
A bound on the armor of |
Static Data Members
| Name | Description |
|---|---|
The armor’s payload indexes no table by a data byte and branches on none. |
Friends
| Name | Description |
|---|---|
|
The typed decode of the armor into its parts: the label and the bytes; with no label in the format, any is accepted (R12). It decodes only, and allocates the bytes. |
webcpp::codecs::codec<formats::armor_t>::configuration_fault
The fault of the format’s configuration: a label longer than 64 characters, or outside RFC 7468’s grammar.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
constexpr
static
std::optional<error>
configuration_fault(formats::armor_t const& format_value) noexcept;
Description
A format with none is no fault: it decodes any label.
Parameters
| Name | Description |
|---|---|
format_value |
The format, which is public. |
webcpp::codecs::codec<formats::armor_t>::decode
Writes the bytes of text_characters at the start of output_bytes, after the whole text is found valid.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
static
result<std::size_t>
decode(
formats::armor_t const& format_value,
std::string_view text_characters,
std::span<uint8_t> output_bytes) noexcept;
Return Value
The bytes written, or the text’s fault as decoded_size gives it, else error::output_too_small, with nothing written.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
output_bytes |
The buffer, which must not overlap the text. |
webcpp::codecs::codec<formats::armor_t>::decoded_size
The exact size of the bytes of text_characters, the whole text checked.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
formats::armor_t const& format_value,
std::string_view text_characters) noexcept;
Return Value
The bytes, or the text’s fault as the format’s type says.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
webcpp::codecs::codec<formats::armor_t>::encode
Writes the armor of input_bytes at the start of output_characters.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
static
result<std::size_t>
encode(
formats::armor_t const& format_value,
std::span<uint8_t const> input_bytes,
std::span<char> output_characters) noexcept;
Return Value
The characters written, or error::invalid_prefix for a format with no label, else error::output_too_small, with nothing written.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_bytes |
The bytes. |
output_characters |
The buffer. |
webcpp::codecs::codec<formats::armor_t>::encode_fault
The fault an encode has, which the core asks before its size check and before any token is prepared: a format with no label, error::invalid_prefix, whatever the input’s size.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
constexpr
static
std::optional<error>
encode_fault(
formats::armor_t const& format_value,
std::span<uint8_t const>) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::codec<formats::armor_t>::encoded_size
The exact size of the armor of input_bytes: 0 for a format with no label, which encode refuses for a fault of the encode.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
constexpr
static
std::size_t
encoded_size(
formats::armor_t const& format_value,
std::span<uint8_t const> input_bytes) noexcept;
Return Value
The characters, SIZE_MAX when they do not fit.
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_bytes |
The bytes. |
webcpp::codecs::codec<formats::armor_t>::max_decoded_size
A bound on the bytes of text_size characters: those of as many base64 symbols.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
constexpr
static
std::size_t
max_decoded_size(std::size_t text_size) noexcept;
Return Value
The bytes, which never wrap.
Parameters
| Name | Description |
|---|---|
text_size |
The characters. |
webcpp::codecs::codec<formats::armor_t>::max_encoded_size
A bound on the armor of input_size bytes over every label: the size with a label of 64 characters.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
constexpr
static
std::size_t
max_encoded_size(std::size_t input_size) noexcept;
Return Value
The characters, SIZE_MAX when they do not fit, so that the core refuses the input with error::input_too_long before it reads it.
Parameters
| Name | Description |
|---|---|
input_size |
The bytes. |
webcpp::codecs::codec<formats::armor_t>::constant_time
The armor’s payload indexes no table by a data byte and branches on none.
webcpp::codecs::codec<formats::hex_t>
The codec of hex: two digits a byte, in constant time.
Static Member Functions
| Name | Description |
|---|---|
Writes the bytes of |
|
The exact size of the bytes of |
|
Writes the two digits of each byte of |
|
The exact size of the text of |
|
One byte every two characters. |
|
Two characters a byte. |
Static Data Members
| Name | Description |
|---|---|
hex indexes no table by a data byte and branches on none. |
webcpp::codecs::codec<formats::hex_t>::decode
Writes the bytes of text_characters at the start of output_bytes, after the whole text is found valid; output_bytes may be the text’s own storage.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
static
result<std::size_t>
decode(
formats::hex_t const& format_value,
std::string_view text_characters,
std::span<uint8_t> output_bytes) noexcept;
Return Value
The bytes written, or the text’s error as decoded_size gives it, else error::output_too_small, with nothing written.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
output_bytes |
The buffer. |
webcpp::codecs::codec<formats::hex_t>::decoded_size
The exact size of the bytes of text_characters, every character checked.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
formats::hex_t const& format_value,
std::string_view text_characters) noexcept;
Return Value
The bytes, or error::invalid_character for a character that is no hex digit, else error::invalid_length for an odd length.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
webcpp::codecs::codec<formats::hex_t>::encode
Writes the two digits of each byte of input_bytes at the start of output_characters.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
static
result<std::size_t>
encode(
formats::hex_t const& format_value,
std::span<uint8_t const> input_bytes,
std::span<char> output_characters) noexcept;
Return Value
The characters written, or error::output_too_small, with nothing written, when output_characters cannot hold them.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format, whose case the letters are written in. |
input_bytes |
The bytes. |
output_characters |
The buffer. |
webcpp::codecs::codec<formats::hex_t>::encoded_size
The exact size of the text of input_bytes: two characters a byte.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
constexpr
static
std::size_t
encoded_size(
formats::hex_t const& format_value,
std::span<uint8_t const> input_bytes) noexcept;
Return Value
The characters.
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_bytes |
The bytes. |
webcpp::codecs::codec<formats::hex_t>::max_decoded_size
One byte every two characters.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
constexpr
static
std::size_t
max_decoded_size(std::size_t text_size) noexcept;
Return Value
The most bytes.
Parameters
| Name | Description |
|---|---|
text_size |
The characters. |
webcpp::codecs::codec<formats::hex_t>::max_encoded_size
Two characters a byte.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
constexpr
static
std::size_t
max_encoded_size(std::size_t input_size) noexcept;
Return Value
The characters, SIZE_MAX when they do not fit.
Parameters
| Name | Description |
|---|---|
input_size |
The bytes. |
webcpp::codecs::codec<formats::hex_t>::constant_time
hex indexes no table by a data byte and branches on none.
webcpp::codecs::codec<formats::percent_t>
The codec of percent: Boost.URL’s sizes, encode and decode, with its errors as codecs’.
Static Member Functions
| Name | Description |
|---|---|
Writes the bytes of |
|
The exact size of the bytes of |
|
Writes the text of |
|
The exact size of the text of |
|
One byte a character at most, for a character that is its own byte. |
|
Three characters a byte at most, for an escape. |
Static Data Members
| Name | Description |
|---|---|
percent takes a different time for each byte: it is not constant time. |
webcpp::codecs::codec<formats::percent_t>::decode
Writes the bytes of text_characters at the start of output_bytes, as boost::urls::decode does, after the whole text is found valid.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
static
result<std::size_t>
decode(
formats::percent_t const& format_value,
std::string_view text_characters,
std::span<uint8_t> output_bytes) noexcept;
Return Value
The bytes written, or the text’s error as decoded_size gives it, else error::output_too_small, with nothing written.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
output_bytes |
The buffer, which must not overlap the text. |
webcpp::codecs::codec<formats::percent_t>::decoded_size
The exact size of the bytes of text_characters, as boost::urls::decoded_size gives it.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
formats::percent_t const& format_value,
std::string_view text_characters) noexcept;
Return Value
The bytes, or error::invalid_character for a % followed by a character that is no hex digit, else error::invalid_length for a text that ends inside an escape.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
webcpp::codecs::codec<formats::percent_t>::encode
Writes the text of input_bytes at the start of output_characters, as boost::urls::encode does.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
static
result<std::size_t>
encode(
formats::percent_t const& format_value,
std::span<uint8_t const> input_bytes,
std::span<char> output_characters) noexcept;
Return Value
The characters written, or error::output_too_small, with nothing written, when output_characters cannot hold them.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_bytes |
The bytes. |
output_characters |
The buffer. |
webcpp::codecs::codec<formats::percent_t>::encoded_size
The exact size of the text of input_bytes, as boost::urls::encoded_size gives it.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
static
std::size_t
encoded_size(
formats::percent_t const& format_value,
std::span<uint8_t const> input_bytes) noexcept;
Return Value
The characters.
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_bytes |
The bytes. |
webcpp::codecs::codec<formats::percent_t>::max_decoded_size
One byte a character at most, for a character that is its own byte.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
constexpr
static
std::size_t
max_decoded_size(std::size_t text_size) noexcept;
Return Value
The most bytes.
Parameters
| Name | Description |
|---|---|
text_size |
The characters. |
webcpp::codecs::codec<formats::percent_t>::max_encoded_size
Three characters a byte at most, for an escape.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
constexpr
static
std::size_t
max_encoded_size(std::size_t input_size) noexcept;
Return Value
The characters, SIZE_MAX when they do not fit.
Parameters
| Name | Description |
|---|---|
input_size |
The bytes. |
webcpp::codecs::codec<formats::percent_t>::constant_time
percent takes a different time for each byte: it is not constant time.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
inline constexpr static
bool constant_time = false;
webcpp::codecs::codec<over<Outer, Inner, Allocator>>
The codec of over<Outer, Inner, Allocator> when both links have a codec.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template<
class Outer,
class Inner,
class Allocator>
requires (detail::has_codec<Outer> && detail::has_codec<Inner>)
struct codec<over<Outer, Inner, Allocator>>;
Description
Its bounds compose the links’, its functions run the links through the core’s dispatchers, and its overloads that take detail::secret_tag first run their secret arithmetic and wipe the intermediate (ruling R7). Its configuration_fault is the outer link’s, else the inner link’s, which the core checks before any data, so that the functions run on links whose configurations have no fault. They are noexcept exactly when the intermediate is in place (ruling R3), which is when the view of the input or of the text is a detail::bounded_bytes or a detail::bounded_text, the core’s way to give a codec the bound its input’s type states.
Type Aliases
| Name | Description |
|---|---|
The chain’s format. |
Static Member Functions
| Name | Description |
|---|---|
The fault of the chain’s configuration, which the core checks before any data: the outer link’s, else the inner link’s. |
|
|
|
|
|
|
|
The fault an encode of |
|
|
|
The inner link’s bound on the outer link’s, saturated at |
|
The outer link’s bound on the inner link’s, saturated at |
Static Data Members
| Name | Description |
|---|---|
A chain is constant time when both links are. |
Template Parameters
| Name | Description |
|---|---|
Outer |
The outer link’s type. |
Inner |
The inner link’s type. |
Allocator |
The allocator’s type. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::format_type
The chain’s format.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
using format_type = over<Outer, Inner, Allocator>;
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::configuration_fault
The fault of the chain’s configuration, which the core checks before any data: the outer link’s, else the inner link’s.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
[[nodiscard]]
constexpr
static
std::optional<error>
configuration_fault(format_type const& chain) noexcept;
Return Value
The fault, or std::nullopt when neither link’s configuration has one.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decode
decode overloads
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
Writes the bytes of text_characters into output_bytes.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decode(
format_type const& chain,
View text_characters,
std::span<uint8_t> output_bytes) noexcept(/* see-below */);
Writes the bytes of text_characters into output_bytes, in a secret operation.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decode(
/* implementation-defined */,
format_type const& chain,
View text_characters,
std::span<uint8_t> output_bytes) noexcept(/* see-below */);
Return Value
The number of bytes written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
output_bytes |
The buffer the bytes are written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decode
Writes the bytes of text_characters into output_bytes.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decode(
format_type const& chain,
View text_characters,
std::span<uint8_t> output_bytes) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_decode_is_noexcept<false, Outer, Inner, View>().
Return Value
The number of bytes written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
output_bytes |
The buffer the bytes are written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decode
Writes the bytes of text_characters into output_bytes, in a secret operation.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decode(
/* implementation-defined */,
format_type const& chain,
View text_characters,
std::span<uint8_t> output_bytes) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_decode_is_noexcept<true, Outer, Inner, View>().
Return Value
The number of bytes written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
output_bytes |
The buffer the bytes are written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decoded_size
decoded_size overloads
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
The exact size of the bytes of text_characters, the whole text checked.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
format_type const& chain,
View text_characters) noexcept(/* see-below */);
The exact size of the bytes of text_characters, in a secret operation.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
/* implementation-defined */,
format_type const& chain,
View text_characters) noexcept(/* see-below */);
Return Value
-
The size, or the outer link’s error, else the inner link’s.
-
The size, or the error, as the overload without the tag gives it.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decoded_size
The exact size of the bytes of text_characters, the whole text checked.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
format_type const& chain,
View text_characters) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_decode_is_noexcept<false, Outer, Inner, View>().
Return Value
The size, or the outer link’s error, else the inner link’s.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::decoded_size
The exact size of the bytes of text_characters, in a secret operation.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
decoded_size(
/* implementation-defined */,
format_type const& chain,
View text_characters) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_decode_is_noexcept<true, Outer, Inner, View>().
Return Value
The size, or the error, as the overload without the tag gives it.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
text_characters |
The text. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encode
encode overloads
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
Writes the text of input_view into output_characters.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
encode(
format_type const& chain,
View input_view,
std::span<char> output_characters) noexcept(/* see-below */);
Writes the text of input_view into output_characters, in a secret operation.
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
encode(
/* implementation-defined */,
format_type const& chain,
View input_view,
std::span<char> output_characters) noexcept(/* see-below */);
Return Value
The number of characters written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
output_characters |
The buffer the text is written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encode
Writes the text of input_view into output_characters.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
encode(
format_type const& chain,
View input_view,
std::span<char> output_characters) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_encode_is_noexcept<false, Outer, Inner, View>().
Return Value
The number of characters written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
output_characters |
The buffer the text is written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encode
Writes the text of input_view into output_characters, in a secret operation.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
result<std::size_t>
encode(
/* implementation-defined */,
format_type const& chain,
View input_view,
std::span<char> output_characters) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_encode_is_noexcept<true, Outer, Inner, View>().
Return Value
The number of characters written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
output_characters |
The buffer the text is written to. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encode_fault
The fault an encode of input_bytes has, which the core asks before its size check: the inner link’s, else the outer link’s on the intermediate when that is in place (over.hpp’s encode_probe); a std::span states no bound, so only the inner link’s here.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
[[nodiscard]]
static
std::optional<error>
encode_fault(
format_type const& chain,
std::span<uint8_t const> input_bytes) noexcept;
Description
The core calls encode_probe<over>, which is secret-aware; this function probes with Secret false, so a direct caller with secret bytes must not use it.
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_bytes |
The bytes. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encoded_size
encoded_size overloads
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
The exact size of the text of input_view, the inner link run into the intermediate.
template</* implementation-defined */ View>
[[nodiscard]]
static
std::size_t
encoded_size(
format_type const& chain,
View input_view) noexcept(/* see-below */);
The exact size of the text of input_view, in a secret operation.
template</* implementation-defined */ View>
[[nodiscard]]
static
std::size_t
encoded_size(
/* implementation-defined */,
format_type const& chain,
View input_view) noexcept(/* see-below */);
Return Value
-
The size; for an input a link refuses
SIZE_MAXwhen it is refused for its size, else 0, as for a chain whose configuration is at fault, which no link then sees. -
The size, as the overload without the tag gives it.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encoded_size
The exact size of the text of input_view, the inner link run into the intermediate.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
std::size_t
encoded_size(
format_type const& chain,
View input_view) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_encode_is_noexcept<false, Outer, Inner, View>().
Return Value
The size; for an input a link refuses SIZE_MAX when it is refused for its size, else 0, as for a chain whose configuration is at fault, which no link then sees.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::encoded_size
The exact size of the text of input_view, in a secret operation.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template</* implementation-defined */ View>
[[nodiscard]]
static
std::size_t
encoded_size(
/* implementation-defined */,
format_type const& chain,
View input_view) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::over_encode_is_noexcept<true, Outer, Inner, View>().
Return Value
The size, as the overload without the tag gives it.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
View |
A |
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
input_view |
The bytes. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::max_decoded_size
The inner link’s bound on the outer link’s, saturated at SIZE_MAX.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
constexpr
static
std::size_t
max_decoded_size(std::size_t text_character_count) noexcept;
Return Value
The bound on the bytes, SIZE_MAX when it does not fit.
Parameters
| Name | Description |
|---|---|
text_character_count |
The characters of the text. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::max_encoded_size
The outer link’s bound on the inner link’s, saturated at SIZE_MAX.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
constexpr
static
std::size_t
max_encoded_size(std::size_t input_byte_count) noexcept;
Return Value
The bound on the text, SIZE_MAX when it does not fit.
Parameters
| Name | Description |
|---|---|
input_byte_count |
The bytes of the input. |
webcpp::codecs::codec<over<Outer, Inner, Allocator>>::constant_time
A chain is constant time when both links are.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
inline constexpr static
bool constant_time = codec<Outer>::constant_time && codec<Inner>::constant_time;
webcpp::codecs::each
A stream transformer that converts each input element on its own, as a whole unit, through the one-shot transformer T (D19): a decoded video frame to an image, the stream of frames becoming a stream of images, with nothing accumulated.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
one_shot_transformer T,
class Storage = std::allocator<T::output_type>>
class each;
Description
It is made by codecs::each(transformer), codecs::each(transformer, codecs::capacity<N>) or codecs::each(transformer, allocator).
send accepts one element, the item, which it borrows until the item is delivered ({1, flow::output_pending}). receive transforms the item straight into the caller’s span when T states a static max_output_size(1) and the span has that room, and otherwise into its own storage for one item’s output, which it delivers over as many receives as the caller’s spans need: a short span is never an error. A receive never writes from two items, and completed_items() counts the items fully delivered, so that a caller whose output is bytes sees each item’s boundary. An item’s error is reported by the receive that transforms it, which writes nothing, and every later call returns it until reset. A fault of T’s configuration (a format’s transformer’s, codecs::each(codecs::decoder(formats::bech32(part))) with a bad part) is asked when the stream is made and reported by its first call, whatever it is, and by every call after, also after reset, before any item is read. flush has nothing to gather: it returns flow::output_pending while an item is pending and flow::finished once the last item is received.
With codecs::capacity<N>, the storage holds N elements in place, which requires T to state max_output_size(1) as a constant expression no larger than N (a static_assert names the fix otherwise), and nothing is allocated; every member is noexcept when T’s transform and the copy of its output elements are. With an allocator, the only form for a T with no constant bound, the storage comes from it, rebound through std::allocator_traits, and grows as an item needs: to T’s exact output_size(input) when it states one, else to its static max_output_size(1), else by doubling while transform reports output_too_small. A bound of the object’s own (a non-static max_output_size, as a configured format’s may be) is not read, and such a T is sized by doubling, up to the most the allocator holds. reset keeps that memory. Construction allocates nothing; receive may allocate and is not noexcept, and an allocator’s exception propagates: a receive that throws leaves the item pending, and the stream valid and resettable.
It is constant time when T is. A move takes the item, its output and the state, and leaves the moved-from each in the state reset leaves, so that it converts a new input from the start; the item stays the caller’s, and a move never carries a borrow away from it. The moved-from stream still calls its T, which the move left as T’s own move leaves it, so it converts anew only when a moved-from T still transforms (a requirement of one_shot_transformer).
It is secret when T is (codecs::is_secret_v, D21): then it is move-only, each of its calls, reset included, holds an engaged secure::timing_guard, which nests with T’s own, and its item storage, whose elements must then be trivially copyable, is wiped by secure::erase_secret on reset, on destruction, in the moved-from stream on a move, in the stream a move assigns to before it takes the other’s, and, from an allocator, before the memory it outgrows goes back.
Type Aliases
| Name | Description |
|---|---|
The elements read: |
|
The elements written: |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
The items fully delivered since the stream started or was reset. |
|
Ends the input: there is nothing to gather. |
|
The allocator of the item storage: the heap form alone. |
|
Writes the item’s output into |
|
Returns to |
|
Accepts the first element of |
Static Data Members
| Name | Description |
|---|---|
The stream runs in a time that does not depend on its data when |
Deduction Guides
| Name | Description |
|---|---|
Deduces |
|
Deduces |
|
Deduces |
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer. |
Storage |
|
webcpp::codecs::each::each
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
A copy borrows the item other borrows; a secret stream is not copyable (D21).
Takes other’s transformer, item, output and state, and leaves other as reset does.
Makes a stream of transformer, in flow::needs_input, with a default Storage.
explicit
each(T transformer) noexcept(/* see-below */);
Makes a stream of transformer, in flow::needs_input.
each(
T transformer,
Storage const& storage) noexcept(nothrow_construction);
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
transformer |
The one-shot transformer. |
storage |
|
webcpp::codecs::each::each
A copy borrows the item other borrows; a secret stream is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
each(each const& other)
requires (!secret) = default;
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::each::each
Takes other’s transformer, item, output and state, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
each(each&& other) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_constructible_v<output_storage>.
Parameters
| Name | Description |
|---|---|
other |
The stream moved from. |
webcpp::codecs::each::each
Makes a stream of transformer, in flow::needs_input, with a default Storage.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
explicit
each(T transformer) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless nothrow_construction && std::is_nothrow_default_constructible_v<Storage>.
Parameters
| Name | Description |
|---|---|
transformer |
The one-shot transformer. |
webcpp::codecs::each::each
Makes a stream of transformer, in flow::needs_input.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
each(
T transformer,
Storage const& storage) noexcept(nothrow_construction);
Parameters
| Name | Description |
|---|---|
transformer |
The one-shot transformer. |
storage |
|
webcpp::codecs::each::~each
Destructors
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Destroys the transformer and the storage, wiped first: a secret stream’s.
~each()
requires secret;
Destroys the transformer and the storage; a public stream wipes nothing.
~each() = default;
webcpp::codecs::each::~each
Destroys the transformer and the storage, wiped first: a secret stream’s.
webcpp::codecs::each::~each
Destroys the transformer and the storage; a public stream wipes nothing.
webcpp::codecs::each::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/adapters.hpp>
A copy borrows the item other borrows; a secret stream is not copyable (D21).
Takes other’s transformer, item, output and state, and leaves other as reset does.
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::each::operator=
A copy borrows the item other borrows; a secret stream is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream copied. |
webcpp::codecs::each::operator=
Takes other’s transformer, item, output and state, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_assignable_v<output_storage>.
Return Value
This stream.
Parameters
| Name | Description |
|---|---|
other |
The stream moved from. |
webcpp::codecs::each::completed_items
The items fully delivered since the stream started or was reset.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
std::size_t
completed_items() const noexcept;
Return Value
The count of items whose output was received whole.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::each::flush
Ends the input: there is nothing to gather.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<flow>
flush() noexcept;
Return Value
flow::output_pending while an item is pending, flow::finished when none is, or the stream’s error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::each::get_allocator
The allocator of the item storage: the heap form alone.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
Storage
get_allocator() const noexcept
requires (!in_place);
webcpp::codecs::each::receive
Writes the item’s output into output: transformed straight into it when it has room for T’s bound, else through the storage, delivered over as many receives as it takes.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<step>
receive(std::span<output_type> output) noexcept(nothrow_receive);
Return Value
The elements written and the state after, or the stream’s error, which the receive that transforms the item reports, writing nothing.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::each::reset
Returns to flow::needs_input with no item, no error and a count of zero; the allocated storage is kept for the next stream, wiped when the stream is secret.
webcpp::codecs::each::send
Accepts the first element of input as the item in flow::needs_input; accepts nothing in another state, or from an empty span.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
[[nodiscard]]
result<step>
send(std::span<input_type const> input) noexcept;
Return Value
{1, flow::output_pending}, {0, state}, or the stream’s error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The elements to convert, the first borrowed until it is delivered. |
webcpp::codecs::each::constant_time
The stream runs in a time that does not depend on its data when T does.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
inline constexpr static
bool constant_time = is_constant_time_v<T>;
webcpp::codecs::fixed_byte_storage
Lets a library’s fixed type be the target of a typed decode.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<class T>
struct fixed_byte_storage;
Description
A specialization has static constexpr std::size_t size and static std::span<std::uint8_t, size> writable(T&) noexcept, and the decode fills exactly size bytes. Declared by the core, never defined.
Specializations
| Name | Description |
|---|---|
|
Template Parameters
| Name | Description |
|---|---|
T |
The library’s fixed type. |
webcpp::codecs::fixed_byte_storage<secure::secret<N>>
secure::secret<N> is the target of a typed decode of exactly N bytes, written through its writable() (owner decision 14).
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<std::size_t N>
struct fixed_byte_storage<secure::secret<N>>;
Static Member Functions
| Name | Description |
|---|---|
The storage of |
Static Data Members
| Name | Description |
|---|---|
The bytes a decode fills. |
Template Parameters
| Name | Description |
|---|---|
N |
The size of the secret. |
webcpp::codecs::fixed_byte_storage<secure::secret<N>>::writable
The storage of target_secret, which the decode fills.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
[[nodiscard]]
static
std::span<uint8_t, N>
writable(secure::secret<N>& target_secret) noexcept;
Parameters
| Name | Description |
|---|---|
target_secret |
The secret decoded into. |
webcpp::codecs::fixed_byte_storage<secure::secret<N>>::size
The bytes a decode fills.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
inline constexpr static
std::size_t size = N;
webcpp::codecs::format_decoder
The transformer of a format’s decoding, text to bytes (D20): a one-shot transformer always, and a stream transformer when the format’s header specializes stream_codec.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
class Format,
stream_options Options>
class format_decoder;
Description
It is made by codecs::decoder(format).
transform(input, output) is the buffer form of codecs::decode: a text whose bytes do not fit in std::size_t is error::input_too_long, then the whole text is checked and its data error with the lowest value returned, then an output shorter than the exact size is error::output_too_small, all with nothing written, and then codec<Format>::decode writes the bytes at the start of output. max_output_size is codec<Format>::max_decoded_size and output_size(input) its decoded_size, 0 for a text it refuses. With Options.secret the format’s secret arithmetic runs where it has one (ruling R7).
The stream members, send, receive, flush and reset, exist when stream_codec<Format> is specialized and forward to its decoder<Options>, which keeps the protocol (D18) and its error rules; human_readable_part() and label() exist when that decoder has them (B39). A fault of the format’s configuration comes first in every form, as for format_encoder, so that transform returns it, output_size is 0, and the stream calls return it from the first, whatever it is, and from every call after, also after reset, giving the stream decoder nothing (B23). A move copies the format and moves the stream state, so that the moved-from decoder converts a new input from the start (Review Focus 5). A format whose stream is a pipe, over, adds a precondition: the decoder is not moved between a receive that reports flow::output_pending and the next call that reports flow::needs_input or flow::finished, unless it has reported an error, since its second link then borrows the pipe’s intermediate (piped). It is copyable when the stream state is and the decoder is public.
With Options.secret, made by codecs::decoder(format, codecs::secret_operation), it is secret (codecs::is_secret_v, D21): it is move-only, each of its calls, transform, output_size and the four stream calls, holds an engaged secure::timing_guard, which nests with the guards of a composition that holds it, and the stream decoder wipes its own pending state (its carries, its error mask, its hold) on reset, on destruction and in the moved-from decoder.
It is constant time when codec<Format> is, and noexcept in every call but the ones that allocate (over’s decode with a heap intermediate, owner decision 24).
Type Aliases
| Name | Description |
|---|---|
The characters the decoder reads. |
|
The bytes the decoder writes. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destroys the decoder. |
Assignment operators |
|
Ends the stream’s input. |
|
The human-readable part the stream read, after a successful |
|
The label the stream read, after a successful |
|
The exact size of the bytes |
|
Writes the stream’s bytes into |
|
Returns the stream to |
|
Gives |
|
Writes the bytes of |
Static Member Functions
| Name | Description |
|---|---|
A bound on the bytes of |
Static Data Members
| Name | Description |
|---|---|
The decoder runs in a time that does not depend on its data when the format’s codec does. |
Template Parameters
| Name | Description |
|---|---|
Format |
The format’s type, which has a |
Options |
The stream’s options. |
webcpp::codecs::format_decoder::input_type
The characters the decoder reads.
webcpp::codecs::format_decoder::output_type
The bytes the decoder writes.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
using output_type = uint8_t;
webcpp::codecs::format_decoder::format_decoder
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
Copies other’s format and stream state, when the stream state is copyable; a secret decoder is not copyable (D21).
format_decoder(format_decoder const& other)
requires (!secret) = default;
Copies other’s format and takes its stream state, which leaves other as reset does.
format_decoder(format_decoder&& other) noexcept(nothrow_move);
Makes the decoder of format_value, in flow::needs_input.
explicit
format_decoder(Format format_value) noexcept(/* see-below */);
Parameters
| Name | Description |
|---|---|
other |
The decoder copied. |
format_value |
The format. |
webcpp::codecs::format_decoder::format_decoder
Copies other’s format and stream state, when the stream state is copyable; a secret decoder is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_decoder(format_decoder const& other)
requires (!secret) = default;
Parameters
| Name | Description |
|---|---|
other |
The decoder copied. |
webcpp::codecs::format_decoder::format_decoder
Copies other’s format and takes its stream state, which leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_decoder(format_decoder&& other) noexcept(nothrow_move);
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from, which keeps its format. |
webcpp::codecs::format_decoder::format_decoder
Makes the decoder of format_value, in flow::needs_input.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
explicit
format_decoder(Format format_value) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_constructible_v<Format> && std::is_nothrow_constructible_v<stream_type, const Format &>.
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::format_decoder::~format_decoder
Destroys the decoder.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
~format_decoder() = default;
webcpp::codecs::format_decoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
Copies other’s format and stream state, when the stream state is copyable; a secret decoder is not copyable (D21).
format_decoder&
operator=(format_decoder const& other)
requires (!secret) = default;
Copies other’s format and takes its stream state, which leaves other as reset does.
format_decoder&
operator=(format_decoder&& other) noexcept(nothrow_move_assignment);
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder copied. |
webcpp::codecs::format_decoder::operator=
Copies other’s format and stream state, when the stream state is copyable; a secret decoder is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_decoder&
operator=(format_decoder const& other)
requires (!secret) = default;
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder copied. |
webcpp::codecs::format_decoder::operator=
Copies other’s format and takes its stream state, which leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_decoder&
operator=(format_decoder&& other) noexcept(nothrow_move_assignment);
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from, which keeps its format. |
webcpp::codecs::format_decoder::flush
Ends the stream’s input.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<flow>
flush() noexcept(nothrow_stream)
requires streams;
Return Value
flow::output_pending while bytes remain, flow::finished when none do, or the error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::format_decoder::human_readable_part
The human-readable part the stream read, after a successful flush, as the stream decoder gives it (B39).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
decltype(auto)
human_readable_part() const noexcept(/* see-below */)
requires detail::gives_human_readable_part<stream_type>;
Exception specification
This function is potentially-throwing unless detail::nothrow_human_readable_part<stream_type>.
Return Value
The stream decoder’s human-readable part.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::format_decoder::label
The label the stream read, after a successful flush, as the stream decoder gives it (B39).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
decltype(auto)
label() const noexcept(detail::nothrow_label<stream_type>)
requires detail::gives_label<stream_type>;
webcpp::codecs::format_decoder::output_size
The exact size of the bytes transform writes for input: codec<Format>::decoded_size, or 0 for a text transform refuses, which writes nothing: a fault of the format’s configuration, a text whose bytes do not fit, or a text of a data error.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
std::size_t
output_size(std::span<char const> input) const noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::codec_decoded_size_is_noexcept<Options.secret, Format, std::string_view>().
Parameters
| Name | Description |
|---|---|
input |
The text. |
webcpp::codecs::format_decoder::receive
Writes the stream’s bytes into output.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<step>
receive(std::span<uint8_t> output) noexcept(nothrow_stream)
requires streams;
Return Value
The bytes written and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::format_decoder::reset
Returns the stream to flow::needs_input, with nothing borrowed or pending and no error; a fault of the format’s configuration stays, as the format does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
void
reset() noexcept
requires streams;
webcpp::codecs::format_decoder::send
Gives input to the stream decoder, which borrows it as the protocol says; returns the fault of the format’s configuration instead, when it has one.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<step>
send(std::span<char const> input) noexcept(nothrow_stream)
requires streams;
Return Value
The characters accepted and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The characters to decode. |
webcpp::codecs::format_decoder::transform
Writes the bytes of input at the start of output, or nothing and the error.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<std::size_t>
transform(
std::span<char const> input,
std::span<uint8_t> output) const noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::decode_calls_are_noexcept<Format, std::string_view, Options.secret>().
Parameters
| Name | Description |
|---|---|
input |
The text. |
output |
The buffer the bytes are written to. |
webcpp::codecs::format_decoder::max_output_size
A bound on the bytes of input_size characters: codec<Format>::max_decoded_size.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
constexpr
static
std::size_t
max_output_size(std::size_t input_size) noexcept;
Return Value
The bound, SIZE_MAX when it does not fit.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input_size |
The characters of a text. |
webcpp::codecs::format_decoder::constant_time
The decoder runs in a time that does not depend on its data when the format’s codec does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
inline constexpr static
bool constant_time = codec<Format>::constant_time;
webcpp::codecs::format_encoder
The transformer of a format’s encoding, bytes to text (D20): a one-shot transformer always, and a stream transformer when the format’s header specializes stream_codec.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
class Format,
stream_options Options>
class format_encoder;
Description
It is made by codecs::encoder(format).
transform(input, output) is the buffer form of codecs::encode: a fault of the encode (its codec’s encode_fault), an input whose encoding does not fit in std::size_t (error::input_too_long) and an output shorter than the exact size (error::output_too_small), all with nothing written, and then codec<Format>::encode writes the text at the start of output. max_output_size is codec<Format>::max_encoded_size and output_size(input) its encoded_size, which buffered and each read: SIZE_MAX for an input refused for its size, 0 for one refused for a fault of the configuration or of the encode. With Options.secret the format’s secret arithmetic runs where it has one (ruling R7), so that codecs::buffered(codecs::encoder(format, codecs::secret_operation)) runs it at flush.
The stream members, send, receive, flush and reset, exist when stream_codec<Format> is specialized and forward to its encoder<Options>, which keeps the protocol (D18) and its error rules. A fault of the format’s configuration (its codec’s configuration_fault, asked when the encoder is made) comes first in every form: transform returns it, output_size is 0, and send, receive and flush return it from the first call, whatever it is, and from every call after, also after reset, giving the stream encoder nothing (B23). A move copies the format and moves the stream state, whose own move leaves the moved-from state as reset does, so that the moved-from encoder converts a new input from the start (Review Focus 5). A format whose stream is a pipe, over, adds a precondition: the encoder is not moved between a receive that reports flow::output_pending and the next call that reports flow::needs_input or flow::finished, unless it has reported an error, since its second link then borrows the pipe’s intermediate (piped). It is copyable when the stream state is and the encoder is public.
With Options.secret, made by codecs::encoder(format, codecs::secret_operation), it is secret (codecs::is_secret_v, D21): it is move-only, each of its calls, transform, output_size and the four stream calls, holds an engaged secure::timing_guard, which nests with the guards of a composition that holds it, and the stream encoder wipes its own pending state on reset, on destruction and in the moved-from encoder.
It is constant time when codec<Format> is, and noexcept in every call but the ones that allocate (over’s encode with a heap intermediate, owner decision 24).
Type Aliases
| Name | Description |
|---|---|
The bytes the encoder reads. |
|
The characters the encoder writes. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destroys the encoder. |
Assignment operators |
|
Ends the stream’s input. |
|
The exact size of the text |
|
Writes the stream’s text into |
|
Returns the stream to |
|
Gives |
|
Writes the text of |
Static Member Functions
| Name | Description |
|---|---|
A bound on the characters of |
Static Data Members
| Name | Description |
|---|---|
The encoder runs in a time that does not depend on its data when the format’s codec does. |
Template Parameters
| Name | Description |
|---|---|
Format |
The format’s type, which has a |
Options |
The stream’s options. |
webcpp::codecs::format_encoder::input_type
The bytes the encoder reads.
webcpp::codecs::format_encoder::output_type
The characters the encoder writes.
webcpp::codecs::format_encoder::format_encoder
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
Copies other’s format and stream state, when the stream state is copyable; a secret encoder is not copyable (D21).
format_encoder(format_encoder const& other)
requires (!secret) = default;
Copies other’s format and takes its stream state, which leaves other as reset does.
format_encoder(format_encoder&& other) noexcept(nothrow_move);
Makes the encoder of format_value, in flow::needs_input.
explicit
format_encoder(Format format_value) noexcept(/* see-below */);
Parameters
| Name | Description |
|---|---|
other |
The encoder copied. |
format_value |
The format. |
webcpp::codecs::format_encoder::format_encoder
Copies other’s format and stream state, when the stream state is copyable; a secret encoder is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_encoder(format_encoder const& other)
requires (!secret) = default;
Parameters
| Name | Description |
|---|---|
other |
The encoder copied. |
webcpp::codecs::format_encoder::format_encoder
Copies other’s format and takes its stream state, which leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_encoder(format_encoder&& other) noexcept(nothrow_move);
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from, which keeps its format. |
webcpp::codecs::format_encoder::format_encoder
Makes the encoder of format_value, in flow::needs_input.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
explicit
format_encoder(Format format_value) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_constructible_v<Format> && std::is_nothrow_constructible_v<stream_type, const Format &>.
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::format_encoder::~format_encoder
Destroys the encoder.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
~format_encoder() = default;
webcpp::codecs::format_encoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
Copies other’s format and stream state, when the stream state is copyable; a secret encoder is not copyable (D21).
format_encoder&
operator=(format_encoder const& other)
requires (!secret) = default;
Copies other’s format and takes its stream state, which leaves other as reset does.
format_encoder&
operator=(format_encoder&& other) noexcept(nothrow_move_assignment);
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder copied. |
webcpp::codecs::format_encoder::operator=
Copies other’s format and stream state, when the stream state is copyable; a secret encoder is not copyable (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_encoder&
operator=(format_encoder const& other)
requires (!secret) = default;
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder copied. |
webcpp::codecs::format_encoder::operator=
Copies other’s format and takes its stream state, which leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
format_encoder&
operator=(format_encoder&& other) noexcept(nothrow_move_assignment);
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from, which keeps its format. |
webcpp::codecs::format_encoder::flush
Ends the stream’s input.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<flow>
flush() noexcept(nothrow_stream)
requires streams;
Return Value
flow::output_pending while text remains, flow::finished when none does, or the error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::format_encoder::output_size
The exact size of the text transform writes for input: codec<Format>::encoded_size, with the one rule of every size for an input transform refuses before it writes: SIZE_MAX for an input refused for its size (its encoding does not fit, bech32’s text past its longest), 0 for one refused for a fault of the format’s configuration or of the encode (its codec’s encode_fault).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
std::size_t
output_size(std::span<uint8_t const> input) const noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::codec_encoded_size_is_noexcept<Options.secret, Format, std::span<const std::uint8_t>>().
Return Value
The characters, SIZE_MAX or 0 for a refused input.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The bytes. |
webcpp::codecs::format_encoder::receive
Writes the stream’s text into output.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<step>
receive(std::span<char> output) noexcept(nothrow_stream)
requires streams;
Return Value
The characters written and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::format_encoder::reset
Returns the stream to flow::needs_input, with nothing borrowed or pending and no error; a fault of the format’s configuration stays, as the format does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
void
reset() noexcept
requires streams;
webcpp::codecs::format_encoder::send
Gives input to the stream encoder, which borrows it as the protocol says; returns the fault of the format’s configuration instead, when it has one.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<step>
send(std::span<uint8_t const> input) noexcept(nothrow_stream)
requires streams;
Return Value
The bytes accepted and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The bytes to encode. |
webcpp::codecs::format_encoder::transform
Writes the text of input at the start of output, or nothing and the error.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
result<std::size_t>
transform(
std::span<uint8_t const> input,
std::span<char> output) const noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::encode_calls_are_noexcept<Format, std::span<const std::uint8_t>, Options.secret>().
Parameters
| Name | Description |
|---|---|
input |
The bytes. |
output |
The buffer the text is written to. |
webcpp::codecs::format_encoder::max_output_size
A bound on the characters of input_size bytes: codec<Format>::max_encoded_size.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
[[nodiscard]]
constexpr
static
std::size_t
max_output_size(std::size_t input_size) noexcept;
Return Value
The bound, SIZE_MAX when it does not fit.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input_size |
The bytes of an input. |
webcpp::codecs::format_encoder::constant_time
The encoder runs in a time that does not depend on its data when the format’s codec does.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
inline constexpr static
bool constant_time = codec<Format>::constant_time;
webcpp::codecs::format_list
A list of formats, by type: what a value_formats declaration states, and what a refusal of a format the type does not have prints, in its failed requirement’s template arguments.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<class... Formats>
struct format_list;
Template Parameters
| Name | Description |
|---|---|
Formats |
The formats’ types. |
webcpp::codecs::is_secret
Whether values of T are secret: false unless a library specializes it for its secret types, which makes every operation on such a value secret (D10).
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<class T>
struct is_secret
: std::false_type
Description
codecs specializes it for secure::secret<N>, for its own secret results, and for its transformers, which are secret when made with codecs::secret_operation or of a secret part (D21). A specialization derives from std::true_type, or from std::bool_constant where the type is secret by its parameters, as a pipe is by its parts.
Base Classes
| Name | Description |
|---|---|
|
Specializations
| Name | Description |
|---|---|
Secret bytes on the heap are secret, whatever their allocator. |
|
A secret string on the heap is secret, whatever its allocator. |
|
secure’s secret is secret. |
|
The bytes of a secret decoding are secret. |
|
The text of a secret encoding is secret. |
|
|
|
|
|
A format’s decoder is secret when its options say so, |
|
A format’s encoder is secret when its options say so, |
|
A pipe is secret when either of its parts, |
Template Parameters
| Name | Description |
|---|---|
T |
The type, cv-unqualified and not a reference. |
webcpp::codecs::is_secret<basic_secret_byte_vector<Allocator>>
Secret bytes on the heap are secret, whatever their allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<class Allocator>
struct is_secret<basic_secret_byte_vector<Allocator>>
: std::true_type
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<basic_secret_string<Allocator>>
A secret string on the heap is secret, whatever its allocator.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<class Allocator>
struct is_secret<basic_secret_string<Allocator>>
: std::true_type
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<secure::secret<N>>
secure’s secret is secret.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<std::size_t N>
struct is_secret<secure::secret<N>>
: std::true_type
Base Classes
| Name | Description |
|---|---|
|
Template Parameters
| Name | Description |
|---|---|
N |
The size of the secret. |
webcpp::codecs::is_secret<secret_bytes<N>>
The bytes of a secret decoding are secret.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<std::size_t N>
struct is_secret<secret_bytes<N>>
: std::true_type
Base Classes
| Name | Description |
|---|---|
|
Template Parameters
| Name | Description |
|---|---|
N |
The most bytes they hold. |
webcpp::codecs::is_secret<secret_text<N>>
The text of a secret encoding is secret.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<std::size_t N>
struct is_secret<secret_text<N>>
: std::true_type
Base Classes
| Name | Description |
|---|---|
|
Template Parameters
| Name | Description |
|---|---|
N |
The most characters it holds. |
webcpp::codecs::is_secret<buffered<T, Storage>>
buffered is secret when its transformer T is (D21), whatever its storage.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
one_shot_transformer T,
class Storage>
struct is_secret<buffered<T, Storage>>
: std::bool_constant<is_secret_v<T>>
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<each<T, Storage>>
each is secret when its transformer T is (D21), whatever its storage.
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
one_shot_transformer T,
class Storage>
struct is_secret<each<T, Storage>>
: std::bool_constant<is_secret_v<T>>
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<format_decoder<Format, Options>>
A format’s decoder is secret when its options say so, Options.secret, as codecs::decoder(format, codecs::secret_operation) makes it (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
class Format,
stream_options Options>
struct is_secret<format_decoder<Format, Options>>
: std::bool_constant<Options.secret>
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<format_encoder<Format, Options>>
A format’s encoder is secret when its options say so, Options.secret, as codecs::encoder(format, codecs::secret_operation) makes it (D21).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
class Format,
stream_options Options>
struct is_secret<format_encoder<Format, Options>>
: std::bool_constant<Options.secret>
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::is_secret<piped<First, Second, Capacity>>
A pipe is secret when either of its parts, First or Second, is (D21), whatever the capacity of its intermediate.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
stream_transformer First,
stream_transformer Second,
std::size_t Capacity>
struct is_secret<piped<First, Second, Capacity>>
: std::bool_constant<is_secret_v<First> || is_secret_v<Second>>
Base Classes
| Name | Description |
|---|---|
|
webcpp::codecs::over
The composition of two formats: encoding encodes with inner and then encodes that output with outer, decoding decodes with outer and then decodes that output with inner.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
Description
Outer is a format with a codec (text feeds it as bytes); Inner is a format with a codec, or one a value_codec converts a value in. Both are constrained by the concept format: a value codec’s format is copyable and has a name as every format has. over is a format whose name is the name of the outer link, then the characters " over ", then the name of the inner link, and class template argument deduction builds it from the two links, with or without the allocator as a third argument. A chain is constant time when both links are, and secret when any link’s operation is: the core runs the links’ secret overloads (ruling R7) and the intermediate is wiped by secure::erase_secret, in place or before its allocator gets it back.
The intermediate, the bytes between the links, is held in place when its bound is known at compile time, which is when the input’s type states its size (std::array, std::span of a static extent, secure::secret, text<N>, bytes<N>), the value codec of an encode states max_encoded_size, or the value codec of a decode states its decode bound, max_decode_input_size, of at most 4096 bytes (detail::in_place_scratch_limit, owner decision 30), the smaller bound then held; it is otherwise made with allocator, which is used for nothing else, so that over<Outer, Inner> allocates through std::allocator. A decode of a value refuses an intermediate longer than the inner value codec’s decode bound with error::input_too_long before it is made, after the outer link’s own error, as a direct decode refuses that input (owner decision 29): nothing is written, allocated or wiped; so a value codec with a bound of at most 4096 bytes is decoded from a std::string_view with no heap, and one with a bound above it from the allocator, of exactly the written size. over’s own value codec states no decode bound (design R8): a link may decode a text longer than the longest it writes, so in a chain of chains only the level whose inner link is that value codec holds its intermediate in place for a text of a dynamic size. The exact encoded_size and decoded_size run the inner link into the intermediate (ruling R3): with a heap intermediate they allocate, so those, encode and decode are not noexcept and an exception of the allocator reaches the caller, the buffer forms of the core among them (the one allocating buffer form), and with a bound known at compile time they are noexcept and allocate nothing. A fault of a link’s configuration is the chain’s, the outer link’s first: every form reports it before it reads any data, in either link. A fault of a link’s encode (its codec’s encode_fault) is the chain’s too, before the core’s size check and any token’s prepare: the inner link’s always, and the outer link’s on the intermediate when that is in place; with a heap intermediate the outer link’s is found by its encode, after prepare (detail::encode_probe). Its transformers, encoder(chain) and decoder(chain), stream through a pipe of the links’ streams when both links stream natively (format_transformer.hpp).
An intermediate in place is held for every bound an input’s static size or an encoded bound gives, with no cap, so that over with a static bound allocates nothing, as the spec’s Allocation requirement says; a decode bound is held in place up to the cap alone. Its cost is the stack: an array of the middle bound (the inner link’s bound on the input’s size for an encode, the smaller of the outer link’s bound on the text’s size and the decode bound for a decode) in the frame of each of over’s functions, one for each level of a chain of chains. A caller with a large input of a static size who wants the intermediate on the heap passes it as a view of a dynamic extent (std::span<std::uint8_t const>, std::string_view), whose intermediate comes from allocator unless a decode bound of at most 4096 bytes holds it in place; the allocator of a result or a token is not the intermediate’s.
Member Functions
Data Members
Static Data Members
| Name | Description |
|---|---|
The name: the outer link’s, " over ", and the inner link’s. |
Deduction Guides
| Name | Description |
|---|---|
Deduces |
|
Deduces |
Template Parameters
| Name | Description |
|---|---|
Outer |
The format that writes the final text and reads it first. |
Inner |
The format whose bytes the outer link encodes and decodes. |
Allocator |
The allocator of the heap intermediate. |
webcpp::codecs::over::over
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
A copy of a chain: the links and the allocator, noexcept when their copies are.
A move of a chain: the links and the allocator, noexcept when their moves are.
Makes a chain of the two links and the allocator of its heap intermediate.
constexpr
over(
Outer outer_link,
Inner inner_link,
Allocator const& allocator_value = Allocator{}) noexcept(/* see-below */);
Parameters
| Name | Description |
|---|---|
outer_link |
The outer link. |
inner_link |
The inner link. |
allocator_value |
The allocator of the heap intermediate. |
webcpp::codecs::over::over
A copy of a chain: the links and the allocator, noexcept when their copies are.
webcpp::codecs::over::over
A move of a chain: the links and the allocator, noexcept when their moves are.
webcpp::codecs::over::over
Makes a chain of the two links and the allocator of its heap intermediate.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
constexpr
over(
Outer outer_link,
Inner inner_link,
Allocator const& allocator_value = Allocator{}) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_constructible_v<Outer> && std::is_nothrow_move_constructible_v<Inner> && std::is_nothrow_copy_constructible_v<Allocator>.
Parameters
| Name | Description |
|---|---|
outer_link |
The outer link. |
inner_link |
The inner link. |
allocator_value |
The allocator of the heap intermediate. |
webcpp::codecs::over::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/over.hpp>
Takes the links and the allocator of other.
Takes the links and the allocator of other, as the copy assignment does.
Return Value
This chain.
Parameters
| Name | Description |
|---|---|
other |
The chain to copy. |
webcpp::codecs::over::operator=
Takes the links and the allocator of other.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
Description
An allocator that cannot be assigned, as std::pmr::polymorphic_allocator, is made again from other’s: a chain is a value, whatever its allocator, and a format is copyable.
Exception specification
This function is potentially-throwing unless std::is_nothrow_copy_assignable_v<Outer> && std::is_nothrow_copy_assignable_v<Inner> && nothrow_take_allocator<const Allocator &>.
Return Value
This chain.
Parameters
| Name | Description |
|---|---|
other |
The chain to copy. |
webcpp::codecs::over::operator=
Takes the links and the allocator of other, as the copy assignment does.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
Exception specification
This function is potentially-throwing unless std::is_nothrow_move_assignable_v<Outer> && std::is_nothrow_move_assignable_v<Inner> && nothrow_take_allocator<Allocator &&>.
Return Value
This chain.
Parameters
| Name | Description |
|---|---|
other |
The chain to take. |
webcpp::codecs::over::name
The name: the outer link’s, " over ", and the inner link’s.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
inline constexpr static
std::string_view name = detail::over_name<Outer, Inner>::value;
webcpp::codecs::piped
A stream transformer that sends its input through First and then through Second, holding the elements between them in an intermediate of Capacity elements in place (D19).
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
stream_transformer First,
stream_transformer Second,
std::size_t Capacity>
class piped;
Description
It is made by pipe.
send gives the input to First, which borrows it as the protocol says. receive moves First’s output into the intermediate, sends it to Second, which borrows it until it reports flow::needs_input, and receives Second’s output into the caller’s span, as long as the span has room. flush flushes First, and Second once First is finished and Second has taken the whole intermediate. reset resets both. The first error of either part is the pipe’s, and every later call returns it until reset; a receive that has already written output when it meets the error returns that output, and the next call returns the error, so that a call that reports an error writes nothing.
The pipe allocates nothing. It is constant time when both parts are, and each call is noexcept when the parts’ calls are. It is not copyable: Second may borrow its intermediate. A move takes the parts and the intermediate’s elements that Second has not taken, and leaves the moved-from pipe in the state reset leaves, so that it converts a new input from the start. Between a receive that reports flow::output_pending and the next call that reports flow::needs_input or flow::finished, Second may still borrow the intermediate, which a move would carry away from it: the pipe must not be moved in that window, unless the pipe has reported an error (it calls Second no more until reset).
The pipe is secret when either part is (codecs::is_secret_v, D21): then each of its calls, reset included, holds an engaged secure::timing_guard, which nests with its parts’ own, and its intermediate, whose elements must then be trivially copyable, is wiped by secure::erase_secret on reset, on destruction, in the moved-from pipe on a move (after the check that Second does not borrow it) and in the pipe a move assigns to before it takes the other’s elements; each part wipes its own state.
Type Aliases
| Name | Description |
|---|---|
The elements the pipe reads: |
|
The elements the pipe writes: |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input: flushes |
|
Writes |
|
Resets both parts and returns to |
|
Gives |
Static Data Members
| Name | Description |
|---|---|
The pipe runs in a time that does not depend on its data when both parts do. |
Derived Classes
Template Parameters
| Name | Description |
|---|---|
First |
The first transformer, whose input is the pipe’s. |
Second |
The second transformer, whose output is the pipe’s. |
Capacity |
The intermediate’s elements, at least one. |
webcpp::codecs::piped::piped
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/pipe.hpp>
Not copyable: Second may borrow the intermediate.
Takes other’s parts, state and the intermediate’s elements that Second has not taken, and leaves other as reset does.
Makes a pipe of first and then second, in flow::needs_input; both are reset, so that the pipe starts with nothing borrowed or pending.
piped(
First first,
Second second) noexcept(detail::nothrow_movable_v<First, Second>);
Parameters
| Name | Description |
|---|---|
other |
The pipe moved from. |
first |
The first transformer. |
second |
The second transformer. |
webcpp::codecs::piped::piped
Takes other’s parts, state and the intermediate’s elements that Second has not taken, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
piped(piped&& other) noexcept(nothrow_moves);
Description
other’s Second must not borrow its intermediate, unless other has reported an error.
Parameters
| Name | Description |
|---|---|
other |
The pipe moved from. |
webcpp::codecs::piped::piped
Makes a pipe of first and then second, in flow::needs_input; both are reset, so that the pipe starts with nothing borrowed or pending.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
piped(
First first,
Second second) noexcept(detail::nothrow_movable_v<First, Second>);
Parameters
| Name | Description |
|---|---|
first |
The first transformer. |
second |
The second transformer. |
webcpp::codecs::piped::~piped
Destructors
Synopses
Declared in <webcpp/codecs/detail/core/pipe.hpp>
Destroys both parts, the intermediate wiped first: a secret pipe’s.
~piped()
requires secret;
Destroys both parts; a public pipe wipes nothing, and is trivially destructible when they are.
~piped() = default;
webcpp::codecs::piped::~piped
Destroys both parts; a public pipe wipes nothing, and is trivially destructible when they are.
webcpp::codecs::piped::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/pipe.hpp>
Not copyable: Second may borrow the intermediate.
Takes other’s parts, state and the intermediate’s elements that Second has not taken, and leaves other as reset does.
Return Value
This pipe.
Parameters
| Name | Description |
|---|---|
other |
The pipe moved from. |
webcpp::codecs::piped::operator=
Takes other’s parts, state and the intermediate’s elements that Second has not taken, and leaves other as reset does.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
Description
other’s Second must not borrow its intermediate, unless other has reported an error.
Return Value
This pipe.
Parameters
| Name | Description |
|---|---|
other |
The pipe moved from. |
webcpp::codecs::piped::flush
Ends the input: flushes First, and Second once First is finished and Second has taken the whole intermediate.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
[[nodiscard]]
result<flow>
flush() noexcept(nothrow_calls);
Return Value
flow::output_pending while output remains, flow::finished when none does, or the pipe’s error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::piped::receive
Writes Second’s output into output, moving First’s output through the intermediate as long as output has room.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
[[nodiscard]]
result<step>
receive(std::span<output_type> output) noexcept(nothrow_calls);
Return Value
The elements written and the state after, or the pipe’s error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::piped::reset
Resets both parts and returns to flow::needs_input, with nothing pending and no error; the intermediate is wiped when the pipe is secret.
webcpp::codecs::piped::send
Gives input to First in flow::needs_input; accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
[[nodiscard]]
result<step>
send(std::span<input_type const> input) noexcept(nothrow_calls);
Return Value
The elements accepted and the state after, or the pipe’s error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The elements to convert, borrowed as |
webcpp::codecs::piped::constant_time
The pipe runs in a time that does not depend on its data when both parts do.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
inline constexpr static
bool constant_time = is_constant_time_v<First> && is_constant_time_v<Second>;
webcpp::codecs::secret_bytes
The bytes of a secret decoding that fit N bytes: the bytes in place, and a size.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
template<std::size_t N>
class secret_bytes;
Description
It is move-only: a copy is asked for by name, with clone(). Its bytes are wiped by secure::erase_secret when it is destroyed and, the source’s, when it is moved from; moved-from bytes are empty. It has no operator==, whose time would tell where two secrets differ. The bytes past size() are zero. The wipe covers the object’s own storage only: a move or a clone may leave copies of the bytes in registers or temporaries, which the library does not reach.
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Wipes the bytes. |
Assignment operators |
|
A copy of the bytes, which the caller then owns. |
|
The bytes, |
|
The number of bytes, at most |
|
|
Static Member Functions
| Name | Description |
|---|---|
The most bytes it holds, |
Template Parameters
| Name | Description |
|---|---|
N |
The most bytes it holds. |
webcpp::codecs::secret_bytes::secret_bytes
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Constructs bytes of size 0 whose N bytes are zero.
secret_bytes() noexcept = default;
Not copyable: a copy is asked for by name, with clone.
secret_bytes(secret_bytes const&) = delete;
Takes the bytes of moved_bytes, which are wiped and left empty.
secret_bytes(secret_bytes&& moved_bytes) noexcept;
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::secret_bytes::secret_bytes
Constructs bytes of size 0 whose N bytes are zero.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_bytes() noexcept = default;
webcpp::codecs::secret_bytes::secret_bytes
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_bytes(secret_bytes const&) = delete;
webcpp::codecs::secret_bytes::secret_bytes
Takes the bytes of moved_bytes, which are wiped and left empty.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_bytes(secret_bytes&& moved_bytes) noexcept;
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::secret_bytes::~secret_bytes
Wipes the bytes.
webcpp::codecs::secret_bytes::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Not copyable: a copy is asked for by name, with clone.
secret_bytes&
operator=(secret_bytes const&) = delete;
Wipes these bytes, then takes those of moved_bytes, which are wiped and left empty; a move to itself changes nothing.
secret_bytes&
operator=(secret_bytes&& moved_bytes) noexcept;
Return Value
These bytes.
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::secret_bytes::operator=
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_bytes&
operator=(secret_bytes const&) = delete;
webcpp::codecs::secret_bytes::operator=
Wipes these bytes, then takes those of moved_bytes, which are wiped and left empty; a move to itself changes nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_bytes&
operator=(secret_bytes&& moved_bytes) noexcept;
Return Value
These bytes.
Parameters
| Name | Description |
|---|---|
moved_bytes |
The bytes to take. |
webcpp::codecs::secret_bytes::clone
A copy of the bytes, which the caller then owns.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
secret_bytes
clone() const noexcept;
webcpp::codecs::secret_bytes::data
The bytes, N of them, those past size() zero.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
uint8_t const*
data() const noexcept;
webcpp::codecs::secret_bytes::size
The number of bytes, at most N.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
size() const noexcept;
webcpp::codecs::secret_bytes::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The first size() bytes, valid while these bytes are.
[[nodiscard]]
std::span<uint8_t const>
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
webcpp::codecs::secret_bytes::view
The first size() bytes, valid while these bytes are.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::span<uint8_t const>
view() const & noexcept;
webcpp::codecs::secret_bytes::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::span<uint8_t const>
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::secret_bytes::capacity
The most bytes it holds, N.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
constexpr
static
std::size_t
capacity() noexcept;
webcpp::codecs::secret_operation_t
The tag that makes a transformer of a format secret: encoder(format, secret_operation).
Member Functions
| Name | Description |
|---|---|
|
Constructed by name only, so that |
webcpp::codecs::secret_operation_t::secret_operation_t
Constructed by name only, so that {} never stands for it.
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
constexpr
explicit
secret_operation_t() = default;
webcpp::codecs::secret_text
The text of a secret encoding that fits N characters: the characters in place, and a size.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
template<std::size_t N>
class secret_text;
Description
It is move-only: a copy is asked for by name, with clone(). Its characters are wiped by secure::erase_secret when it is destroyed and, the source’s, when it is moved from; a moved-from text is empty. It has no operator==, whose time would tell where two secrets differ. The characters past size() are zero. The wipe covers the object’s own storage only: a move or a clone may leave copies of the characters in registers or temporaries, which the library does not reach.
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Wipes the characters. |
Assignment operators |
|
A copy of the characters, which the caller then owns. |
|
The characters, |
|
The number of characters, at most |
|
|
Static Member Functions
| Name | Description |
|---|---|
The most characters it holds, |
Template Parameters
| Name | Description |
|---|---|
N |
The most characters it holds. |
webcpp::codecs::secret_text::secret_text
Constructors
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Constructs a text of size 0 whose N characters are zero.
secret_text() noexcept = default;
Not copyable: a copy is asked for by name, with clone.
secret_text(secret_text const&) = delete;
Takes the characters of moved_text, which is wiped and left empty.
secret_text(secret_text&& moved_text) noexcept;
Parameters
| Name | Description |
|---|---|
moved_text |
The text to take the characters of. |
webcpp::codecs::secret_text::secret_text
Constructs a text of size 0 whose N characters are zero.
webcpp::codecs::secret_text::secret_text
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_text(secret_text const&) = delete;
webcpp::codecs::secret_text::secret_text
Takes the characters of moved_text, which is wiped and left empty.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_text(secret_text&& moved_text) noexcept;
Parameters
| Name | Description |
|---|---|
moved_text |
The text to take the characters of. |
webcpp::codecs::secret_text::~secret_text
Wipes the characters.
webcpp::codecs::secret_text::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Not copyable: a copy is asked for by name, with clone.
secret_text&
operator=(secret_text const&) = delete;
Wipes these characters, then takes those of moved_text, which is wiped and left empty; a move to itself changes nothing.
secret_text&
operator=(secret_text&& moved_text) noexcept;
Return Value
This text.
Parameters
| Name | Description |
|---|---|
moved_text |
The text to take the characters of. |
webcpp::codecs::secret_text::operator=
Not copyable: a copy is asked for by name, with clone.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_text&
operator=(secret_text const&) = delete;
webcpp::codecs::secret_text::operator=
Wipes these characters, then takes those of moved_text, which is wiped and left empty; a move to itself changes nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
secret_text&
operator=(secret_text&& moved_text) noexcept;
Return Value
This text.
Parameters
| Name | Description |
|---|---|
moved_text |
The text to take the characters of. |
webcpp::codecs::secret_text::clone
A copy of the characters, which the caller then owns.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
secret_text
clone() const noexcept;
webcpp::codecs::secret_text::data
The characters, N of them, those past size() zero.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
char const*
data() const noexcept;
webcpp::codecs::secret_text::size
The number of characters, at most N.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::size_t
size() const noexcept;
webcpp::codecs::secret_text::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
The first size() characters, valid while this text is.
[[nodiscard]]
std::string_view
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::string_view
view() const && = delete;
webcpp::codecs::secret_text::view
The first size() characters, valid while this text is.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::string_view
view() const & noexcept;
webcpp::codecs::secret_text::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
std::string_view
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::secret_text::capacity
The most characters it holds, N.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
[[nodiscard]]
constexpr
static
std::size_t
capacity() noexcept;
webcpp::codecs::step
What a stream transformer’s send or receive did: a count of elements and the state after.
webcpp::codecs::stream_codec
The stream conversion of a format between bytes and text: declared by the core, never defined, and specialized by a format’s header when the format streams natively, as codec is (D20).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<class Format>
struct stream_codec;
Description
A specialization has two class templates over the stream’s options:
template <> struct stream_codec<formats::hex_t> {
template <stream_options Options> class encoder; // std::uint8_t to char
template <stream_options Options> class decoder; // char to std::uint8_t
};
Each is a stream_transformer constructed from the format’s value (formats::hex_t const&), with input_type and output_type as written above and every call noexcept. It keeps the format’s minimal pending state and nothing else, and reads the caller’s input and writes the caller’s output as the protocol says (D18). A fault of the format’s configuration is not the stream codec’s to find: the transformer asks the codec’s configuration_fault when it is made and reports the fault from its first call, whatever it is, and from every call after, never calling the stream codec’s encoder or decoder, which may be made from such a format and check nothing of it. The error rules every stream codec keeps (D18, B23, B44): a fault of the data is reported once, after flush, by the first call that has processed the whole input (flush itself when nothing is still borrowed, otherwise the receive that reaches the end), and it is the error the one-shot form reports for the same whole input; that call writes nothing, the verdict running over everything still borrowed before the tail is written; after an error every call returns it until reset. A moved-from encoder or decoder is in the state reset leaves.
With Options.secret (D21) the stream codec’s encoder and decoder wipe their own pending state (the carries, the error mask, a hold) by secure::erase_secret on reset, on destruction and in the moved-from object on a move, and need not be copyable; the core’s class holds the engaged secure::timing_guard around each of their calls, is move-only, and runs the format’s secret arithmetic in its one-shot form (ruling R7).
A decoder that holds its input until its verdict (bech32’s) declares static constexpr bool holds = true and holds Options.capacity elements, or its default when it is 0; decoder(format, codecs::capacity<N>) of any other format stops the build. The stream codec may publish static constexpr std::size_t maximum_hold, the longest hold: a larger N stops the build before the decoder type is named (a format without it has no limit). A decoder that gives a part of its input after a successful flush has human_readable_part() or label(), which format_decoder forwards (B39).
Specializations
| Name | Description |
|---|---|
The stream codec of the armor (D20): an encoder that writes the BEGIN boundary with the first input, the base64 lines as it goes and the END boundary at |
|
The stream codec of hex (D20): an encoder that holds one character of a pair its output had no room for, and a decoder that holds one digit of a pair and the error mask, each in constant time. |
|
The stream codec of percent (D20): an encoder that holds up to two characters of an escape its output had no room for, and a decoder that holds the escape it has read so far and the fault it found. Each applies the format’s set and options byte by byte, which Boost.URL has no stream function for. |
|
The stream of |
Template Parameters
| Name | Description |
|---|---|
Format |
The format’s type. |
webcpp::codecs::stream_codec<formats::armor_t>
The stream codec of the armor (D20): an encoder that writes the BEGIN boundary with the first input, the base64 lines as it goes and the END boundary at flush, and a decoder that reads the BEGIN line, the payload as it comes, and the END boundary at flush, the payload in constant time.
Types
| Name | Description |
|---|---|
The stream decoder: the BEGIN line read as it comes, the payload’s bytes written straight into the caller’s span as its characters leave a window of the last 82 characters, and at |
|
The stream encoder: the BEGIN boundary, then four characters a group of three borrowed bytes and a line feed every 64, written straight into the caller’s span; |
webcpp::codecs::stream_codec<formats::armor_t>::decoder
The stream decoder: the BEGIN line read as it comes, the payload’s bytes written straight into the caller’s span as its characters leave a window of the last 82 characters, and at flush the END boundary taken from the window, its payload read and the last line checked.
Description
It holds the BEGIN line (public), the window (which may hold symbols), base64’s bits of a group and the masks, and the third and fourth bytes of a group until the group is known not to be the last, as base64’s padded decoder does; which bytes it delivers it decides from public facts alone. Every fault is reported after flush by the call that reads the end of the input, which runs the verdict over everything still borrowed before it writes, as the one-shot form reports it (B44). The bytes delivered before flush may come from a text that later fails that verdict: a caller discards what was delivered when the stream reports an error. The label read is label() after a successful flush. With Options.secret it is move-only and wipes the window, the masks, base64’s state and the held and waiting bytes by secure::erase_secret on reset, on destruction and in the moved-from decoder.
Type Aliases
| Name | Description |
|---|---|
The characters read. |
|
The bytes written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself. |
|
The label the BEGIN line held, after a successful |
|
Reads the borrowed characters, writing the bytes they give as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::input_type
The characters read.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::output_type
The bytes written.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::decoder
Constructors
Synopses
Declared in <webcpp/codecs/armor.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
A decoder in flow::needs_input, which accepts the label of format_value, or any when it has none.
explicit
decoder(formats::armor_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::decoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
decoder(decoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::armor_t>::decoder::decoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::decoder
A decoder in flow::needs_input, which accepts the label of format_value, or any when it has none.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
explicit
decoder(formats::armor_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::~decoder
Destructors
Synopses
Declared in <webcpp/codecs/armor.hpp>
Wipes the window, the masks and the held and waiting bytes of a secret stream.
~decoder()
requires wipes;
A public stream wipes nothing.
~decoder() = default;
webcpp::codecs::stream_codec<formats::armor_t>::decoder::~decoder
Wipes the window, the masks and the held and waiting bytes of a secret stream.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::~decoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/armor.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
Return Value
This decoder.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::flush
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself.
Return Value
flow::output_pending while bytes remain, else flow::finished, or the error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::label
The label the BEGIN line held, after a successful flush.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
std::string_view
label() const noexcept;
Return Value
A view of it, valid until the next reset of this decoder; empty before a successful flush.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::receive
Reads the borrowed characters, writing the bytes they give as output has room; after flush, the window’s payload and the held bytes of the last group too.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
result<step>
receive(std::span<uint8_t> output) noexcept;
Description
After flush, the first call runs the verdict over what is still borrowed and returns its error, writing nothing.
Return Value
The bytes written and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::reset
Back to flow::needs_input, nothing borrowed, the verdict and the error forgotten; the window, the masks and the held and waiting bytes of a secret stream wiped.
webcpp::codecs::stream_codec<formats::armor_t>::decoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
result<step>
send(std::span<char const> input) noexcept;
Return Value
The characters accepted and the state after, or the error found after flush.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The characters to decode. |
webcpp::codecs::stream_codec<formats::armor_t>::decoder::wipes
Whether the stream wipes its pending state: it is secret.
webcpp::codecs::stream_codec<formats::armor_t>::encoder
The stream encoder: the BEGIN boundary, then four characters a group of three borrowed bytes and a line feed every 64, written straight into the caller’s span; flush completes the last group, with its padding, the last line and the END boundary.
Description
The BEGIN boundary is written with the first input, or at flush. It holds up to two bytes of a group and the characters of a group its output had no room for. A format with no label is refused by every call with error::invalid_prefix, also after reset; it has no other fault. With Options.secret it is move-only and wipes the waiting bytes and characters by secure::erase_secret on reset, on destruction and in the moved-from encoder.
Type Aliases
| Name | Description |
|---|---|
The bytes read. |
|
The characters written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input: bytes have no fault for the armor to find. |
|
Writes the characters the input gives, as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::input_type
The bytes read.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::output_type
The characters written.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::encoder
Constructors
Synopses
Declared in <webcpp/codecs/armor.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
An encoder in flow::needs_input, writing the label of format_value.
explicit
encoder(formats::armor_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::encoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
encoder(encoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::armor_t>::encoder::encoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::encoder
An encoder in flow::needs_input, writing the label of format_value.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
explicit
encoder(formats::armor_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::~encoder
Destructors
Synopses
Declared in <webcpp/codecs/armor.hpp>
Wipes the waiting bytes and characters of a secret stream.
~encoder()
requires wipes;
A public stream wipes nothing.
~encoder() = default;
webcpp::codecs::stream_codec<formats::armor_t>::encoder::~encoder
Wipes the waiting bytes and characters of a secret stream.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::~encoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/armor.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
Return Value
This encoder.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::flush
Ends the input: bytes have no fault for the armor to find.
Return Value
flow::output_pending while characters remain, else flow::finished, or error::invalid_prefix for a format with no label.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::receive
Writes the characters the input gives, as output has room; after flush, the last group, the last line and the END boundary too.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
result<step>
receive(std::span<char> output) noexcept;
Return Value
The characters written and the state after, or error::invalid_prefix for a format with no label.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::reset
Back to flow::needs_input, nothing borrowed or pending; the waiting bytes and characters of a secret stream wiped.
Description
The label stays, as the format does.
webcpp::codecs::stream_codec<formats::armor_t>::encoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
result<step>
send(std::span<uint8_t const> input) noexcept;
Return Value
The bytes accepted and the state after, or error::invalid_prefix for a format with no label.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The bytes to encode. |
webcpp::codecs::stream_codec<formats::armor_t>::encoder::wipes
Whether the stream wipes its pending state: it is secret.
webcpp::codecs::stream_codec<formats::hex_t>
The stream codec of hex (D20): an encoder that holds one character of a pair its output had no room for, and a decoder that holds one digit of a pair and the error mask, each in constant time.
webcpp::codecs::stream_codec<formats::hex_t>::decoder
The stream decoder: a byte for each pair of digits, written straight into the caller’s span.
Description
The first digit of a pair whose second is not borrowed yet is held. Every digit’s verdict is accumulated in a mask, and reported after flush by the call that reads the end of the input, which runs it over everything still borrowed before it writes, as the one-shot form reports it (B44): error::invalid_character, else error::invalid_length. The bytes delivered before flush may come from pairs that later fail that verdict (the error is reported after flush so that the time does not depend on where the text is invalid): a caller discards what was delivered when the stream reports an error. For "0g12", two bytes are delivered and flush then reports error::invalid_character. With Options.secret it is move-only and wipes the held digit and the error mask by secure::erase_secret on reset, on destruction and in the moved-from decoder.
Type Aliases
| Name | Description |
|---|---|
The digits read. |
|
The bytes written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself. |
|
Writes a byte for each pair of digits, as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::input_type
The digits read.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::output_type
The bytes written.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::decoder
Constructors
Synopses
Declared in <webcpp/codecs/hex.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
A decoder in flow::needs_input; it reads either case, whatever the format’s.
explicit
decoder(formats::hex_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::decoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
decoder(decoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::hex_t>::decoder::decoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::decoder
A decoder in flow::needs_input; it reads either case, whatever the format’s.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
explicit
decoder(formats::hex_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::~decoder
Destructors
Synopses
Declared in <webcpp/codecs/hex.hpp>
Wipes the held digit and the error mask of a secret stream.
~decoder()
requires wipes;
A public stream wipes nothing.
~decoder() = default;
webcpp::codecs::stream_codec<formats::hex_t>::decoder::~decoder
Wipes the held digit and the error mask of a secret stream.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::~decoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/hex.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
Return Value
This decoder.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::flush
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself.
Return Value
flow::output_pending while bytes remain, else flow::finished, or the error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::receive
Writes a byte for each pair of digits, as output has room.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
result<step>
receive(std::span<uint8_t> output) noexcept;
Description
After flush, the first call runs the verdict over what is still borrowed and returns its error, writing nothing.
Return Value
The bytes written and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::reset
Back to flow::needs_input, nothing borrowed or held, the verdict and the error forgotten; the held digit and the error mask of a secret stream wiped.
webcpp::codecs::stream_codec<formats::hex_t>::decoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state; a lone digit is held at once, which frees the input.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
result<step>
send(std::span<char const> input) noexcept;
Return Value
The digits accepted and the state after, or the error found after flush.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The digits to decode. |
webcpp::codecs::stream_codec<formats::hex_t>::decoder::wipes
Whether the stream wipes its pending state: it is secret.
webcpp::codecs::stream_codec<formats::hex_t>::encoder
The stream encoder: two digits a borrowed byte, written straight into the caller’s span.
Description
The low digit of a byte whose high digit filled the span waits for the next receive. It never fails. With Options.secret it is move-only and wipes the waiting digit by secure::erase_secret on reset, on destruction and in the moved-from encoder.
Type Aliases
| Name | Description |
|---|---|
The bytes read. |
|
The digits written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input: hex has no fault of the data to find in bytes. |
|
Writes the waiting digit, then two digits a borrowed byte, as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::input_type
The bytes read.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::output_type
The digits written.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::encoder
Constructors
Synopses
Declared in <webcpp/codecs/hex.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
An encoder in flow::needs_input, writing the case of format_value.
explicit
encoder(formats::hex_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::encoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
encoder(encoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::hex_t>::encoder::encoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::encoder
An encoder in flow::needs_input, writing the case of format_value.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
explicit
encoder(formats::hex_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::~encoder
Destructors
Synopses
Declared in <webcpp/codecs/hex.hpp>
Wipes the waiting digit of a secret stream.
~encoder()
requires wipes;
A public stream wipes nothing.
~encoder() = default;
webcpp::codecs::stream_codec<formats::hex_t>::encoder::~encoder
Wipes the waiting digit of a secret stream.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::~encoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/hex.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
Return Value
This encoder.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::flush
Ends the input: hex has no fault of the data to find in bytes.
Return Value
flow::output_pending while digits remain, else flow::finished.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::receive
Writes the waiting digit, then two digits a borrowed byte, as output has room.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
result<step>
receive(std::span<char> output) noexcept;
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::reset
Back to flow::needs_input, nothing borrowed or pending; the waiting digit of a secret stream wiped.
webcpp::codecs::stream_codec<formats::hex_t>::encoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/hex.hpp>
[[nodiscard]]
result<step>
send(std::span<uint8_t const> input) noexcept;
Parameters
| Name | Description |
|---|---|
input |
The bytes to encode. |
webcpp::codecs::stream_codec<formats::hex_t>::encoder::wipes
Whether the stream wipes its pending state: it is secret.
webcpp::codecs::stream_codec<formats::percent_t>
The stream codec of percent (D20): an encoder that holds up to two characters of an escape its output had no room for, and a decoder that holds the escape it has read so far and the fault it found. Each applies the format’s set and options byte by byte, which Boost.URL has no stream function for.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
template<>
struct stream_codec<formats::percent_t>;
webcpp::codecs::stream_codec<formats::percent_t>::decoder
The stream decoder: a byte for each character that is its own and each escape, written straight into the caller’s span.
Description
The % and the first digit of an escape whose second digit is not borrowed yet are held. The fault of the text is kept, and reported after flush by the call that reads the end of the input, which runs it over everything still borrowed before it writes, as the one-shot form reports it (B44): error::invalid_character for a % followed by a character that is no hex digit, else error::invalid_length for a text that ends inside an escape. The bytes delivered before flush may come from a text that later fails: a caller discards what was delivered when the stream reports an error. Once a fault is known, nothing more is delivered: what was delivered is always the bytes of a valid text’s prefix. For "a%g", one byte is delivered and flush then reports error::invalid_character; for "%g41", none is. With Options.secret it is move-only and wipes the held escape and the fault by secure::erase_secret on reset, on destruction and in the moved-from decoder.
Type Aliases
| Name | Description |
|---|---|
The characters read. |
|
The bytes written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself. |
|
Writes a byte for each character that is its own and each escape, as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::input_type
The characters read.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::output_type
The bytes written.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::decoder
Constructors
Synopses
Declared in <webcpp/codecs/percent.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
A decoder in flow::needs_input, reading a plus sign as a space as the format’s options say.
explicit
decoder(formats::percent_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::decoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
decoder(decoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::percent_t>::decoder::decoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::decoder
A decoder in flow::needs_input, reading a plus sign as a space as the format’s options say.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
explicit
decoder(formats::percent_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::~decoder
Destructors
Synopses
Declared in <webcpp/codecs/percent.hpp>
Wipes the held escape and the fault of a secret stream.
~decoder()
requires wipes;
A public stream wipes nothing.
~decoder() = default;
webcpp::codecs::stream_codec<formats::percent_t>::decoder::~decoder
Wipes the held escape and the fault of a secret stream.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::~decoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/percent.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
Return Value
This decoder.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This decoder.
Parameters
| Name | Description |
|---|---|
other |
The decoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::flush
Ends the input; with nothing borrowed, it runs the verdict and reports its error itself.
Return Value
flow::output_pending while bytes remain, else flow::finished, or the error.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::receive
Writes a byte for each character that is its own and each escape, as output has room.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
result<step>
receive(std::span<uint8_t> output) noexcept;
Description
After flush, the first call runs the verdict over what is still borrowed and returns its error, writing nothing.
Return Value
The bytes written and the state after, or the error.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::reset
Back to flow::needs_input, nothing borrowed or held, the verdict and the error forgotten; the held escape and the fault of a secret stream wiped.
webcpp::codecs::stream_codec<formats::percent_t>::decoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state; the characters that write nothing, a % and a first digit, are held at once.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
result<step>
send(std::span<char const> input) noexcept;
Return Value
The characters accepted and the state after, or the error found after flush.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
input |
The characters to decode. |
webcpp::codecs::stream_codec<formats::percent_t>::decoder::wipes
Whether the stream wipes its pending state: it is secret.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
inline constexpr static
bool wipes = Options.secret;
webcpp::codecs::stream_codec<formats::percent_t>::encoder
The stream encoder: a character or an escape a borrowed byte, written straight into the caller’s span.
Description
The characters of an escape that the span had no room for, one or two, wait for the next receive. It never fails. With Options.secret it is move-only and wipes the waiting characters by secure::erase_secret on reset, on destruction and in the moved-from encoder.
Type Aliases
| Name | Description |
|---|---|
The bytes read. |
|
The characters written. |
Member Functions
| Name | Description |
|---|---|
|
Constructors |
|
Destructors |
Assignment operators |
|
Ends the input: percent has no fault of the data to find in bytes. |
|
Writes the waiting characters, then the character or the escape of each borrowed byte, as |
|
Back to |
|
Borrows all of |
Static Data Members
| Name | Description |
|---|---|
Whether the stream wipes its pending state: it is secret. |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::input_type
The bytes read.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::output_type
The characters written.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::encoder
Constructors
Synopses
Declared in <webcpp/codecs/percent.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
An encoder in flow::needs_input, leaving the characters of format_value as they are.
explicit
encoder(formats::percent_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
format_value |
The format. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::encoder
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
encoder(encoder const&) noexcept
requires (!Options.secret) = default;
webcpp::codecs::stream_codec<formats::percent_t>::encoder::encoder
Takes other’s state and leaves other as reset does.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::encoder
An encoder in flow::needs_input, leaving the characters of format_value as they are.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
explicit
encoder(formats::percent_t const& format_value) noexcept;
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::~encoder
Destructors
Synopses
Declared in <webcpp/codecs/percent.hpp>
Wipes the waiting characters of a secret stream.
~encoder()
requires wipes;
A public stream wipes nothing.
~encoder() = default;
webcpp::codecs::stream_codec<formats::percent_t>::encoder::~encoder
Wipes the waiting characters of a secret stream.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::~encoder
A public stream wipes nothing.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::operator=
Assignment operators
Synopses
Declared in <webcpp/codecs/percent.hpp>
A copy of the state, borrowing what the other borrows; a secret stream has none.
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::operator=
A copy of the state, borrowing what the other borrows; a secret stream has none.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
Return Value
This encoder.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::operator=
Takes other’s state and leaves other as reset does.
Return Value
This encoder.
Parameters
| Name | Description |
|---|---|
other |
The encoder moved from. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::flush
Ends the input: percent has no fault of the data to find in bytes.
Return Value
flow::output_pending while characters remain, else flow::finished.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::receive
Writes the waiting characters, then the character or the escape of each borrowed byte, as output has room.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
result<step>
receive(std::span<char> output) noexcept;
Return Value
The characters written and the state after.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
output |
The span to write into. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::reset
Back to flow::needs_input, nothing borrowed or pending; the waiting characters of a secret stream wiped.
webcpp::codecs::stream_codec<formats::percent_t>::encoder::send
Borrows all of input in flow::needs_input, and accepts nothing in another state.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
[[nodiscard]]
result<step>
send(std::span<uint8_t const> input) noexcept;
Parameters
| Name | Description |
|---|---|
input |
The bytes to encode. |
webcpp::codecs::stream_codec<formats::percent_t>::encoder::wipes
Whether the stream wipes its pending state: it is secret.
Synopsis
Declared in <webcpp/codecs/percent.hpp>
inline constexpr static
bool wipes = Options.secret;
webcpp::codecs::stream_codec<over<Outer, Inner, Allocator>>
The stream of over<Outer, Inner, Allocator> when both links stream natively: the encoder is a pipe of the inner link’s encoder and then the outer link’s, the decoder a pipe of the outer link’s decoder and then the inner link’s, each with an intermediate in place of the default capacity (D11, B43).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
class Outer,
class Inner,
class Allocator>
requires (detail::has_stream_codec<Outer> && detail::has_stream_codec<Inner>)
struct stream_codec<over<Outer, Inner, Allocator>>;
Description
A fault of a link’s configuration, the outer link’s first, is the chain’s own (its codec’s configuration_fault): the chain’s transformer reports it from its first call and never calls the pipe, so that it comes before any data of either link. The pipe’s rules are the stream’s: the first error of either link is the chain’s, a call that reports it writes nothing, and a move leaves the moved-from stream as reset does; the chain’s stream must not be moved while the second link borrows the intermediate, between a receive that reports flow::output_pending and the next call that reports flow::needs_input or flow::finished, unless it has reported an error (piped).
Types
Template Parameters
| Name | Description |
|---|---|
Outer |
The outer link’s type. |
Inner |
The inner link’s type. |
Allocator |
The allocator’s type, which the stream does not use. |
webcpp::codecs::stream_codec<over<Outer, Inner, Allocator>>::decoder
The chain’s stream decoder: the outer link’s decoder, then the inner link’s.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<stream_options Options>
class decoder
: public piped<format_decoder<Outer, Options>, format_decoder<Inner, Options>, default_capacity_v<std::uint8_t>>
Base Classes
| Name | Description |
|---|---|
A stream transformer that sends its input through |
Member Functions
| Name | Description |
|---|---|
|
Makes the pipe of the decoders of |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options, which both links take. |
webcpp::codecs::stream_codec<over<Outer, Inner, Allocator>>::decoder::decoder
Makes the pipe of the decoders of chain’s links.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
explicit
decoder(over<Outer, Inner, Allocator> const& chain) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_constructible_v<format_decoder<Outer, Options>, const Outer &> && std::is_nothrow_constructible_v<format_decoder<Inner, Options>, const Inner &> && std::is_nothrow_constructible_v<links, format_decoder<Outer, Options>, format_decoder<Inner, Options>>.
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
webcpp::codecs::stream_codec<over<Outer, Inner, Allocator>>::encoder
The chain’s stream encoder: the inner link’s encoder, then the outer link’s.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<stream_options Options>
class encoder
: public piped<format_encoder<Inner, Options>, format_encoder<Outer, Options>, default_capacity_v<char>>
Base Classes
| Name | Description |
|---|---|
|
A stream transformer that sends its input through |
Member Functions
| Name | Description |
|---|---|
|
Makes the pipe of the encoders of |
Template Parameters
| Name | Description |
|---|---|
Options |
The stream’s options, which both links take. |
webcpp::codecs::stream_codec<over<Outer, Inner, Allocator>>::encoder::encoder
Makes the pipe of the encoders of chain’s links.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
explicit
encoder(over<Outer, Inner, Allocator> const& chain) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless std::is_nothrow_constructible_v<format_encoder<Inner, Options>, const Inner &> && std::is_nothrow_constructible_v<format_encoder<Outer, Options>, const Outer &> && std::is_nothrow_constructible_v<links, format_encoder<Inner, Options>, format_encoder<Outer, Options>>.
Parameters
| Name | Description |
|---|---|
chain |
The chain. |
webcpp::codecs::stream_options
The options of a format’s stream transformer, a structural type that stream_codec’s encoder and decoder templates take (B37).
Description
encoder(format, codecs::secret_operation) and decoder(format, codecs::secret_operation) set secret; decoder(format, codecs::capacity<N>) sets capacity, the hold of a decoder that holds its input (bech32’s, in characters, B47), which is 1 or more: codecs::capacity<0> stops the build, as 0 here is the decoder’s default.
webcpp::codecs::stream_options::capacity
The hold of a decoder that holds its input; 0 for the decoder’s default.
webcpp::codecs::stream_options::secret
Whether the stream is secret: its state wiped, its calls under secure’s timing guard.
webcpp::codecs::text
The fixed text result: N characters in place and a size (defined in results.hpp).
Member Functions
| Name | Description |
|---|---|
|
Constructs a text of size 0 whose |
The characters, |
|
The number of characters, at most |
|
|
|
Conversion operators |
Static Member Functions
| Name | Description |
|---|---|
The most characters it holds, |
Friends
| Name | Description |
|---|---|
Whether two texts hold the same characters. |
Template Parameters
| Name | Description |
|---|---|
N |
The most characters it holds. |
webcpp::codecs::text::data
The characters, N of them, those past size() zero.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
char const*
data() const noexcept;
webcpp::codecs::text::size
The number of characters, at most N.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
std::size_t
size() const noexcept;
webcpp::codecs::text::view
view overloads
Synopses
Declared in <webcpp/codecs/detail/core/results.hpp>
The first size() characters, valid while this text is.
[[nodiscard]]
constexpr
std::string_view
view() const & noexcept;
Deleted on an rvalue: the view would dangle.
[[nodiscard]]
std::string_view
view() const && = delete;
webcpp::codecs::text::view
The first size() characters, valid while this text is.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
std::string_view
view() const & noexcept;
webcpp::codecs::text::view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
std::string_view
view() const && = delete;
Return Value
|
Note
|
The return value should not be discarded. |
webcpp::codecs::text::operator std::string_view
Conversion operators
Synopses
Declared in <webcpp/codecs/detail/core/results.hpp>
The first size() characters; implicit, on an lvalue only (B8).
constexpr
operator std::string_view() const & noexcept;
Deleted on an rvalue: the view would dangle.
operator std::string_view() const && = delete;
Return Value
A view of the characters.
webcpp::codecs::text::operator std::string_view
The first size() characters; implicit, on an lvalue only (B8).
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
constexpr
operator std::string_view() const & noexcept;
Return Value
A view of the characters.
webcpp::codecs::text::operator std::string_view
Deleted on an rvalue: the view would dangle.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
operator std::string_view() const && = delete;
webcpp::codecs::text::capacity
The most characters it holds, N.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
[[nodiscard]]
constexpr
static
std::size_t
capacity() noexcept;
webcpp::codecs::value_codec
The conversion of a format between a typed value and its encoding: declared by the core, never defined, and specialized by the library that owns the format or the type, in the header that defines the pair.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<
class Format,
class Value>
struct value_codec;
Description
A specialization states the kind of its encoding and has the functions of the directions it converts, encoding only, decoding only, or both:
template <> struct value_codec<crypto::formats::pkcs8_t, crypto::curves::p256::keypair> {
static constexpr codecs::output_kind output = codecs::output_kind::bytes;
static constexpr bool secret = true; // optional; false when absent
static constexpr std::size_t max_encoded_size = 138; // optional; a fixed result when present
// optional; the longest input decode accepts
static constexpr std::size_t max_decode_input_size = 138;
static std::size_t encoded_size(crypto::formats::pkcs8_t const& format_value,
crypto::curves::p256::keypair const& held_value) noexcept;
static result<std::size_t> encode(crypto::formats::pkcs8_t const& format_value,
crypto::curves::p256::keypair const& held_value,
std::span<std::uint8_t> output_buffer) noexcept;
static result<crypto::curves::p256::keypair> decode(
crypto::formats::pkcs8_t const& format_value,
std::span<std::uint8_t const> input_bytes) noexcept;
};
max_decode_input_size, optional, is the longest input decode accepts, in the elements it reads (bytes, or characters for a value codec of text): its acceptance contract, which the core enforces on every path of a decode, the typed decode<Value> and over’s call of the value codec alike, by refusing a longer input with error::input_too_long before the value codec is called, after the format’s configuration fault; an input of exactly the bound reaches it, and a bound below the longest valid input refuses that input everywhere. A value codec that states both bounds with max_decode_input_size below max_encoded_size stops the build: its decode would refuse its own longest encoding.
A value codec whose output is output_kind::text writes a std::span<char> and reads a std::string_view. The errors it returns, of any category, reach the caller unchanged. Its decode takes std::span<std::uint8_t const> or std::string_view, not a deduced parameter, as a codec’s functions do: the core may give it a detail::bounded_bytes<N> or a detail::bounded_text<N>, which converts to them. Its encoded_size, encode and decode may also have overloads that take detail::secret_tag first, which the core calls in a secret operation (ruling R7), as for a codec.
Specializations
| Name | Description |
|---|---|
The typed decode of the armor into its parts: the label and the bytes; with no label in the format, any is accepted (R12). It decodes only, and allocates the bytes. |
|
The value codec of |
Template Parameters
| Name | Description |
|---|---|
Format |
The format’s type. |
Value |
The value’s type. |
webcpp::codecs::value_codec<formats::armor_t, formats::armor_parts>
The typed decode of the armor into its parts: the label and the bytes; with no label in the format, any is accepted (R12). It decodes only, and allocates the bytes.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
template<>
struct value_codec<formats::armor_t, formats::armor_parts>;
Static Member Functions
| Name | Description |
|---|---|
Decodes |
Static Data Members
| Name | Description |
|---|---|
The encoding is a text. |
webcpp::codecs::value_codec<formats::armor_t, formats::armor_parts>::decode
Decodes text_characters into its parts, the whole text checked first.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
[[nodiscard]]
static
result<formats::armor_parts>
decode(
formats::armor_t const& format_value,
std::string_view text_characters);
Return Value
The parts, or the text’s fault as the codec’s decoded_size gives it.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_characters |
The text. |
webcpp::codecs::value_codec<formats::armor_t, formats::armor_parts>::output
The encoding is a text.
Synopsis
Declared in <webcpp/codecs/armor.hpp>
inline constexpr static
output_kind output = output_kind::text;
webcpp::codecs::value_codec<over<Outer, Inner, Allocator>, Value>
The value codec of over<Outer, Inner, Allocator> for a Value the value codec of Inner converts.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template<
class Outer,
class Inner,
class Allocator,
class Value>
requires (detail::has_codec<Outer> && detail::inner_value_codec<Inner, Value>)
struct value_codec<over<Outer, Inner, Allocator>, Value>;
Description
It exists when Outer has a codec: the value codec of Inner runs into the intermediate and Outer encodes that, or Outer decodes into the intermediate and the value codec of Inner reads that. Its encoding is text. It states max_encoded_size when the inner value codec does and the outer link’s bound on it fits, so that the default result is in place, and it is secret when the value is (is_secret_v) or the inner value codec says so, which wipes the intermediate and runs both links’ secret arithmetic. Its overloads that take detail::secret_tag first do the same, and the core calls them in every secret operation (ruling R7), one made secret by its token alone (tokens::secret, a token whose secret is true) included. Its functions are noexcept exactly when the intermediate is in place (ruling R3), as codec<over<...>>’s are; its decode’s intermediate is in place also for a text of a dynamic size when the inner value codec states a decode bound (max_decode_input_size) of at most 4096 bytes, and an intermediate past that bound is refused with error::input_too_long before it is made. It states no max_decode_input_size of its own (design R8): a codec’s decoder may accept a text longer than the longest it writes (the armor’s CRLF lines), so no bound on the chain’s text follows from its links’ contracts, and in a chain of chains only the level whose inner link is that value codec is in place for a text of a dynamic size.
Static Data Members
Template Parameters
| Name | Description |
|---|---|
Outer |
The outer link’s type. |
Inner |
The inner link’s type. |
Allocator |
The allocator’s type. |
Value |
The value’s type. |
webcpp::codecs::value_codec<over<Outer, Inner, Allocator>, Value>::output
Text: the outer link writes characters.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
inline constexpr static
output_kind output = output_kind::text;
webcpp::codecs::value_codec<over<Outer, Inner, Allocator>, Value>::secret
Secret when the value is or the inner value codec says so.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
inline constexpr static
bool secret = detail::over_value_is_secret<Inner, Value>;
webcpp::codecs::value_formats
The formats a value type has, declared by the library that owns the type: declared by the core, never defined, as value_codec is, and specialized for a type, fully or by a partial specialization constrained by a concept (a library’s family of types at once).
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<class Value>
struct value_formats;
Description
A value codec is one pair; the declaration is the type’s whole list, so that a refusal says what the type has, and the place of a library’s reasons, so that a refusal says why in the library’s words:
template <> struct value_formats<toy::point> {
// Required: the formats the type has, printed by a refusal.
using formats = codecs::format_list<toy::raw_t, toy::spki_t>;
// Optional: whether the type has Format, for a list that names a family;
// by default, Format is one of formats.
template <class Format>
static constexpr bool has_format =
std::same_as<Format, toy::raw_t> || std::same_as<Format, toy::spki_t>;
// Optional, together: whether the pair has a reason of its own in Direction,
// and the library's sentence, a static_assert false for those pairs alone.
template <class Format, codecs::direction Direction>
static constexpr bool has_reason =
std::same_as<Format, toy::raw_t> && Direction == codecs::direction::decode;
template <class Format, codecs::direction Direction>
static constexpr void refuse() noexcept {
static_assert(!has_reason<Format, Direction>, "toy: a point decodes from its spki form");
}
};
For a declared Value, the pair of Format and Value converts in a direction exactly when it has no reason of its own in that direction (has_reason false or absent); the type has the format (has_format<Format>, by default Format in formats), or Format is over<Outer, Inner, Allocator> and the pair of Inner and Value converts in that direction (a declared type composes under any outer codec, unless a reason refuses the composition); and a value codec of the pair converts in that direction. encodable and decodable are true exactly then. Every operation that converts a value (encode in every form, encoded_size, the typed decode<Value>) and check_conversion refuse any other pair with one error, the first that applies: the declaration’s refuse<Format, Direction>(); for a format the type does not have, codecs’ assertion whose requirement, webcpp::codecs::detail::format_listed<Format, Value, List>, prints the declaration’s formats as List; 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 composition the type does not have is refused as its inner link is, after any reason given for the composition itself.
The members’ shapes are fixed: has_format takes the format alone, and has_reason and refuse take the format and then the direction, as above; a member of another shape is not found, and the type is read as not stating it. refuse<Format, Direction>() must stop the build for every pair whose has_reason is true, its sentence the build’s one error: codecs calls it instead of converting, and an operation it does not stop returns an error, never a value. A type with no declaration converts and is 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.
Template Parameters
| Name | Description |
|---|---|
Value |
The value’s type. |
webcpp::codecs::direction
The direction of a conversion, for a reason of a value_formats that holds in one alone.
Members
| Name | Description |
|---|---|
|
From the value to its encoding. |
|
From the encoding to the value. |
webcpp::codecs::error
Why a conversion of webcpp::codecs failed.
Description
The values are fixed and never reused.
Members
| Name | Description |
|---|---|
|
A character is outside the format’s alphabet. |
|
The length is one no encoding of the format has. |
|
The padding is missing, misplaced or not zero. |
|
The checksum does not match. |
|
The prefix or label is not the format’s. |
|
The text mixes upper and lower case. |
|
The output is shorter than the result. |
|
The input is longer than the format or the buffer allows. |
webcpp::codecs::flow
The state of a stream transformer after a call, beside its result and never an error (D18).
Description
"Receive again" and "send more" are the normal course of a stream, so they are not error codes: a result’s error is a real fault alone.
Members
| Name | Description |
|---|---|
|
Everything accepted is processed: send more, or flush. |
|
Output is waiting: receive it. |
|
Flushed and every output received: reset to start again. |
webcpp::codecs::output_kind
What a value codec’s encoding is made of.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
enum class output_kind : unsigned char;
Members
| Name | Description |
|---|---|
|
Bytes: the encoding is written to a |
|
Text: the encoding is written to a |
webcpp::codecs::category
The category of every error.
Synopsis
Declared in <webcpp/codecs/detail/core/error.hpp>
[[nodiscard]]
boost::system::error_category const&
category() noexcept;
Description
Its name() is "webcpp.codecs", and its message(value) the message of the error, or "unknown webcpp.codecs error" for a value error does not define.
Return Value
The category, a constant with a fixed identity.
|
Note
|
The return value should not be discarded. |
webcpp::codecs::check_conversion
Checks, for a library’s own entry point that converts a value and is not one of codecs’ verbs (a decode that takes a memory resource), that the pair of Format and Value converts in Direction, with the refusal codecs’ verbs have.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<
direction Direction,
class Value,
class Format>
constexpr
void
check_conversion() noexcept;
Description
It does nothing for a pair that converts in Direction (encodable or decodable), and stops the build for any other with one error, as encode and decode do: for a type that declares its formats (value_formats), the declaration’s reason, else the list’s assertion, else the assertion that no value codec of the pair converts; for a type with no declaration, the assertion that the format does not convert this type.
Template Parameters
| Name | Description |
|---|---|
Direction |
The direction of the conversion. |
Value |
The value’s type. |
Format |
The format’s type. |
webcpp::codecs::decode
decode overloads
Synopses
Declared in <webcpp/codecs/detail/core/operations.hpp>
Decodes text_value in format_value and returns the bytes, with the default result (D9): bytes<M> when the text’s size is known at compile time (text<N>, a std::array<char, N>), M being the format’s bound, and std::vector<std::uint8_t> otherwise.
Decodes input_value in format_value into a Value, the type the caller names.
template<
class Value,
class F,
class Input>
[[nodiscard]]
result<Value>
decode(
F const& format_value,
Input const& input_value) noexcept(/* see-below */);
Decodes text_value in format_value into the caller’s buffer, allocating nothing.
template<
format F,
/* implementation-defined */ Text>
[[nodiscard]]
result<std::size_t>
decode(
F const& format_value,
Text const& text_value,
std::span<uint8_t> output_buffer) noexcept(/* see-below */);
Decodes text_value in format_value into token, which says where the bytes go and what they are.
Decodes input_value in format_value into a Value, a string or a vector of std::uint8_t, public or secret, that is made with allocator_value, as a standard container constructed with it is (decode<std::pmr::vector<std::uint8_t>>(format, text, allocator)); the form without an allocator makes a default-constructed one, so decode<std::pmr::vector<std::uint8_t>> uses the default memory resource.
template<
class Value,
class F,
class Input,
class Allocator>
[[nodiscard]]
result<Value>
decode(
F const& format_value,
Input const& input_value,
Allocator const& allocator_value);
Return Value
-
The bytes, or the error.
-
The value, or the error.
-
The number of bytes written, or the error.
-
The token’s result, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Text |
The text’s type: anything a |
Value |
The type to decode into. |
Input |
The input’s type. |
Token |
A tag of |
Allocator |
The allocator’s type, one |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_value |
The text to decode; a string literal is read up to its terminating zero. |
input_value |
The text, or the bytes of a value codec of bytes, to decode. |
output_buffer |
The buffer the bytes are written to. |
token |
The token. |
allocator_value |
The allocator the result is made with. |
webcpp::codecs::decode
Decodes text_value in format_value and returns the bytes, with the default result (D9): bytes<M> when the text’s size is known at compile time (text<N>, a std::array<char, N>), M being the format’s bound, and std::vector<std::uint8_t> otherwise.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
/* implementation-defined */ Text>
[[nodiscard]]
auto
decode(
F const& format_value,
Text const& text_value) noexcept(/* see-below */);
Description
It is noexcept exactly when the result is a bytes, which allocates nothing. A fault of the format’s configuration is returned first (its codec’s configuration_fault); a text whose bytes do not fit in std::size_t is error::input_too_long, before it is read; the whole text is then checked, and its data error with the lowest value of error is returned. A format with no codec specialization stops the build with a message that the format does not convert bytes (named webcpp::codecs::detail::decoded_bytes).
Exception specification
This function is potentially-throwing unless detail::is_fixed_result<detail::default_decode_result<F, Text>> && detail::decode_calls_are_noexcept<F, Text, false>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Text |
The text’s type: anything a |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_value |
The text to decode; a string literal is read up to its terminating zero. |
webcpp::codecs::decode
Decodes input_value in format_value into a Value, the type the caller names.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
class Value,
class F,
class Input>
[[nodiscard]]
result<Value>
decode(
F const& format_value,
Input const& input_value) noexcept(/* see-below */);
Description
Value is a type a value codec of F decodes (read from a byte input for a value codec of bytes, a text input for one of text; its errors reach the caller unchanged), or a byte result of a format with a codec: a std::array<std::uint8_t, N>, which takes exactly N bytes, or a type of fixed_byte_storage, which takes exactly its size (error::invalid_length otherwise), secure::secret<N> among them; a bytes<N> or a secret_bytes<N>, which take up to N bytes (error::output_too_small otherwise); a std::string, a std::vector<std::uint8_t>, a basic_secret_string or a basic_secret_byte_vector, which take the heap. A fault of the format’s configuration is returned first, before any data, in every case (its codec’s configuration_fault, or a chain’s links’). A value codec that states max_decode_input_size then refuses a longer input with error::input_too_long before it is called, whatever the input’s type, public or secret (owner decision 29); an input whose size is known at compile time and at most the bound skips the check. It is noexcept for the fixed byte results, and for a value codec as the value codec’s decode is declared; the heap types allocate and are not. The operation is secret (D10) when Value’s is_secret_v or the value codec’s secret says so: it then holds secure’s timing guard, runs the format’s secret arithmetic where it has one, and wipes the temporary it decodes into before it returns, by secure::erase_secret. A pair F does not convert stops the build with a message that the format does not convert this type; for a Value that declares its formats (value_formats), with design D10’s one error, the declaration’s reason, else the list’s assertion, else the assertion that no value codec of the pair decodes it. An input the pair does not read stops it with one that names the input’s type: a value codec of bytes given what is no byte input says that it decodes from bytes, one of text given what is no text that it decodes from text (ruling R25), and a decode into bytes given what is no text that the format does not convert it.
Exception specification
This function is potentially-throwing unless detail::typed_decode_is_noexcept<Value, F, Input>().
Template Parameters
| Name | Description |
|---|---|
Value |
The type to decode into. |
F |
The format’s type. |
Input |
The input’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The text, or the bytes of a value codec of bytes, to decode. |
webcpp::codecs::decode
Decodes text_value in format_value into the caller’s buffer, allocating nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/sizes.hpp>
template<
format F,
/* implementation-defined */ Text>
[[nodiscard]]
result<std::size_t>
decode(
F const& format_value,
Text const& text_value,
std::span<uint8_t> output_buffer) noexcept(/* see-below */);
Description
The checks come first, and on every error nothing is written: a fault of the format’s configuration is returned first, as its codec’s configuration_fault gives it; a text whose bytes do not fit in std::size_t is error::input_too_long, before it is read; then the whole text is checked, and its data error with the lowest value of error is returned; then an output_buffer shorter than the exact size is error::output_too_small. The bytes are then written at the start of output_buffer, whose other bytes are unchanged. Where the format’s page says so, output_buffer may be the text’s own storage.
A format with no codec specialization stops the build with a message that the format does not convert bytes (named webcpp::codecs::detail::decoded_bytes).
Exception specification
This function is potentially-throwing unless detail::decode_calls_are_noexcept<F, Text, false>().
Return Value
The number of bytes written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Text |
The text’s type: anything a |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_value |
The text to decode; a string literal is read up to its terminating zero. |
output_buffer |
The buffer the bytes are written to. |
webcpp::codecs::decode
Decodes text_value in format_value into token, which says where the bytes go and what they are.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
/* implementation-defined */ Text,
class Token>
requires detail::token_argument<Token>
[[nodiscard]]
auto
decode(
F const& format_value,
Text const& text_value,
Token&& token) noexcept(/* see-below */);
Description
token is one of the tags of codecs::tokens (automatic, the default result of the form without a token; return_string and return_string(allocator), the bytes as a string; append_to and assign_to of a string or a vector of std::uint8_t, which return the container by reference; fixed<N>, a bytes<N>; secret and secret(allocator), secret_bytes<M> for a text of a size known at compile time and basic_secret_byte_vector of the allocator otherwise) or an object of the token contract (a byte token), used as given. The result is `result<typename Token::result_type>`. The order is that of the buffer form’s: a fault of the format’s configuration first, a text whose bytes do not fit in std::size_t is error::input_too_long, the whole text is checked and its data error with the lowest value of error returned, then the token’s capacity against the exact size (error::output_too_small), then one prepare with the exact size, the conversion, one result. A token is untouched when a check fails, and a token of codecs’ also when the conversion fails after prepare (see encode). The forms that allocate are not noexcept; fixed<N> is, and secret when its result is in place. A decode is secret (D10) through its token alone (secret, or a token whose secret is true): it then holds secure’s timing guard and runs the format’s secret arithmetic where it has one. A format with no codec specialization stops the build with a message that the format does not convert bytes (named webcpp::codecs::detail::decoded_bytes), and a token that is not a byte token with one that names the token’s type.
Exception specification
This function is potentially-throwing unless detail::decode_token_is_noexcept<F, Text, Token>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Text |
The text’s type: anything a |
Token |
A tag of |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_value |
The text to decode; a string literal is read up to its terminating zero. |
token |
The token. |
webcpp::codecs::decode
Decodes input_value in format_value into a Value, a string or a vector of std::uint8_t, public or secret, that is made with allocator_value, as a standard container constructed with it is (decode<std::pmr::vector<std::uint8_t>>(format, text, allocator)); the form without an allocator makes a default-constructed one, so decode<std::pmr::vector<std::uint8_t>> uses the default memory resource.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
class Value,
class F,
class Input,
class Allocator>
[[nodiscard]]
result<Value>
decode(
F const& format_value,
Input const& input_value,
Allocator const& allocator_value);
Description
The order and the errors are those of the typed decode without an allocator, and a secret Value (basic_secret_byte_vector, basic_secret_string) makes the operation secret as there. It allocates, and is not noexcept: the allocator’s exception propagates (owner decision 24). A Value that is not a string or a vector of bytes, or that allocator_value does not construct, stops the build with a message that only those take an allocator that constructs them, a format with no codec with one that the format does not convert bytes, and an input that is not a text with one that names the input’s type.
Template Parameters
| Name | Description |
|---|---|
Value |
The string or vector to decode into. |
F |
The format’s type. |
Input |
The text’s type. |
Allocator |
The allocator’s type, one |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The text to decode. |
allocator_value |
The allocator the result is made with. |
webcpp::codecs::decoder
decoder overloads
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
The transformer of format’s decoding, text to bytes (D20): a format_decoder, a one-shot transformer always and a stream transformer when the format streams natively.
The secret transformer of format’s decoding (D20, D21): as decoder(format), its stream secret and the format’s secret arithmetic run where it has one (ruling R7).
template<format F>
[[nodiscard]]
auto
decoder(
F const& format_value,
secret_operation_t) noexcept(/* see-below */);
The transformer of format’s decoding whose stream decoder holds N elements of its input (bech32’s, in characters, B47).
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
capacity_t<N>) noexcept(/* see-below */);
The secret transformer of format’s decoding whose stream decoder holds N elements of its input, as decoder(format, codecs::capacity<N>) with codecs::secret_operation.
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
secret_operation_t,
capacity_t<N>) noexcept(/* see-below */);
The secret transformer of format’s decoding whose stream decoder holds N elements of its input: the tags in the other order.
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
capacity_t<N>,
secret_operation_t) noexcept(/* see-below */);
Return Value
-
The format’s decoder.
-
The format’s secret decoder.
-
The format’s decoder, of the hold
N. -
The format’s secret decoder, of the hold
N.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
N |
The hold, 1 or more. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::decoder
The transformer of format’s decoding, text to bytes (D20): a format_decoder, a one-shot transformer always and a stream transformer when the format streams natively.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<format F>
[[nodiscard]]
auto
decoder(F const& format_value) noexcept(/* see-below */);
Description
decoder(over{outer, inner}) streams through a pipe of the outer link’s decoder and then the inner link’s when both stream natively (B43). A value codec’s format has no transformer, and the call stops the build with a message that says so.
Exception specification
This function is potentially-throwing unless detail::nothrow_decoder<F, detail::public_stream>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::decoder
The secret transformer of format’s decoding (D20, D21): as decoder(format), its stream secret and the format’s secret arithmetic run where it has one (ruling R7).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<format F>
[[nodiscard]]
auto
decoder(
F const& format_value,
secret_operation_t) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::nothrow_decoder<F, detail::secret_stream>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::decoder
The transformer of format’s decoding whose stream decoder holds N elements of its input (bech32’s, in characters, B47).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
capacity_t<N>) noexcept(/* see-below */);
Description
A format whose decoder holds nothing stops the build with a message that says so, and so does codecs::capacity<0>: a hold is 1 or more, and so does a hold above the format’s maximum_hold (bech32’s MaximumLength), checked before the decoder type is named.
Exception specification
This function is potentially-throwing unless detail::nothrow_decoder<F, stream_options{.capacity = N}>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
N |
The hold, 1 or more. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::decoder
The secret transformer of format’s decoding whose stream decoder holds N elements of its input, as decoder(format, codecs::capacity<N>) with codecs::secret_operation.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
secret_operation_t,
capacity_t<N>) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::nothrow_decoder<F, stream_options{.secret = true, .capacity = N}>().
Return Value
The format’s secret decoder, of the hold N.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
N |
The hold, 1 or more. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::decoder
The secret transformer of format’s decoding whose stream decoder holds N elements of its input: the tags in the other order.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<
format F,
std::size_t N>
[[nodiscard]]
auto
decoder(
F const& format_value,
capacity_t<N>,
secret_operation_t) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::nothrow_decoder<F, stream_options{.secret = true, .capacity = N}>().
Return Value
The format’s secret decoder, of the hold N.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
N |
The hold, 1 or more. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::drain
drain overloads
Synopses
Declared in <webcpp/codecs/detail/core/pipe.hpp>
Receives from transformer until it reports flow::needs_input or flow::finished, and calls sink(std::span<output_type const>) with each non-empty piece, through a buffer in place of codecs::default_capacity_v elements (D19).
template<
class T,
class Sink>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink) noexcept(detail::nothrow_drain<T, Sink>());
Receives from transformer into sink as drain does, through the caller’s buffer: each piece is a view of its first elements.
template<
class T,
class Sink>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink,
std::span<T::output_type> buffer) noexcept(detail::nothrow_drain<T, Sink>());
Receives from transformer into sink as drain does, through a buffer in place of N elements, wiped before the drain returns when the transformer is secret.
template<
class T,
class Sink,
std::size_t N>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink,
capacity_t<N>) noexcept(detail::nothrow_drain<T, Sink>());
Return Value
The state the drain stopped at, or the first error, the transformer’s or the sink’s.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
T |
The transformer’s type. |
Sink |
The sink’s type. |
N |
The buffer’s elements. |
Parameters
| Name | Description |
|---|---|
transformer |
A stream transformer; a one-shot transformer is made one by |
sink |
What takes each piece. |
buffer |
The span the transformer writes each piece into. |
webcpp::codecs::drain
Receives from transformer until it reports flow::needs_input or flow::finished, and calls sink(std::span<output_type const>) with each non-empty piece, through a buffer in place of codecs::default_capacity_v elements (D19).
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class T,
class Sink>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink) noexcept(detail::nothrow_drain<T, Sink>());
Description
The sink is called directly, as a template parameter, and returns void or codecs::result<void>, whose error stops the drain. When output is pending and the transformer writes none of it into the buffer, the drain stops with error::output_too_small. Of a secret transformer (codecs::is_secret_v, D21), the buffer is wiped by secure::erase_secret before the drain returns, by every path.
Return Value
The state the drain stopped at, or the first error, the transformer’s or the sink’s.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
T |
The transformer’s type. |
Sink |
The sink’s type. |
Parameters
| Name | Description |
|---|---|
transformer |
A stream transformer; a one-shot transformer is made one by |
sink |
What takes each piece. |
webcpp::codecs::drain
Receives from transformer into sink as drain does, through the caller’s buffer: each piece is a view of its first elements.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class T,
class Sink>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink,
std::span<T::output_type> buffer) noexcept(detail::nothrow_drain<T, Sink>());
Description
The buffer stays the caller’s, who wipes it as the caller’s own secret buffers are wiped: the drain does not, also of a secret transformer.
Return Value
The state the drain stopped at, or the first error, the transformer’s or the sink’s.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
T |
The transformer’s type. |
Sink |
The sink’s type. |
Parameters
| Name | Description |
|---|---|
transformer |
A stream transformer. |
sink |
What takes each piece. |
buffer |
The span the transformer writes each piece into. |
webcpp::codecs::drain
Receives from transformer into sink as drain does, through a buffer in place of N elements, wiped before the drain returns when the transformer is secret.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class T,
class Sink,
std::size_t N>
[[nodiscard]]
result<flow>
drain(
T& transformer,
Sink&& sink,
capacity_t<N>) noexcept(detail::nothrow_drain<T, Sink>());
Return Value
The state the drain stopped at, or the first error, the transformer’s or the sink’s.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
T |
The transformer’s type. |
Sink |
The sink’s type. |
N |
The buffer’s elements. |
Parameters
| Name | Description |
|---|---|
transformer |
A stream transformer. |
sink |
What takes each piece, of at most |
webcpp::codecs::encode
encode overloads
Synopses
Declared in <webcpp/codecs/detail/core/operations.hpp>
Refuses the encode of Input, a type that declares its formats, in a format whose pair does not convert by that declaration (value_formats).
template<
format F,
class Input>
requires detail::declaration_refuses<direction::encode, Input, F>
[[nodiscard]]
result<std::string>
encode(
F const&,
Input const&) noexcept;
Encodes input_value in format_value and returns the encoding, with the default result (D9): text<M> (or bytes<M> for a value codec of bytes) when the input’s size is known at compile time or the value codec states max_encoded_size, M being the format’s bound, and std::string (or std::vector<std::uint8_t>) otherwise.
Encodes input_value, a value of a value codec of text, in format_value into the caller’s buffer, allocating nothing.
template<
format F,
class Input>
requires ((detail::value_encodable<Input, F> &&
value_codec<F, Input>::output == output_kind::text) ||
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<char> output_buffer) noexcept(/* see-below */);
Encodes input_value in format_value into the caller’s buffer, allocating nothing.
template<
format F,
/* implementation-defined */ Input>
requires (!detail::value_encodable<Input, F> &&
!detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<char> output_buffer) noexcept(/* see-below */);
Encodes input_value, a value of a value codec of bytes, in format_value into the caller’s buffer, allocating nothing.
template<
format F,
class Input>
requires ((detail::value_encodable<Input, F> &&
value_codec<F, Input>::output == output_kind::bytes) ||
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<uint8_t> output_buffer) noexcept(/* see-below */);
Refuses the encode into a token of Input, a type that declares its formats (value_formats), in a format whose pair does not convert by that declaration, as the form without a token does: design D10’s one error, whatever the token.
template<
format F,
class Input,
class Token>
requires (detail::token_argument<Token> &&
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::string>
encode(
F const&,
Input const&,
Token&&) noexcept;
Encodes input_value in format_value into token, which says where the result goes and what it is.
Return Value
-
Never used: the build stops.
-
The encoding, or the error.
-
The number of characters written, or the error.
-
The number of bytes written, or the error.
-
The token’s result, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The value’s type. |
Token |
A tag of |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The bytes, or the value, to encode. |
output_buffer |
The buffer the text is written to. |
token |
The token. |
webcpp::codecs::encode
Refuses the encode of Input, a type that declares its formats, in a format whose pair does not convert by that declaration (value_formats).
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input>
requires detail::declaration_refuses<direction::encode, Input, F>
[[nodiscard]]
result<std::string>
encode(
F const&,
Input const&) noexcept;
Description
The build stops with design D10’s one error, the declaration’s reason, else the list’s assertion, else the assertion that no value codec of the pair encodes it. Its declaration and exception specification are well-formed, so that the refusal is the build’s only error.
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The value’s type. |
webcpp::codecs::encode
Encodes input_value in format_value and returns the encoding, with the default result (D9): text<M> (or bytes<M> for a value codec of bytes) when the input’s size is known at compile time or the value codec states max_encoded_size, M being the format’s bound, and std::string (or std::vector<std::uint8_t>) otherwise.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input>
requires (!detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
auto
encode(
F const& format_value,
Input const& input_value) noexcept(/* see-below */);
Description
A secret operation (D10: the input’s is_secret_v, or the value codec’s secret) gives the secret column instead, secret_text<M> (or secret_bytes<M>) and secret_string (or secret_byte_vector), holds secure’s timing guard for its duration and runs the format’s secret arithmetic where it has one.
It is noexcept exactly when the result is held in place, which allocates nothing. A fault of the format’s configuration is returned first (its codec’s configuration_fault), then a fault of the encode (its codec’s encode_fault: bech32’s missing human-readable part, the armor’s missing label), whatever the input’s size, before any result is made; an input whose encoding does not fit in std::size_t is error::input_too_long, before it is read. A value codec of F and Input is used when it encodes, else codec<F>. A pair that is not encodable stops the build with a message that the format does not convert this type; a pair of a type that declares its formats (value_formats) is taken by the overload that refuses it by its declaration.
Exception specification
This function is potentially-throwing unless detail::is_fixed_result<detail::default_encode_result<F, Input>> && detail::encode_calls_are_noexcept<F, Input, detail::secret_operation_v<F, Input, void>>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The input’s type: a byte input, or a value of a value codec. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The bytes, or the value, to encode. |
webcpp::codecs::encode
Encodes input_value, a value of a value codec of text, in format_value into the caller’s buffer, allocating nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input>
requires ((detail::value_encodable<Input, F> &&
value_codec<F, Input>::output == output_kind::text) ||
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<char> output_buffer) noexcept(/* see-below */);
Description
The checks come first, and on every error nothing is written: a fault of the format’s configuration is returned first (its codec’s configuration_fault); an output_buffer shorter than the exact size is error::output_too_small. The text is then written at the start of output_buffer, whose other characters are unchanged. The errors the value codec returns reach the caller unchanged. A secret value (is_secret_v, or the value codec’s secret) holds secure’s timing guard while the value codec runs, which runs its overloads that take detail::secret_tag first where it has them (R7). A type that declares its formats (value_formats) is taken whatever its pair, and a pair that does not convert by its declaration stops the build with design D10’s one error, never with no matching function.
Exception specification
This function is potentially-throwing unless detail::encode_form_is_noexcept<F, Input>().
Return Value
The number of characters written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The value’s type, one |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The value to encode. |
output_buffer |
The buffer the text is written to. |
webcpp::codecs::encode
Encodes input_value in format_value into the caller’s buffer, allocating nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/sizes.hpp>
template<
format F,
/* implementation-defined */ Input>
requires (!detail::value_encodable<Input, F> &&
!detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<char> output_buffer) noexcept(/* see-below */);
Description
The checks come first, and on every error nothing is written: a fault of the format’s configuration is returned first, as its codec’s configuration_fault gives it; then a fault of the encode, as its codec’s encode_fault gives it (bech32’s missing human-readable part, the armor’s missing label), whatever the input’s size; an input whose encoding does not fit in std::size_t is error::input_too_long, before it is read; an output_buffer shorter than the exact size is error::output_too_small. The text is then written at the start of output_buffer, whose other characters are unchanged.
A secret input (is_secret_v, as secure::secret<N>) makes the operation secret: it holds secure’s timing guard and runs the format’s secret arithmetic where it has one (D10). A format with no codec specialization stops the build with a message that the format does not convert this type. A type a value codec of F encodes takes the value codec’s buffer form instead (operations.hpp), as a type that declares its formats (value_formats) and whose pair does not convert does, which refuses it by its declaration.
Exception specification
This function is potentially-throwing unless detail::encode_calls_are_noexcept<F, Input, detail::secret_operation_v<F, Input, void>>().
Return Value
The number of characters written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The input’s type: a contiguous sized range of |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The bytes to encode. |
output_buffer |
The buffer the text is written to. |
webcpp::codecs::encode
Encodes input_value, a value of a value codec of bytes, in format_value into the caller’s buffer, allocating nothing.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input>
requires ((detail::value_encodable<Input, F> &&
value_codec<F, Input>::output == output_kind::bytes) ||
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::size_t>
encode(
F const& format_value,
Input const& input_value,
std::span<uint8_t> output_buffer) noexcept(/* see-below */);
Description
The checks come first, and on every error nothing is written: a fault of the format’s configuration is returned first (its codec’s configuration_fault); an output_buffer shorter than the exact size is error::output_too_small. The bytes are then written at the start of output_buffer, whose other bytes are unchanged. The errors the value codec returns reach the caller unchanged. A secret value (is_secret_v, or the value codec’s secret) holds secure’s timing guard while the value codec runs, which runs its overloads that take detail::secret_tag first where it has them (R7). A type that declares its formats (value_formats) is taken whatever its pair, and a pair that does not convert by its declaration stops the build with design D10’s one error, never with no matching function.
Exception specification
This function is potentially-throwing unless detail::encode_form_is_noexcept<F, Input>().
Return Value
The number of bytes written, or the error.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The value’s type, one |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The value to encode. |
output_buffer |
The buffer the bytes are written to. |
webcpp::codecs::encode
Refuses the encode into a token of Input, a type that declares its formats (value_formats), in a format whose pair does not convert by that declaration, as the form without a token does: design D10’s one error, whatever the token.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input,
class Token>
requires (detail::token_argument<Token> &&
detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
result<std::string>
encode(
F const&,
Input const&,
Token&&) noexcept;
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The value’s type. |
Token |
A tag of |
webcpp::codecs::encode
Encodes input_value in format_value into token, which says where the result goes and what it is.
Synopsis
Declared in <webcpp/codecs/detail/core/operations.hpp>
template<
format F,
class Input,
class Token>
requires (detail::token_argument<Token> &&
!detail::declaration_refuses<direction::encode, Input, F>)
[[nodiscard]]
auto
encode(
F const& format_value,
Input const& input_value,
Token&& token) noexcept(/* see-below */);
Description
token is one of the tags of codecs::tokens (automatic, which is the default result of the form without a token; return_string and return_string(allocator), a string; append_to and assign_to of a string, which return the string by reference; fixed<N>, a text<N>, or a bytes<N> for a value codec of bytes; secret and secret(allocator), D9’s secret column, in place when the bound is known at compile time and on the heap of the allocator otherwise) or an object of the token contract of Boost.URL’s string tokens, used as given. The result is result<typename Token::result_type>. The order is that of the buffer form’s: a fault of the format’s configuration first, then a fault of the encode (its codec’s encode_fault: bech32’s missing human-readable part, a text past its longest, a word above 31; the armor’s missing label), whatever the input’s size, then every other check of the input (an input whose encoding does not fit in std::size_t is error::input_too_long), then the token’s capacity against the exact size (error::output_too_small), then one prepare with the exact size, the conversion, one result. A token is untouched when a check fails, and a token of codecs’ also when the conversion fails after prepare (an error of a value codec’s own): append_to is put back as it was, and assign_to converts into a scratch (in place when the bound is known at compile time and at most 4096 elements, else of the container’s allocator) and copies it into the container only on success; a token of a program’s own is left as prepare made it. A token of codecs’ holds what the format wrote. The forms that allocate are not noexcept (an allocator’s exception propagates, owner decision 24); fixed<N> is, and secret when its result is in place. The operation is secret (D10) when the input’s is_secret_v, the value codec’s secret or the token’s secret says so: it then holds secure’s timing guard and runs the format’s secret arithmetic where it has one, and the result is the token’s (a secret input into return_string gives a std::string, as the caller asked); a token of codecs’ then wipes, by secure::erase_secret, what the caller does not get (what it wrote when the conversion fails, the tail it cuts, its own copy, assign_to’s scratch). A pair that is not encodable stops the build with a message that the format does not convert this type, and a token that does not take the pair’s encoding (append_to of a vector, which is for decode) with one that names the token’s type. A pair of a type that declares its formats (value_formats) and does not convert by that declaration is taken by the overload that refuses it by its declaration.
Exception specification
This function is potentially-throwing unless detail::encode_token_is_noexcept<F, Input, Token>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The input’s type: a byte input, or a value of a value codec. |
Token |
A tag of |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The bytes, or the value, to encode. |
token |
The token. |
webcpp::codecs::encoded_size
The exact size of what encode writes for input_value in format_value: characters, or bytes for a value codec of bytes.
Synopsis
Declared in <webcpp/codecs/detail/core/sizes.hpp>
template<
format F,
class Input>
[[nodiscard]]
constexpr
std::size_t
encoded_size(
F const& format_value,
Input const& input_value) noexcept(/* see-below */);
Description
It is a constant expression where the format and the input are, and the input’s bytes are std::uint8_t or unsigned char (or the input is a value of a value codec whose encoded_size is constexpr), and the input is not secret. A value codec of F and Input is used when it encodes, else codec<F>. Of a secret input (is_secret_v, or a value codec’s secret) it holds secure’s timing guard and runs the format’s secret arithmetic where it has one (D10). It has no error channel, and keeps the one rule of every size for an input that every encode refuses, as a transformer’s output_size does: SIZE_MAX when it is refused for its size (its encoding does not fit, or bech32’s text is past the instance’s longest), 0 when it is refused for a fault of the format’s configuration or of the encode (bech32’s missing human-readable part or a word above 31, the armor’s missing label); the format’s other functions are then not called (B23).
A pair that is not encodable stops the build with a message that the format does not convert this type; for a type that declares its formats (value_formats), with design D10’s one error, the declaration’s reason, else the list’s assertion, else the assertion that no value codec of the pair encodes it.
Exception specification
This function is potentially-throwing unless detail::encode_form_is_noexcept<F, Input>().
Return Value
The size; SIZE_MAX for an input refused for its size, 0 for one refused for a fault of the configuration or of the encode.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Input |
The input’s type: a byte input, or a value of a value codec. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
input_value |
The bytes, or the value, to encode. |
webcpp::codecs::encoder
encoder overloads
Synopses
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
The transformer of format’s encoding, bytes to text (D20): a format_encoder, a one-shot transformer always and a stream transformer when the format streams natively.
The secret transformer of format’s encoding (D20, D21): as encoder(format), its stream secret and the format’s secret arithmetic run where it has one (ruling R7).
template<format F>
[[nodiscard]]
auto
encoder(
F const& format_value,
secret_operation_t) noexcept(/* see-below */);
Return Value
-
The format’s encoder.
-
The format’s secret encoder.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::encoder
The transformer of format’s encoding, bytes to text (D20): a format_encoder, a one-shot transformer always and a stream transformer when the format streams natively.
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<format F>
[[nodiscard]]
auto
encoder(F const& format_value) noexcept(/* see-below */);
Description
encoder(over{outer, inner}) streams through a pipe of the links’ encoders when both stream natively (B43). A value codec’s format has no transformer: typed values are converted whole, and the call stops the build with a message that says so.
Exception specification
This function is potentially-throwing unless detail::nothrow_encoder<F, detail::public_stream>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::encoder
The secret transformer of format’s encoding (D20, D21): as encoder(format), its stream secret and the format’s secret arithmetic run where it has one (ruling R7).
Synopsis
Declared in <webcpp/codecs/detail/core/format_transformer.hpp>
template<format F>
[[nodiscard]]
auto
encoder(
F const& format_value,
secret_operation_t) noexcept(/* see-below */);
Exception specification
This function is potentially-throwing unless detail::nothrow_encoder<F, detail::secret_stream>().
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
webcpp::codecs::make_error_code
Makes the error_code of an error, as its implicit conversion does.
Synopsis
Declared in <webcpp/codecs/detail/core/error.hpp>
[[nodiscard]]
boost::system::error_code
make_error_code(error error_value) noexcept;
Return Value
error_value as an error_code of the category category.
|
Note
|
The return value should not be discarded. |
Parameters
| Name | Description |
|---|---|
error_value |
The error. |
webcpp::codecs::max_decoded_size
A bound on the bytes decode writes for text_value in format_value, from the text’s size alone.
Synopsis
Declared in <webcpp/codecs/detail/core/sizes.hpp>
template<
format F,
/* implementation-defined */ Text>
[[nodiscard]]
constexpr
std::size_t
max_decoded_size(
F const& format_value,
Text const& text_value) noexcept;
Description
It is a constant expression where the format and the text are. A format with no codec specialization stops the build with a message that the format does not convert bytes (named webcpp::codecs::detail::decoded_bytes).
Return Value
The bound, SIZE_MAX when it does not fit in std::size_t.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
F |
The format’s type. |
Text |
The text’s type: anything a |
Parameters
| Name | Description |
|---|---|
format_value |
The format. |
text_value |
The text; a string literal is read up to its terminating zero. |
webcpp::codecs::pipe
pipe overloads
Synopses
Declared in <webcpp/codecs/detail/core/pipe.hpp>
A stream transformer of first and then second, with an intermediate in place of codecs::default_capacity_v elements of first’s output (D19).
template<
class First,
class Second>
[[nodiscard]]
auto
pipe(
First first,
Second second) noexcept(detail::nothrow_movable_v<First, Second>);
A stream transformer of first and then second, with an intermediate in place of N elements of first’s output (D19).
template<
class First,
class Second,
std::size_t N>
[[nodiscard]]
auto
pipe(
First first,
Second second,
capacity_t<N>) noexcept(detail::nothrow_movable_v<First, Second>);
The pipe of three or more stream transformers, from the left: pipe(a, b, c) is pipe(pipe(a, b), c), each intermediate of the default capacity.
template<
class First,
class Second,
class Third,
class... Rest>
[[nodiscard]]
auto
pipe(
First first,
Second second,
Third third,
Rest... rest) noexcept(/* see-below */);
Return Value
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
First |
The first transformer’s type. |
Second |
The second transformer’s type. |
N |
The intermediate’s elements. |
Third |
The third transformer’s type. |
Rest |
The types of the transformers after the third, and of a last capacity tag. |
Parameters
| Name | Description |
|---|---|
first |
The first transformer. |
second |
The second transformer. |
third |
The third transformer. |
rest |
The transformers after the third, and optionally a |
webcpp::codecs::pipe
A stream transformer of first and then second, with an intermediate in place of codecs::default_capacity_v elements of first’s output (D19).
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class First,
class Second>
[[nodiscard]]
auto
pipe(
First first,
Second second) noexcept(detail::nothrow_movable_v<First, Second>);
Description
codecs::capacity<N> as a third argument sets another capacity. It compiles only when both are stream transformers and first’s output_type is compatible with second’s input_type.
Template Parameters
| Name | Description |
|---|---|
First |
The first transformer’s type. |
Second |
The second transformer’s type. |
Parameters
| Name | Description |
|---|---|
first |
The first transformer. |
second |
The second transformer. |
webcpp::codecs::pipe
A stream transformer of first and then second, with an intermediate in place of N elements of first’s output (D19).
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class First,
class Second,
std::size_t N>
[[nodiscard]]
auto
pipe(
First first,
Second second,
capacity_t<N>) noexcept(detail::nothrow_movable_v<First, Second>);
Description
It compiles only when both are stream transformers and first’s output_type is compatible with second’s input_type: the same type, or both one-byte character or byte types. A one-shot transformer is made a stream by codecs::each (per item) or codecs::buffered (accumulating).
Template Parameters
| Name | Description |
|---|---|
First |
The first transformer’s type. |
Second |
The second transformer’s type. |
N |
The intermediate’s elements. |
Parameters
| Name | Description |
|---|---|
first |
The first transformer. |
second |
The second transformer. |
webcpp::codecs::pipe
The pipe of three or more stream transformers, from the left: pipe(a, b, c) is pipe(pipe(a, b), c), each intermediate of the default capacity.
Synopsis
Declared in <webcpp/codecs/detail/core/pipe.hpp>
template<
class First,
class Second,
class Third,
class... Rest>
[[nodiscard]]
auto
pipe(
First first,
Second second,
Third third,
Rest... rest) noexcept(/* see-below */);
Description
A codecs::capacity<N> after the last transformer, pipe(a, b, c, codecs::capacity<N>), is pipe(pipe(a, b), c, codecs::capacity<N>): it sets the last intermediate’s capacity alone, and the others keep the default.
Exception specification
This function is potentially-throwing unless detail::nothrow_pipe_of_many<First, Second, Third, Rest...>().
Return Value
A piped whose first part is the pipe of the transformers before the last.
|
Note
|
The return value should not be discarded. |
Template Parameters
| Name | Description |
|---|---|
First |
The first transformer’s type. |
Second |
The second transformer’s type. |
Third |
The third transformer’s type. |
Rest |
The types of the transformers after the third, and of a last capacity tag. |
Parameters
| Name | Description |
|---|---|
first |
The first transformer. |
second |
The second transformer. |
third |
The third transformer. |
rest |
The transformers after the third, and optionally a |
webcpp::codecs::swap
swap overloads
Synopses
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
Exchanges the bytes of two byte vectors, as their member swap.
void
swap(
basic_secret_byte_vector& first_bytes,
basic_secret_byte_vector& second_bytes) noexcept(noexcept(first_bytes.swap(second_bytes)));
Exchanges the characters of two strings, as their member swap.
void
swap(
basic_secret_string& first_string,
basic_secret_string& second_string) noexcept(/* see-below */);
Parameters
| Name | Description |
|---|---|
first_bytes |
Bytes. |
second_bytes |
Other bytes. |
first_string |
A string. |
second_string |
Another string. |
webcpp::codecs::swap
Exchanges the bytes of two byte vectors, as their member swap.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
swap(
basic_secret_byte_vector& first_bytes,
basic_secret_byte_vector& second_bytes) noexcept(noexcept(first_bytes.swap(second_bytes)));
|
Note
|
This function is a hidden friend of basic_secret_byte_vector, declared only inside that class: it can be found only through argument-dependent lookup. |
Parameters
| Name | Description |
|---|---|
first_bytes |
Bytes. |
second_bytes |
Other bytes. |
webcpp::codecs::swap
Exchanges the characters of two strings, as their member swap.
Synopsis
Declared in <webcpp/codecs/detail/core/secret_types.hpp>
void
swap(
basic_secret_string& first_string,
basic_secret_string& second_string) noexcept(/* see-below */);
|
Note
|
This function is a hidden friend of basic_secret_string, declared only inside that class: it can be found only through argument-dependent lookup. |
Exception specification
This function is potentially-throwing unless noexcept(first_string.swap(second_string)).
Parameters
| Name | Description |
|---|---|
first_string |
A string. |
second_string |
Another string. |
webcpp::codecs::operator==
Equality operators
Synopses
Declared in <webcpp/codecs/detail/core/results.hpp>
Whether two texts hold the same characters.
constexpr
bool
operator==(
text const& first_text,
text const& second_text) noexcept;
Whether two values hold the same bytes.
constexpr
bool
operator==(
bytes const& first_bytes,
bytes const& second_bytes) noexcept;
Return Value
-
Whether their characters are the same.
-
Whether their bytes are the same.
Parameters
| Name | Description |
|---|---|
first_text |
A text. |
second_text |
Another text. |
first_bytes |
Bytes. |
second_bytes |
Other bytes. |
webcpp::codecs::operator==
Whether two texts hold the same characters.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
|
Note
|
This function is a hidden friend of text, declared only inside that class: it can be found only through argument-dependent lookup. |
Return Value
Whether their characters are the same.
Parameters
| Name | Description |
|---|---|
first_text |
A text. |
second_text |
Another text. |
webcpp::codecs::operator==
Whether two values hold the same bytes.
Synopsis
Declared in <webcpp/codecs/detail/core/results.hpp>
|
Note
|
This function is a hidden friend of bytes, declared only inside that class: it can be found only through argument-dependent lookup. |
Return Value
Whether their bytes are the same.
Parameters
| Name | Description |
|---|---|
first_bytes |
Bytes. |
second_bytes |
Other bytes. |
webcpp::codecs::capacity
A capacity in place of N elements: codecs::pipe(first, second, codecs::capacity<64>).
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<std::size_t N>
inline constexpr capacity_t<N> capacity = {};
Template Parameters
| Name | Description |
|---|---|
N |
The capacity, in elements. |
webcpp::codecs::default_capacity_v
The default capacity in place of a composition’s buffer of elements of type Element: 512 bytes, at least one element (B32).
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<class Element>
inline constexpr std::size_t default_capacity_v = sizeof(Element) >= 512 ? 1 : 512 / sizeof(Element);
Template Parameters
| Name | Description |
|---|---|
Element |
The buffer’s element type. |
webcpp::codecs::is_constant_time_v
Whether a transformer of type T runs in a time that does not depend on its data: its static constexpr bool constant_time when it states one, and false otherwise.
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<class T>
inline constexpr bool is_constant_time_v = detail::constant_time_of<std::remove_cvref_t<T>>();
Template Parameters
| Name | Description |
|---|---|
T |
The transformer’s type; a reference and |
webcpp::codecs::is_secret_v
Whether values of T are secret, T’s references and const ignored.
Synopsis
Declared in <webcpp/codecs/detail/core/secrecy.hpp>
template<class T>
inline constexpr bool is_secret_v = is_secret<std::remove_cvref_t<T>>::value;
Template Parameters
| Name | Description |
|---|---|
T |
The type. |
webcpp::codecs::secret_operation
The tag that makes a transformer of a format secret, wiped and under secure’s timing guard.
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
inline constexpr secret_operation_t secret_operation = secret_operation{};
webcpp::codecs::static_input_size_v
The size of an input of type T when it is known at compile time, else std::dynamic_extent.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<class T>
inline constexpr std::size_t static_input_size_v = detail::static_input_size<std::remove_cvref_t<T>>::value;
Description
It is known for a std::array and a std::span of a static extent of byte elements, an array of std::uint8_t, unsigned char or std::byte, text<N> and bytes<N> (their capacity), and a type with a static constexpr size() that converts to std::span<std::uint8_t const, size()>, as secure::secret<N> does. An array of char, a string literal, is read as a std::string_view and its size is not static (B5).
Template Parameters
| Name | Description |
|---|---|
T |
The input’s type; a reference and |
webcpp::codecs::decodable
Whether a value of type V decodes from the format F: V is a byte result the core builds (std::string, std::vector<std::uint8_t>, std::array<std::uint8_t, N>, bytes<N>, or a library’s fixed type with a fixed_byte_storage), codec<F> is specialized and no value codec of the pair decodes it, or value_codec<F, V> is specialized with decode and, when V declares its formats (value_formats), the pair converts by that declaration, so that the concept is true exactly where the typed decode<V> builds.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<
class V,
class F>
concept decodable = format<F> &&
((detail::byte_result<V> && detail::has_codec<F> && !detail::value_decodable<V, F>) ||
(detail::value_decodable<V, F> && detail::pair_converts<direction::decode, F, V>()));
Description
A pair with a value codec is the value codec’s, a byte result’s included: its declaration governs it.
Template Parameters
| Name | Description |
|---|---|
V |
The value’s type. |
F |
The format’s type. |
webcpp::codecs::encodable
Whether a value of type V encodes in the format F: V is a byte input, codec<F> is specialized and no value codec of the pair encodes it, or value_codec<F, V> is specialized with encode and encoded_size and, when V declares its formats (value_formats), the pair converts by that declaration, so that the concept is true exactly where encode builds.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<
class V,
class F>
concept encodable = format<F> &&
((detail::byte_input<V> && detail::has_codec<F> && !detail::value_encodable<V, F>) ||
(detail::value_encodable<V, F> && detail::pair_converts<direction::encode, F, V>()));
Description
A pair with a value codec is the value codec’s, a byte input’s included: its declaration governs it.
A byte input is a contiguous sized range of std::uint8_t, unsigned char, char or std::byte, a type with a static constexpr size() that converts to std::span<std::uint8_t const, size()>, as secure::secret<N>, or a fixed result (text<N>, bytes<N>), which is read through its view().
Template Parameters
| Name | Description |
|---|---|
V |
The value’s type. |
F |
The format’s type. |
webcpp::codecs::format
A format: a copyable type with a constant name that converts to std::string_view, passed by value as the first argument of every operation.
Synopsis
Declared in <webcpp/codecs/detail/core/contract.hpp>
template<class F>
concept format = std::copyable<F> && requires {
{ F::name } -> std::convertible_to<std::string_view>;
};
Template Parameters
| Name | Description |
|---|---|
F |
The type to check. |
webcpp::codecs::one_shot_transformer
A transformer that converts a whole input at once: transform(input, output) writes all of its output and returns the count, or writes nothing and returns an error (D17).
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<class T>
concept one_shot_transformer = detail::transformer_types<T> &&
requires(T& transformer, std::span<typename T::input_type const> input,
std::span<typename T::output_type> output) {
{ transformer.transform(input, output) } -> std::same_as<result<std::size_t>>;
};
Description
Its input_type and output_type are any cv-unqualified object types (a byte, a character, a compressed packet, a decoded frame) and every transfer is a contiguous span of elements, read from the caller’s input and written into the caller’s output. A short output is error::output_too_small, with nothing written. transform takes the transformer by non-const reference, so that it may keep state between calls (a media encoder’s context). A type may add overloads of its own; the concept requires the span form alone, and assumes no bytes, characters, constant time or secrecy. A moved-from T must still transform: each and buffered move their transformer along with the rest of their state, and a moved-from one keeps calling the T it was left holding, so a stateful move-only T has to leave its moved-from object able to convert (the concept cannot check it).
Optional members, read when present and never required: a static max_output_size(std::size_t), a bound on the output of that many input elements, constexpr where it can be (a bound of the object’s own, a non-static member, is not read, and each and buffered size such a transformer’s output by doubling), and output_size(input), the exact size; static constexpr bool constant_time, read through is_constant_time_v.
Template Parameters
| Name | Description |
|---|---|
T |
The type to check. |
webcpp::codecs::stream_transformer
A transformer that converts a stream: send gives it input, receive takes its output, flush ends the input and reset starts again, with the protocol of D18.
Synopsis
Declared in <webcpp/codecs/detail/core/transformer.hpp>
template<class T>
concept stream_transformer = detail::transformer_types<T> &&
requires(T& transformer, std::span<typename T::input_type const> input,
std::span<typename T::output_type> output) {
{ transformer.send(input) } -> std::same_as<result<step>>;
{ transformer.receive(output) } -> std::same_as<result<step>>;
{ transformer.flush() } -> std::same_as<result<flow>>;
{ transformer.reset() } noexcept -> std::same_as<void>;
};
Description
It starts in flow::needs_input. send(input) in that state accepts a prefix of input and returns how many elements it accepted with the state after; in any other state it accepts nothing and returns {0, state}. The elements accepted stay the caller’s, alive and unchanged, until the transformer next reports flow::needs_input or flow::finished, or is reset or destroyed: it reads them during receive, from the caller’s input straight into the caller’s output. receive(output) writes up to output.size() elements and returns how many with the state after; an empty span returns {0, state}. flush() ends the input and returns flow::output_pending while output remains and flow::finished when none does; after it nothing is accepted until reset. A fault of the data is reported once, after flush, by the first call that has processed the whole input, and every call returns it until reset. reset() returns the transformer to flow::needs_input with nothing borrowed, nothing pending and no error, and a moved-from transformer is in the state reset leaves, so that it converts a new input from the start; the concept cannot check either, and every transformer of codecs keeps both.
The concept assumes no bytes, characters, constant time or secrecy; a type may satisfy it and one_shot_transformer both.
Template Parameters
| Name | Description |
|---|---|
T |
The type to check. |
webcpp::codecs::buffered<T>
Deduces buffered<T>, the heap form with std::allocator, from buffered(transformer).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<class T>
buffered<T>(T) -> buffered<T>;
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
webcpp::codecs::buffered<T, Allocator>
Deduces buffered<T, Allocator>, the heap form with the allocator, from buffered(transformer, allocator).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
class T,
class Allocator>
buffered<T, Allocator>(
T,
Allocator) -> buffered<T, Allocator>;
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
Allocator |
The allocator’s type. |
webcpp::codecs::buffered<T, capacity_t<N>>
Deduces buffered<T, capacity_t<N>>, the form in place, from buffered(transformer, codecs::capacity<N>).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
class T,
std::size_t N>
buffered<T, capacity_t<N>>(
T,
capacity_t<N>) -> buffered<T, capacity_t<N>>;
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
N |
The capacity, in elements. |
webcpp::codecs::each<T>
Deduces each<T>, the heap form with std::allocator, from each(transformer).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
webcpp::codecs::each<T, Allocator>
Deduces each<T, Allocator>, the heap form with the allocator, from each(transformer, allocator).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
class T,
class Allocator>
each<T, Allocator>(
T,
Allocator) -> each<T, Allocator>;
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
Allocator |
The allocator’s type. |
webcpp::codecs::each<T, capacity_t<N>>
Deduces each<T, capacity_t<N>>, the form in place, from each(transformer, codecs::capacity<N>).
Synopsis
Declared in <webcpp/codecs/detail/core/adapters.hpp>
template<
class T,
std::size_t N>
each<T, capacity_t<N>>(
T,
capacity_t<N>) -> each<T, capacity_t<N>>;
Template Parameters
| Name | Description |
|---|---|
T |
The one-shot transformer’s type. |
N |
The capacity, in elements. |
webcpp::codecs::over<Outer, Inner>
Deduces over<Outer, Inner> from the two links.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template<
class Outer,
class Inner>
over<Outer, Inner>(
Outer,
Inner) -> over<Outer, Inner>;
Template Parameters
| Name | Description |
|---|---|
Outer |
The outer link’s type. |
Inner |
The inner link’s type. |
webcpp::codecs::over<Outer, Inner, Allocator>
Deduces over<Outer, Inner, Allocator> from the two links and the allocator of the heap intermediate.
Synopsis
Declared in <webcpp/codecs/detail/core/over.hpp>
template<
class Outer,
class Inner,
class Allocator>
over<Outer, Inner, Allocator>(
Outer,
Inner,
Allocator) -> over<Outer, Inner, Allocator>;
Template Parameters
| Name | Description |
|---|---|
Outer |
The outer link’s type. |
Inner |
The inner link’s type. |
Allocator |
The allocator’s type. |
WEBCPP_CODECS_NO_EXCEPTIONS
Defined when codecs is built without exceptions: when webcpp has none (the compiler has none, or the developer defined WEBCPP_NO_EXCEPTIONS for every webcpp library), or when the developer defines it alone, to disable codecs’ in a build that has them.
Description
codecs reports every failure as an error code, so the macro changes nothing in what a function returns. It is provided so that a program can set it for every webcpp library alike.
Appendix A: 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.
Unreleased
-
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 and zbase32.hpp: base32 and base32hex of RFC 4648, padding an option, and z-base-32, pkarr’s keys, 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, with basic_armor for a label in the type.
-
Added the guide, with its examples built and run on every target.