irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_hasher_factory.cpp
Go to the documentation of this file.
2 #include "checksum.hpp"
3 #include "MD5Strategy.hpp"
4 #include "SHA256Strategy.hpp"
5 #include "rodsErrorTable.h"
6 #include <sstream>
7 #include <boost/unordered_map.hpp>
8 
9 namespace irods {
10 
11  namespace {
12  const SHA256Strategy _sha256;
13  const MD5Strategy _md5;
14 
15  boost::unordered_map<const std::string, const HashStrategy*>
16  make_map() {
17  boost::unordered_map<const std::string, const HashStrategy*> map;
18  map[ SHA256_NAME ] = &_sha256;
19  map[ MD5_NAME ] = &_md5;
20  return map;
21  }
22 
23  const boost::unordered_map<const std::string, const HashStrategy*> _strategies( make_map() );
24  };
25 
26  error
27  getHasher( const std::string& _name, Hasher& _hasher ) {
28  boost::unordered_map<const std::string, const HashStrategy*>::const_iterator it = _strategies.find( _name );
29  if ( _strategies.end() == it ) {
30  std::stringstream msg;
31  msg << "Unknown hashing scheme [" << _name << "]";
32  return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
33  }
34  _hasher.init( it->second );
35  return SUCCESS();
36  }
37 
38  error
40  const std::string& _chksum,
41  std::string& _scheme ) {
42  if ( _chksum.empty() ) {
43  return ERROR(
45  "empty chksum string" );
46  }
47  for ( boost::unordered_map<const std::string, const HashStrategy*>::const_iterator it = _strategies.begin();
48  _strategies.end() != it; ++it ) {
49  if ( it->second->isChecksum( _chksum ) ) {
50  _scheme = it->second->name();
51  return SUCCESS();
52  }
53  }
54  return ERROR(
56  "hash scheme not found" );
57 
58  } // get_hasher_scheme_from_checksum
59 
60 }; // namespace irods
61 
62 
irods::SHA256_NAME
const std::string SHA256_NAME("sha256")
irods::getHasher
error getHasher(const std::string &name, Hasher &hasher)
Definition: irods_hasher_factory.cpp:27
checksum.hpp
irods::get_hash_scheme_from_checksum
error get_hash_scheme_from_checksum(const std::string &checksum, std::string &scheme)
Definition: irods_hasher_factory.cpp:39
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods
Definition: apiHandler.hpp:35
irods::Hasher
Definition: Hasher.hpp:15
irods::Hasher::init
error init(const HashStrategy *)
Definition: Hasher.cpp:13
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
error
int error
Definition: filesystem.cpp:101
irods_hasher_factory.hpp
irods::MD5_NAME
const std::string MD5_NAME("md5")
rodsErrorTable.h
SHA256Strategy.hpp
MD5Strategy.hpp