CMS 3D CMS Logo

Hash.cc
Go to the documentation of this file.
5 
6 #include <functional>
7 
8 namespace edm {
9  namespace detail {
10  // This string is the 16-byte, non-printable version.
12  static std::string const invalid = cms::MD5Result().compactForm();
13  return invalid;
14  }
15  } // namespace detail
16 
17  namespace hash_detail {
19  if (isCompactForm_(hash)) {
20  return hash;
21  }
23  fixup_(temp);
24  return temp;
25  }
26 
27  // 'Fix' the string data member of this Hash, i.e., if it is in
28  // the hexified (32 byte) representation, make it be in the
29  // 16-byte (unhexified) representation.
31  switch (hash.size()) {
32  case 16: {
33  break;
34  }
35  case 32: {
37  temp.fromHexifiedString(hash);
38  hash = temp.compactForm();
39  break;
40  }
41  case 0: {
42  throw Exception(errors::LogicError) << "Empty edm::Hash<> instance:\n"
43  << "\nPlease report this to the core framework developers";
44  }
45  default: {
46  throw Exception(errors::LogicError) << "edm::Hash<> instance with data in illegal state:\n"
47  << hash << "\nPlease report this to the core framework developers";
48  }
49  }
50  }
51 
52  size_t smallHash_(value_type const& hash) {
53  //NOTE: In future we could try to xor the first 8bytes into the second 8bytes of the string to make the hash
54  std::hash<std::string> h;
55  if (hash.size() == 16) {
56  return h(hash);
57  }
58  return h(compactForm_(hash));
59  }
60 
61  bool isCompactForm_(value_type const& hash) { return 16 == hash.size(); }
62 
63  bool isValid_(value_type const& hash) {
64  return isCompactForm_(hash) ? (hash != detail::InvalidHash()) : (!hash.empty());
65  }
66 
68  // Fixup not needed here.
69  if (hash.size() % 2 == 1) {
70  throw Exception(errors::LogicError) << "Ill-formed Hash instance. "
71  << "Please report this to the core framework developers";
72  }
73  }
74 
76  value_type temp1(hash);
77  fixup_(temp1);
79  copy_all(temp1, temp.bytes.begin());
80  result += temp.toString();
81  }
82 
83  void toDigest_(cms::Digest& digest, value_type const& hash) {
84  // FIXME: do we really need to go through a temporary value_type???
85  value_type temp1(hash);
86  fixup_(temp1);
88  copy_all(temp1, temp.bytes.begin());
89  digest.append(temp.toString());
90  }
91 
92  std::ostream& print_(std::ostream& os, value_type const& hash) {
93  value_type temp1(hash);
94  fixup_(temp1);
96  copy_all(temp1, temp.bytes.begin());
97  os << temp.toString();
98  return os;
99  }
100  } // namespace hash_detail
101 } // namespace edm
void toDigest_(cms::Digest &digest, value_type const &hash)
Definition: Hash.cc:83
bool isCompactForm_(value_type const &hash)
Definition: Hash.cc:61
bool isValid_(value_type const &hash)
Definition: Hash.cc:63
void fixup_(value_type &hash)
Definition: Hash.cc:30
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:92
void toString_(std::string &result, value_type const &hash)
Definition: Hash.cc:75
size_t smallHash_(value_type const &hash)
Definition: Hash.cc:52
std::string value_type
Definition: Hash.h:30
value_type compactForm_(value_type const &hash)
Definition: Hash.cc:18
std::string compactForm() const
Definition: Digest.cc:109
HLT enums.
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
std::string const & InvalidHash()
Definition: Hash.cc:11
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void throwIfIllFormed(value_type const &hash)
Definition: Hash.cc:67
void append(std::string const &s)
Definition: Digest.cc:161