LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Hash.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 #include "cetlib/MD5Digest.h"
4 #include "cetlib/container_algorithms.h"
5 
6 namespace {
7  std::string const invalid{cet::MD5Result{}.compactForm()};
8 }
9 
10 namespace art::detail {
11  void
12  fixup(std::string& hash)
13  {
14  if (hash.size() == 16) {
15  // Already in compact form.
16  return;
17  }
18  if (hash.size() == 0) {
19  hash = art::detail::InvalidHash();
20  return;
21  }
22  if (hash.size() == 32) {
23  cet::MD5Result md5;
24  md5.fromHexifiedString(hash);
25  hash = md5.compactForm();
26  return;
27  }
29  << "art::Hash<> instance with data in illegal state:\n"
30  << hash << "\nPlease report this to the core framework developers";
31  }
32 
33  std::string
34  hash_to_string(std::string const& hash)
35  {
36  cet::MD5Result temp;
37  cet::copy_all(hash, temp.bytes);
38  return temp.toString();
39  }
40 
41  // This string is the 16-byte, non-printable version.
42  std::string const&
44  {
45  return invalid;
46  }
47 }
std::string const & InvalidHash()
Definition: Hash.cc:43
std::string hash_to_string(std::string const &hash)
Definition: Hash.cc:34
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void fixup(std::string &hash)
Definition: Hash.cc:12