A library for working with phylogenetic and population genetic data.
v0.32.0
utils/tools/hash/functions.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2018 Lucas Czech and HITS gGmbH
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
36 
37 #include <iostream>
38 #include <stdexcept>
39 
40 namespace genesis {
41 namespace utils {
42 
43 // ================================================================================================
44 // Hashing
45 // ================================================================================================
46 
47 std::string hash_hex( std::shared_ptr<BaseInputSource> source, HashingFunctions hash_fct )
48 {
49  switch( hash_fct ) {
51  return MD5::read_hex( source );
52  }
54  return SHA1::read_hex( source );
55  }
57  return SHA256::read_hex( source );
58  }
59  }
60 
61  throw std::invalid_argument( "Invalid hashing function selected." );
62 }
63 
64 } // namespace utils
65 } // namespace genesis
genesis::utils::HashingFunctions
HashingFunctions
List of the currently implemented hashing functions.
Definition: utils/tools/hash/functions.hpp:53
genesis::utils::hash_hex
std::string hash_hex(std::shared_ptr< BaseInputSource > source, HashingFunctions hash_fct)
Calculate the hash of an input source, using a given hashing function, and return its hex representat...
Definition: utils/tools/hash/functions.cpp:47
genesis::utils::MD5::read_hex
static std::string read_hex(std::shared_ptr< BaseInputSource > source)
Calculate the checksum for the content of an input source.
Definition: md5.cpp:96
genesis::utils::HashingFunctions::kSHA256
@ kSHA256
Use SHA256 for hashing.
genesis::utils::SHA256::read_hex
static std::string read_hex(std::shared_ptr< BaseInputSource > source)
Calculate the checksum for the content of an input source.
Definition: sha256.cpp:121
sha1.hpp
genesis::utils::SHA1::read_hex
static std::string read_hex(std::shared_ptr< BaseInputSource > source)
Calculate the checksum for the content of an input source.
Definition: sha1.cpp:65
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
md5.hpp
genesis::utils::HashingFunctions::kMD5
@ kMD5
Use MD5 for hashing.
genesis::utils::HashingFunctions::kSHA1
@ kSHA1
Use SHA1 for hashing.
functions.hpp
sha256.hpp