]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/beast/test/beast/core/detail/sha1.cpp
2 // Copyright (c) 2016-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)
7 // Official repository: https://github.com/boostorg/beast
10 #include <boost/beast/core/detail/sha1.hpp>
11 #include <boost/beast/unit_test/suite.hpp>
18 class sha1_test
: public beast::unit_test::suite
26 if(c
>= '0' && c
<= '9')
28 if(c
>= 'a' && c
<= 'f')
30 if(c
>= 'A' && c
<= 'F')
32 throw std::invalid_argument("not a hex digit");
37 unhex(std::string
const& in
)
40 out
.reserve(in
.size() / 2);
42 throw std::domain_error("invalid hex string");
43 for(std::size_t i
= 0; i
< in
.size(); i
+= 2)
45 (unhex(in
[i
])<<4) + unhex(in
[i
+1]));
50 check(std::string
const& message
, std::string
const& answer
)
53 digest
= unhex(answer
);
56 result
.resize(sha1_context::digest_size
);
58 update(ctx
, message
.data(), message
.size());
59 finish(ctx
, &result
[0]);
60 BEAST_EXPECT(result
== digest
);
66 // http://www.di-mgt.com.au/sha_testvectors.html
69 "a9993e36" "4706816a" "ba3e2571" "7850c26c" "9cd0d89d");
71 "da39a3ee" "5e6b4b0d" "3255bfef" "95601890" "afd80709");
72 check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
73 "84983e44" "1c3bd26e" "baae4aa1" "f95129e5" "e54670f1");
74 check("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
75 "a49b2446" "a02c645b" "f419f995" "b6709125" "3a04a259");
79 BEAST_DEFINE_TESTSUITE(beast
,core
,sha1
);