Public Member Functions | Public Attributes | List of all members
cet::MD5Result Struct Reference

#include <MD5Digest.h>

Public Member Functions

 MD5Result ()
 
std::string toString () const
 
std::string compactForm () const
 
void fromHexifiedString (std::string const &s)
 
bool isValid () const
 

Public Attributes

unsigned char bytes [16]
 

Detailed Description

Definition at line 17 of file MD5Digest.h.

Constructor & Destructor Documentation

cet::MD5Result::MD5Result ( )

Definition at line 42 of file MD5Digest.cc.

42 { set_to_default(*this); }
void set_to_default(MD5Result &val)
Definition: MD5Digest.cc:22

Member Function Documentation

std::string cet::MD5Result::compactForm ( ) const

Definition at line 68 of file MD5Digest.cc.

69  {
70  // This is somewhat dangerous, because the conversion of 'unsigned
71  // char' to 'char' may be undefined if 'char' is a signed type
72  // (4.7p3 in the Standard).
73  const char* p = reinterpret_cast<const char*>(&bytes[0]);
74  return std::string(p, p + sizeof(bytes));
75  }
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
unsigned char bytes[16]
Definition: MD5Digest.h:24
void cet::MD5Result::fromHexifiedString ( std::string const &  s)

Definition at line 78 of file MD5Digest.cc.

79  {
80  switch (hexy.size()) {
81  case 0: {
82  set_to_default(*this);
83  } break;
84  case 32: {
85  std::string const chars = cet::nybbler(hexy).as_char();
86  std::string::const_iterator it = chars.begin();
87  for (size_t i = 0; i != 16; ++i)
88  bytes[i] = *it++;
89  } break;
90  default: {
91  throw "String of illegal length given to MD5Result::fromHexifiedString";
92  }
93  }
94  }
std::string string
Definition: nybbler.cc:12
intermediate_table::const_iterator const_iterator
void set_to_default(MD5Result &val)
Definition: MD5Digest.cc:22
unsigned char bytes[16]
Definition: MD5Digest.h:24
string as_char() const
Definition: nybbler.cc:31
bool cet::MD5Result::isValid ( ) const

Definition at line 97 of file MD5Digest.cc.

98  {
99  return (*this != invalidResult());
100  }
std::string cet::MD5Result::toString ( ) const

Definition at line 45 of file MD5Digest.cc.

46  {
47  // Note: The code used to be this:
48  //
49  // std::ostringstream os;
50  // os << std::hex << std::setfill('0');
51  // for (size_t i = 0; i < sizeof(bytes); ++i)
52  // os << std::setw(2) << static_cast<int>(bytes[i]);
53  // return os.str();
54  //
55  // However profiling shows that this causes a measurable slowdown.
56  // The following code does the same thing, but is much faster.
57  constexpr char hex_bytes[] = "0123456789abcdef";
58  std::string ret;
59  ret.resize(sizeof(bytes) << 1);
60  for (size_t i = 0; i < sizeof(bytes); ++i) {
61  ret[i << 1] = hex_bytes[bytes[i] >> 4];
62  ret[(i << 1) + 1] = hex_bytes[bytes[i] & 0x0F];
63  }
64  return ret;
65  }
std::string string
Definition: nybbler.cc:12
unsigned char bytes[16]
Definition: MD5Digest.h:24

Member Data Documentation

unsigned char cet::MD5Result::bytes[16]

Definition at line 24 of file MD5Digest.h.


The documentation for this struct was generated from the following files: