libmoost
/home/mhx/git/github/libmoost/src/digest/base.cpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 #include <boost/cstdint.hpp>
00029 
00030 #include "../../include/moost/digest/base.h"
00031 
00032 namespace moost { namespace digest {
00033 
00034 namespace {
00035    const char hexchars[] = "0123456789abcdef";
00036 }
00037 
00038 base::~base()
00039 {
00040 }
00041 
00042 std::string base::hexdigest() const
00043 {
00044    const std::string& bin = digest();
00045    std::string hex;
00046    hex.resize(2*bin.size());
00047    for (size_t i = 0; i < bin.size(); ++i)
00048    {
00049       const boost::uint8_t byte = static_cast<boost::uint8_t>(bin[i]);
00050       hex[2*i + 0] = hexchars[(byte >> 4) & 0xF];
00051       hex[2*i + 1] = hexchars[(byte >> 0) & 0xF];
00052    }
00053    return hex;
00054 }
00055 
00056 }}