Boost logo

Boost :

From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-10-30 07:38:07


Just picked up the crypto lib from the vault (at least the sha1 and
md5 parts). There was one issue with the to_string() member function
of message_digest. It uses snprintf which isn't readily available in
MSVC (vs 2005 at least) so I rewrote it using some bit twiddling:

template<class Context>
std::string message_digest<Context>::to_string() const
{
  static const char hex_digit[] =
{'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  char buf[context_type::digest_length * 2];

  for (int i = 0; i < context_type::digest_length; ++i) {
        buf[2*i] = hex_digit[((static_cast<const unsigned
char*>(digest())[i])&0xf0)>>4];
        buf[2*i+1] = hex_digit[((static_cast<const unsigned
char*>(digest())[i])&0x0f)];
  }
  return std::string(buf, context_type::digest_length * 2);
}

This works at least for both vs 2005 and gcc 4.1.1, ymmv

Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk