-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
26 lines (22 loc) · 765 Bytes
/
hash.cpp
File metadata and controls
26 lines (22 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <boost/algorithm/hex.hpp>
#include "hash.h"
using boost::uuids::detail::md5;
CRC32Hash::value_type CRC32Hash::operator()(const char *buf, std::size_t size) const {
boost::crc_32_type hash;
hash.process_bytes(buf, size);
return hash.checksum();
}
MD5Hash::value_type MD5Hash::operator()(const char *buf, std::size_t size) const {
md5 hash;
md5::digest_type digest;
hash.process_bytes(buf, size);
hash.get_digest(digest);
value_type result;
std::copy(std::begin(digest), std::end(digest), result.begin());
return result;
}
std::string MD5Hash::to_string(MD5Hash::value_type digest) {
std::string result;
boost::algorithm::hex(digest.begin(), digest.end(), std::back_inserter(result));
return result;
}