Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2024-03-19 20:55:31


On 3/19/24 20:46, Ruben Perez via Boost wrote:
> Hi all,
>
> I've been thinking of writing a base64 encoder/decoder library for
> some time. I first found the need when writing ServerTech chat
> (https://github.com/anarthal/servertech-chat), and I couldn't find a
> library that suited my needs. All the libraries I could find were
> either forgotten one-day projects with no tests, or private parts of
> something bigger.
>
> From this issue from Beast
> (https://github.com/boostorg/beast/issues/1710) it looks like this
> could be useful to people.
>
> My idea would be writing something that is:
> * Boost quality - extensive testing and fuzzing.
> * Configurable. My use case in ServerTech required me to not output
> padding chars, for instance.
> * Support for a streaming API.
> * Support for calling in a constexpr context.
> * I'd prefer to focus on doing base64 only and doing it well, rather
> than targeting arbitrary bases.
>
> I don't have any sample code yet. Following our recommendations, I'm
> only determining interest. My questions are:
> * Do you think a library like this could be useful to the C++ community?

I think, a BaseN library (with N being at least 16 and 64) with high
performance (i.e. with SIMD support) and configurability would be
useful. The particular points of configuration and capabilities I'm
interested in:

- Character set. For Base16 - upper or lower-case letters. For Base64 -
normal or URL-safe[1] character set.
- For Base64, whether to include trailing padding on encoding.
- For decoding, support error indication via exception or an error code.
- Support output into an externally provided buffer. This also implies
that the library must provide means to estimate the size of that buffer
for a given input. Support for output in unallocated buffer (e.g. via
std::back_inserter) is also welcome, but not a strong requirement.
- Zero allocation, context-less mode. I.e. a function taking inputs and
outputs and doing the whole job in one go.

I have my own implementation in my project, and having a well-tested
Boost library with these capabilities, I think, would be useful.

> * If the answer to the above is yes, do you think it could belong to
> Boost, or would be better as a standalone library?

I would be interested in a Boost library, not a standalone version.

There are plenty implementations out there (for example, in OpenSSL), so
the proposed library will need to have a comparison, including
performance, with popular alternatives in the docs.

[1]: https://datatracker.ietf.org/doc/html/rfc4648#section-5


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk