File: sha1.cpp

package info (click to toggle)
actor-framework 0.18.7-1~exp1
  • links: PTS
  • area: main
  • in suites: experimental
  • size: 8,740 kB
  • sloc: cpp: 85,162; sh: 491; python: 187; makefile: 11
file content (33 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download
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
27
28
29
30
31
32
33
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.

#define CAF_SUITE hash.sha1

#include "caf/hash/sha1.hpp"

#include "core-test.hpp"

using namespace caf;

namespace {

template <class... Ts>
auto make_hash(Ts... xs) {
  static_assert(sizeof...(Ts) == 20);
  return hash::sha1::result_type{{static_cast<byte>(xs)...}};
}

} // namespace

#define CHECK_HASH_EQ(str, bytes)                                              \
  CHECK_EQ(hash::sha1::compute(string_view{str}), bytes);

CAF_TEST(strings are hashed by their content only) {
  CHECK_HASH_EQ("dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
                make_hash(0xb3, 0x7a, 0x4f, 0x2c,   // Bytes  1 -  4
                          0xc0, 0x62, 0x4f, 0x16,   //        5 -  8
                          0x90, 0xf6, 0x46, 0x06,   //        9 - 12
                          0xcf, 0x38, 0x59, 0x45,   //       13 - 16
                          0xb2, 0xbe, 0xc4, 0xea)); //       17 - 20
}