The message digest of all information inserted into such an std::ostream is computed.
All the message digests defined by the OpenSSL library that can be selected by name may be used in combination with DigestBuf objects.
The currently supported message digest algorithms are shown by the openssl list -digest-commands. The names of the digest algorithms can be used to select a digest algorithms for the class's constructor, below.
The bufsize argument specifies the size of the internal buffer used by DigestBuf to store incoming characters temporarily. The provided default argument should be OK in all normal cases.
The copy and move constructors and assignment operators are not available.
All members of std::streambuf are available, as FBB::DigestBuf inherits from this class.
1. create a DigestBuf object 2. use it to create a std::ostream object 3. insert information into the ostream object 4. call the DigestBuf object's eoi() member or insert the eoi manipulator into the ostream (see below) 5. obtain/process the hash value from the DigestBuf object.
#include <iostream> #include <ostream> #include <bobcat/digestbuf> using namespace std; using namespace FBB; int main(int argc, char **argv) try { DigestBuf digestbuf(argc == 1 ? "sha256" : argv[1]); ostream out(&digestbuf); string hw("hello world\n"); out << hw << eoi; cout << ">" << digestbuf << "<" << endl; digestbuf.reset(); out.write(hw.c_str(), hw.length()) << eoi; cout << ">" << digestbuf << "<" << endl; } catch(exception const &err) { cout << err.what() << endl; return 1; }