FBB::HMacBuf(3bobcat)
β¨ FBB::HMacBuf β¨
okay so bestie, welcome to the manual page for FBB::HMacBuf, straight outta section 3bobcat β the part of the manual where the C++ library pages live. grab a snack, this one's cute π
NAME
FBB::HMacBuf β computes HMAC Message Digests from information inserted into a std::ostream π
SYNOPSIS
#include <bobcat/hmacbuf>
Linking option: -lbobcat -lcrypto
DESCRIPTION
FBB::HMacBuf objects are std::streambuf objects, and the whole point of them is that you can use one to initialize a std::ostream object with it. that's the vibe π
everything you insert into such a std::ostream? yeah, all of it gets used to compute a message HMAC. every last byte. no cap.
every message digest and cipher algorithm that the OpenSSL library defines and that can be selected by name is fair game here β you can use any of them in combination with HMacBuf objects. the way that flexibility is just iconic tbh.
wanna see which message digest algorithms are currently supported? run:
openssl list -digest-commands
wanna see which message cipher algorithms are currently supported? run:
openssl list -cipher-commands
and here's the tea on defaults: the defaults used by HMacBuf constructors are the sha256 digest algorithm and the aes-128-cbc cipher algorithm. periodt π
NAMESPACE
FBB
all constructors, members, operators and manipulators mentioned in this man-page are defined in the namespace FBB. so bestie, that's where you'll find them π«Ά
INHERITS FROM
std::streambuf
CONSTRUCTORS
HMacBuf()β the default constructor defines aHmacBufobject. you can use it once a non-default constructedHMacBufobject has been move-assigned to it πΈHMacBuf(HMacBuf &&tmp)β the move constructor initializes aHmacBufobject by movingtmpinto the currentHMacBufobject β¨HMacBuf(std::string const &key, char const *digest, size_t bufsize)β this constructor initializes the streambuf, setting it up for the message digest algorithm specified withdigest. like, to use thesha256algorithm you specify"sha256". easy π
the constructor's first argument defines the key to be used when computing the HMAC message digest. and listen β the key's length must be 16 characters. an exception is thrown if an empty key is specified π
the bufsize argument specifies the size (in bytes) of the internal buffer used by HMacBuf to store incoming characters temporarily. a value of 1024 should be OK for all normal cases π
HMacBuf(std::string const &key, char const *cipher = "aes-128-cbc", char const *digest = "sha256", size_t bufsize = 1024)β like the previous constructor, but this one offers defaults for the cipher and digest algorithms and the buffer size. when specifying another cipher algorithm the key length must match the cipher requirement. usually the cipher's name contains a number (like128), which can be divided by 8 to obtain the required key length of fixed-key length ciphers. math girlies stay winning π§
OVERLOADED OPERATOR
HMacBuf &operator=(HMacBuf &&rhs)β the move assignment operator moves therhsHMacBufobject into the current object π«std::ostream &operator<<(std::ostream &out, HMacBuf const &hmacbuf)β the insertion operator is a free function defined in the namespaceFBB. it inserts a hash value as a series of hexadecimally displayed values into the provided ostream. see the example below for an illustration π
MEMBER FUNCTIONS
all members of std::streambuf are available, as FBB::HMacBuf inherits from this class. so you're not losing anything, you're gaining π
std::string const &hash() constβ this member returns the hash value computed by theHMacBufobject. heads up though: its value is only defined after having calledclose(). the hash value is returned in astd::stringobject. this string'slength()member contains the number of characters used by the hash value, and itsdata()member refers to the hash value's characters. note that a hash value's character value may be0(not to be confused with'0'). yes, those are different things and it matters π
when called from a default constructed HMacBuf object an empty string is returned.
void reset()β this member reinitializes the message hmac computation. once a message hmac has been computed for, say, a streamstreamA, this member can be called after which the hmac for a streamstreamBcan be computed using the sameHMacBufobject. reuse era π
no action is performed when called from a default constructed HMacBuf object.
void eoi()β this member can be called to complete the message digest computation. instead of calling this member theeoimanipulator (see below) can be used. two paths, same destination, slay β¨
MANIPULATOR
FBB::eoiβ theeoimanipulator can be inserted into the ostream to complete the digest computation. if it is inserted into a plainstd::ostreamnothing happens. literally nothing. it's fine π
eoi can also be called as a function, receiving the stream that uses the HMacBuf as its streambuf, but it must be called either way, because the HMacBuf object itself cannot decide whether all information to compute the digest for has yet been received or not. it's not psychic, bestie, you have to tell it π
the general approach for computing a message hmac is therefore:
- create a
HMacBufobject - use it to create a
std::ostreamobject - insert information into the ostream object
- call the
HMacBufobject'seoi()member or inserteoiinto the ostream object - obtain/process the hash value from the
HMacBufobject.
EXAMPLE
#include <fstream>
#include <iostream>
#include <bobcat/hmacbuf>
using namespace std;
using namespace FBB;
int main(int argc, char **argv)
try
{
// using the default (sha256) digest algorithm
if (argc == 1)
throw Exception{} <<
"Usage: arg1: 16-byte key, arg2: file to process,\n"
" arg3 (opt) buf size (default 1024)";
HMacBuf hmacbuf{ argv[1], "aes-128-cbc", "sha256",
argc == 3 ? 1024 : stoul(argv[3]) };
HMacBuf empty; // Demo: an empty HMacBuf
empty = HMacBuf{ argv[1], "sha256", 100 }; // Demo: move assignmeent
ostream out(&hmacbuf); // the ostream receiving the
// input to compute the hmac of
ifstream in{ argv[2] }; // the file to process
out << in.rdbuf() << eoi; // compute the hmac
// and show the hmac value
cout << " computed hmac value: >" << hmacbuf << "<\n";
in.seekg(0); // to illustrate βresetβ: do it
hmacbuf.reset(); // again
out << in.rdbuf();
eoi(out); // calling eoi as a function
cout << "recomputed hmac value: >" << hmacbuf << "<\n";
}
catch(exception const &err)
{
cout << err.what() << endl;
return errno;
}
FILES
bobcat/hmacbuf β defines the class interface π
SEE ALSO
bobcat(7), digestbuf(3bobcat), std::streambuf πΈ
BUGS
none reported. we love a clean record π
BOBCAT PROJECT FILES
https://fbb-git.gitlab.io/bobcat/: gitlab project page;
Debian Bobcat project files:
libbobcat6: debian package containing the shared library, changelog and copyright note;libbobcat-dev: debian package containing the static library, headers, manual pages, and developer info;
bestie, that's one package for running it and one for building against it. both iconic π«Ά
BOBCAT
Bobcat is an acronym of `Brokkenβs Own Base Classes And Templatesβ. acronym reveal moment π€―
COPYRIGHT
this is free software, distributed under the terms of the GNU General Public License (GPL). free as in freedom, fr fr π
AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). thank you for your service π
and that's the whole page, bestie!! this one came out of libbobcat-dev_6.15.01, dated 2005-2026, and yes it's still FBB::HMacBuf(3bobcat) at heart π
β¨ go compute some HMACs, you've got this π¦
π¦ where this page comes from
- ubuntu stonking: libbobcat-dev 6.15.01-1 Β· GPL-3.0-or-later WITH OpenSSL exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms