-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_qt5.cpp
82 lines (64 loc) · 2.36 KB
/
test_qt5.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#if defined(QT_CORE_LIB)
#include <catch2/catch.hpp>
#include "mbedcrypto/tcodec.hpp"
#include "mbedcrypto/hash.hpp"
#include "generator.hpp"
///////////////////////////////////////////////////////////////////////////////
namespace {
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
} // namespace anon
///////////////////////////////////////////////////////////////////////////////
TEST_CASE("test qt5 bindings", "[qt5]") {
using namespace mbedcrypto;
SECTION("test pointers") {
QByteArray sample{"mbedcrypto"};
auto pc = to_const_ptr(sample);
REQUIRE( *pc == 'm' );
auto p = to_ptr(sample);
*p = 'M';
REQUIRE( (sample == "Mbedcrypto") );
}
SECTION("text codecs") {
std::string s{"mbedcrypto library"};
QByteArray q = QByteArray::fromStdString(s);
auto sr = to_hex(s);
auto qr = to_hex(q);
REQUIRE( (qr == sr) );
auto ts = from_hex(sr);
auto tq = from_hex(qr);
REQUIRE( (tq == ts) );
sr = to_base64(s);
qr = to_base64(q);
REQUIRE( (qr == sr) );
ts = from_base64(sr);
tq = from_base64(qr);
REQUIRE( (tq == ts) );
}
SECTION("message digests") {
std::string s{test::long_text()};
QByteArray q{test::long_text()};
auto hs = to_base64(to_sha1(s));
auto hq = to_base64(to_sha1(q));
REQUIRE( (hq == hs) );
hs = to_base64(to_sha256(s));
hq = to_base64(to_sha256(q));
REQUIRE( (hq == hs) );
hs = to_base64(to_sha512(s));
hq = to_base64(to_sha512(q));
REQUIRE( (hq == hs) );
std::string ks{test::short_text()};
QByteArray kq{test::short_text()};
auto ms = to_base64(hmac::make(hash_t::sha1, ks, s));
auto mq = to_base64(hmac::make(hash_t::sha1, kq, q));
REQUIRE( (mq == ms) );
ms = to_base64(make_hmac(hash_t::sha256, ks, s));
mq = to_base64(make_hmac(hash_t::sha256, kq, q));
REQUIRE( (mq == ms) );
ms = to_base64(hmac::make(hash_t::sha512, ks, s));
mq = to_base64(hmac::make(hash_t::sha512, kq, q));
REQUIRE( (mq == ms) );
}
}
///////////////////////////////////////////////////////////////////////////////
#endif // QT_CORE_LIB