Vanetza
 
Loading...
Searching...
No Matches
hashed_id.cpp
1#include <vanetza/security/hashed_id.hpp>
2#include <boost/functional/hash.hpp>
3#include <algorithm>
4#include <cassert>
5
6namespace vanetza
7{
8namespace security
9{
10
11HashedId3 truncate(const HashedId8& in)
12{
13 HashedId3 out;
14 assert(out.size() <= in.size());
15 std::copy_n(in.rbegin(), out.size(), out.rbegin());
16 return out;
17}
18
19HashedId8 create_hashed_id8(const Sha256Digest& digest)
20{
21 HashedId8 hashed;
22 std::copy(digest.end() - 8, digest.end(), hashed.data());
23 return hashed;
24}
25
26HashedId8 create_hashed_id8(const Sha384Digest& digest)
27{
28 HashedId8 hashed;
29 std::copy(digest.end() - 8, digest.end(), hashed.data());
30 return hashed;
31}
32
33} // namespace security
34} // namespace vanetza
35
36namespace std
37{
38
39size_t hash<vanetza::security::HashedId8>::operator()(const vanetza::security::HashedId8& hid8) const
40{
41 size_t seed = 0;
42 for (uint8_t octet : hid8) {
43 boost::hash_combine(seed, octet);
44 }
45 return seed;
46}
47
48} // namespace std
STL namespace.