[crypto] remove snprintf in message_digest::to_string() for msvc

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

Hello Chris!
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:
Actually it uses sprintf, not snprintf. It's possible that the old msvc lib does not promote sprintf to the std namespace so it will not find the std::sprintf() call. I could simply add a using namespace std. I will consider your version though since it should be faster. Kevin
participants (2)
-
Chris Fairles
-
Kevin Sopp