.TH "FBB::Digestbuf" "3bobcat" "2005\-2016" "libbobcat\-dev_4\&.04\&.00\-x\&.tar\&.gz" "Compute Message Digests" .PP .SH "NAME" FBB::Digestbuf \- Computes Message Digests from information inserted into a std::ostream .PP .SH "SYNOPSIS" \fB#include \fP .br Linking option: \fI\-lbobcat\fP .PP .SH "DESCRIPTION" \fBFBB::Digestbuf\fP objects are \fBstd::streambuf\fP objects that can be used to initialize \fIstd::ostream\fP objects with\&. .PP All information inserted into such a \fIstd::ostream\fP is used to compute a message digest from\&. .PP All the message digests defined by the OpenSSL library that can be selected by name may be used in combination with \fIDigestBuf\fP objects\&. .PP The following message digest algorithms are currently supported: mull, md2, md5, sha, sha1, sha224, sha256, sha384, sha512, dss, dss1, ecdsa, mdc2, ripemd160\&. These very names are the ones to use to select the particular digest algorithms for the class\(cq\&s constructor, below\&. It is quite possible that future releases of the openssl library will support additional message digest algorithms\&. The header file \fIopenssl/evp\&.h\fP lists all available digest algorithms (in that file look for \fIEVP_MD *EVP_\fP: a message digest algorithm immediately follows the 2nd underscore\&. E\&.g\&., \fIconst EVP_MD *EVP_md4(void)\fP which refers to the md4 message digest algorithm)\&. .PP .SH "NAMESPACE" \fBFBB\fP .br All constructors, members, operators and manipulators, mentioned in this man\-page, are defined in the namespace \fBFBB\fP\&. .PP .SH "INHERITS FROM" \fBstd::streambuf\fP .PP .SH "CONSTRUCTORS" .IP o \fBDigestbuf(char const *type, size_t bufsize = 1024)\fP: .br This constructor initializes the streambuf, setting it up for the message digest algorithm specified with \fItype\fP\&. The message digest algorithms specified in the \fBDESCRIPTION\fP section may be used here\&. E\&.g\&., to use the sha256 algorithm specify \fI\(dq\&sha256\(dq\&\fP\&. .IP The \fIbufsize\fP argument specifies the internal buffer used by \fIDigestbuf\fP to store incoming characters temporarily\&. The provided default argument should be OK in all normal cases\&. There is no copy constructor\&. .PP .SH "OVERLOADED OPERATOR" .PP .IP o \fBstd::ostream &operator<<(std::ostream &out, DigestBuf const &digestbuf)\fP: .br The insertion operator is a free function defined in the namespace \fIFBB\fP\&. It inserts a hash value as a series of hexadecimally displayed values into the provided \fIostream\fP\&. See the example below for an illustration\&. The overloaded assignment operator is not available\&. .PP .SH "MEMBER FUNCTIONS" .PP All members of \fBstd::streambuf\fP are available, as \fBFBB::Digestbuf\fP inherits from this class\&. Some of the \fBstd::streambuf\fP\(cq\&s member are overridden or are hidden by \fIDigestbuf\fP\&. In normal situations these inherited members will not be used by programs using \fIDigestBuf\fP objects\&. .PP .IP o \fBvoid close()\fP: .br This member finishes the computation of the message digest computation\&. It is needed as the \fIDigestBuf\fP object has no external means for deciding whether all information to compute the digest for has yet been received or not\&. The general approach to follow when computing a message digest is therefore: .nf create a DigestBuf object use it to create a std::ostream object insert information into the ostream object call the DigestBuf object\(cq\&s close() member obtain/process the hash value from the DigestBuf object\&. .fi .IP o \fBstd::string const &hash() const\fP: .br This member returns the hash value computed by the \fIDigestBuf\fP object\&. Its value is only defined after having called \fIclose()\fP\&. The hash value is returned in a \fIstd::string\fP object\&. This string\(cq\&s \fIlength()\fP member contains the number of characters used by the hash value, and its \fIdata()\fP member refers to the hash value\(cq\&s characters\&. Note that a hash value\(cq\&s character value may be 0 (not to be confused with \fI\(cq\&0\(cq\&\fP)\&. .IP o \fBvoid open()\fP: .br This member reinitializes the message digest computation\&. One a message digest has been computed for, say a stream \fIstreamA\fP this member can be called after which the digest for a stream \fIstreamB\fP can be computed using the same \fIDigestBuf\fP object\&. .PP .SH "EXAMPLE" .nf #include #include #include #include using namespace std; using namespace FBB; int main(int argc, char **argv) try { DigestBuf digestbuf(argv[1]); ostream out(&digestbuf); string hw(\(dq\&hello world\en\(dq\&); out << hw; digestbuf\&.close(); cout << \(dq\&>\(dq\& << digestbuf << \(dq\&<\(dq\& << endl; digestbuf\&.open(); out\&.write(hw\&.c_str(), hw\&.length()); digestbuf\&.close(); cout << \(dq\&>\(dq\& << digestbuf << \(dq\&<\(dq\& << endl; } catch(exception const &err) { cout << err\&.what() << endl; return 1; } .fi .PP .SH "FILES" \fIbobcat/digestbuf\fP \- defines the class interface .PP .SH "SEE ALSO" \fBbobcat\fP(7), \fBhmacbuf\fP(3bobcat), \fBstd::streambuf\fP .PP .SH "BUGS" None reported .PP .SH "DISTRIBUTION FILES" .IP o \fIbobcat_4\&.04\&.00\-x\&.dsc\fP: detached signature; .IP o \fIbobcat_4\&.04\&.00\-x\&.tar\&.gz\fP: source archive; .IP o \fIbobcat_4\&.04\&.00\-x_i386\&.changes\fP: change log; .IP o \fIlibbobcat1_4\&.04\&.00\-x_*\&.deb\fP: debian package holding the libraries; .IP o \fIlibbobcat1\-dev_4\&.04\&.00\-x_*\&.deb\fP: debian package holding the libraries, headers and manual pages; .IP o \fIhttp://sourceforge\&.net/projects/bobcat\fP: public archive location; .PP .SH "BOBCAT" Bobcat is an acronym of `Brokken\(cq\&s Own Base Classes And Templates\(cq\&\&. .PP .SH "COPYRIGHT" This is free software, distributed under the terms of the GNU General Public License (GPL)\&. .PP .SH "AUTHOR" Frank B\&. Brokken (\fBf\&.b\&.brokken@rug\&.nl\fP)\&. .PP