brace is a general-purpose C++ library, made up of classes and functions that I have found useful. It is very much a work in progress and I will be adding to the library from time to time. My hope is that you will find it useful as well.
The core library is header-only and I expect the core to remain header-only.
brace is written using Modern C++, which is to say C++17. It's 2023 and most compiler vendors by now have excellent support for C++17. brace is a new library and I have no intention of modifying brace to support older versions of the language.
Currently there is nothing to build, as brace is header-only. You only need to copy the include/brace
directory to somewhere your compiler can find it and #include
the appropriate header files in your project's source files.
The classes and function in the brace library are contained within the brace
namespace, so you will need to preface usage with the namespace name, as in
brace::Base64Url encoder;
Classes are named using Pascal casing, as in MyClass
. Function names, both free functions and member functions, are named using snake casing, as in my_function
.
brace is composed of a number of classes and functions implementing things such as:
- Bit twiddling
- Byte order (endianness)
- A FILE abstraction
- Various hash algorithms
- Base 32/64 encoding
- Binary streams
brace provides functions for setting, clearing, flipping, and testing individual bits within values, as well as rotating bits left and right. Include the file brace/bits.h
to access these functions.
brace provides functions for swapping bytes for various endianness, as well as enum class Endian
. Include the file brace/byteorder.h
to access these functions.
brace provides a wrapper class around the FILE
structure used in C
file I/O. Include the file brace/file.h
to use the File
class.
brace provides classes for several hashing algorithms.
The MD5 hash algorithm produces a 128-bit hash. To use the MD5
class, include brace/md5.h
.
The SHA-1 hash algorithm produces a 160-bit hash. The SHA1
class is defined in the header brace/sha1.h
.
The SHA-224 and SHA-256 hash algorithms produce 224-bit and 256-bit hashes respectively. The SHA224
and SHA256
classes are defined in brace/sha2.h
.
The SHA-384 and SHA-512 hash algorithms produce 384-bit and 512-bit hashes respectively. The SHA384
and SHA512
classes are defined in brace/sha2.h
.
brace provides classes for Base32, Base32-Hex, Base64, and Base64-URL encoding and decoding as described in RFC-4648. The Base32
and Base32Hex
classes are defined in the header brace/base32.h
. The Base64
and Base64Url
classes are defined in brace/base64.h
.
brace offers classes for handling binary data streams. These classes function similarly to the standard stream classes, but operate on binary data rather than formatted data. Overloads of operators >>
and <<
are provided for extracting and inserting data of fundamental types from and into binary streams. The classes understand endianness and can byte-swap data as needed.
Classes are provided for operating on binary data in files and in fixed-length arrays.
The header brace/binfstream.h
defines the following classes for operating on binary data in files:
BinIFStream
for reading binary data from a fileBinOFStream
for writing binary data to a file.BinFStream
for both reading and writing binary data from and to a file.
The header brace/binastream.h
defines these classes for operating on binary data in fixed-length arrays
BinIArrayStream
for reading binary data from a fixed-length arrayBinOArrayStream
for writing binary data to a fixed-length arrayBinArrayStream
for reading a writing binary data from and to a fixed-length array.