]>
git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/test/core/sha1.cpp
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #include <beast/core/detail/sha1.hpp>
9 #include <beast/unit_test/suite.hpp>
15 class sha1_test
: public beast::unit_test::suite
23 if(c
>= '0' && c
<= '9')
25 if(c
>= 'a' && c
<= 'f')
27 if(c
>= 'A' && c
<= 'F')
29 throw std::invalid_argument("not a hex digit");
34 unhex(std::string
const& in
)
37 out
.reserve(in
.size() / 2);
39 throw std::domain_error("invalid hex string");
40 for(std::size_t i
= 0; i
< in
.size(); i
+= 2)
42 (unhex(in
[i
])<<4) + unhex(in
[i
+1]));
47 check(std::string
const& message
, std::string
const& answer
)
50 digest
= unhex(answer
);
53 result
.resize(sha1_context::digest_size
);
55 update(ctx
, message
.data(), message
.size());
56 finish(ctx
, &result
[0]);
57 BEAST_EXPECT(result
== digest
);
63 // http://www.di-mgt.com.au/sha_testvectors.html
66 "a9993e36" "4706816a" "ba3e2571" "7850c26c" "9cd0d89d");
68 "da39a3ee" "5e6b4b0d" "3255bfef" "95601890" "afd80709");
69 check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
70 "84983e44" "1c3bd26e" "baae4aa1" "f95129e5" "e54670f1");
71 check("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
72 "a49b2446" "a02c645b" "f419f995" "b6709125" "3a04a259");
76 BEAST_DEFINE_TESTSUITE(sha1
,core
,beast
);