CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  }
16 
17  namespace hash_detail {
20  if (isCompactForm_(hash)) {
21  return hash;
22  }
23  value_type temp(hash);
24  fixup_(temp);
25  return temp;
26  }
27 
28  // 'Fix' the string data member of this Hash, i.e., if it is in
29  // the hexified (32 byte) representation, make it be in the
30  // 16-byte (unhexified) representation.
31  void
33  switch (hash.size()) {
34  case 16: {
35  break;
36  }
37  case 32: {
39  temp.fromHexifiedString(hash);
40  hash = temp.compactForm();
41  break;
42  }
43  case 0: {
45  << "Empty edm::Hash<> instance:\n" << "\nPlease report this to the core framework developers";
46  }
47  default: {
49  << "edm::Hash<> instance with data in illegal state:\n"
50  << hash
51  << "\nPlease report this to the core framework developers";
52  }
53  }
54  }
55 
56  size_t
58  //NOTE: In future we could try to xor the first 8bytes into the second 8bytes of the string to make the hash
59  std::hash<std::string> h;
60  if (hash.size()==16) {
61  return h(hash);
62  }
63  return h(compactForm_(hash));
64  }
65 
66  bool
68  return 16 == hash.size();
69  }
70 
71  bool
73  return isCompactForm_(hash) ? (hash != detail::InvalidHash()) : (!hash.empty());
74  }
75 
76  void
78  // Fixup not needed here.
79  if (hash.size() % 2 == 1) {
81  << "Ill-formed Hash instance. "
82  << "Please report this to the core framework developers";
83  }
84  }
85 
86  void
88  value_type temp1(hash);
89  fixup_(temp1);
91  copy_all(temp1, temp.bytes);
92  result += temp.toString();
93  }
94 
95  void
96  toDigest_(cms::Digest& digest, value_type const& hash) {
97  // FIXME: do we really need to go through a temporary value_type???
98  value_type temp1(hash);
99  fixup_(temp1);
101  copy_all(temp1, temp.bytes);
102  digest.append(temp.toString());
103  }
104 
105  std::ostream&
106  print_(std::ostream& os, value_type const& hash) {
107  value_type temp1(hash);
108  fixup_(temp1);
110  copy_all(temp1, temp.bytes);
111  os << temp.toString();
112  return os;
113  }
114  }
115 }
void toDigest_(cms::Digest &digest, value_type const &hash)
Definition: Hash.cc:96
bool isCompactForm_(value_type const &hash)
Definition: Hash.cc:67
bool isValid_(value_type const &hash)
Definition: Hash.cc:72
void fixup_(value_type &hash)
Definition: Hash.cc:32
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:106
void toString_(std::string &result, value_type const &hash)
Definition: Hash.cc:87
unsigned char bytes[16]
Definition: Digest.h:21
void fromHexifiedString(std::string const &s)
Definition: Digest.cc:111
size_t smallHash_(value_type const &hash)
Definition: Hash.cc:57
std::string const & InvalidHash()
Definition: Hash.cc:11
std::string value_type
Definition: Hash.h:29
value_type compactForm_(value_type const &hash)
Definition: Hash.cc:19
std::string compactForm() const
Definition: Digest.cc:102
tuple result
Definition: query.py:137
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
std::string toString() const
Definition: Digest.cc:87
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:24
void throwIfIllFormed(value_type const &hash)
Definition: Hash.cc:77
void append(std::string const &s)
Definition: Digest.cc:182