]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-ipcrypt_cc.cc
1 #ifndef BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_NO_MAIN
12 #include <boost/test/unit_test.hpp>
13 #include "ipcipher.hh"
16 using namespace boost
;
18 BOOST_AUTO_TEST_SUITE(test_ipcrypt_hh
)
20 BOOST_AUTO_TEST_CASE(test_ipcrypt4
)
22 ComboAddress
address("127.0.0.1");
23 std::string key
= "0123456789ABCDEF";
24 auto encrypted
= encryptCA(address
, key
);
26 auto decrypted
= decryptCA(encrypted
, key
);
27 BOOST_CHECK_EQUAL(address
.toString(), decrypted
.toString());
30 BOOST_AUTO_TEST_CASE(test_ipcrypt4_vector
)
32 // test vector from https://github.com/veorq/ipcrypt
33 vector
<pair
<string
, string
>> tests
{{{"127.0.0.1"}, {"114.62.227.59"}},
34 {{"8.8.8.8"}, {"46.48.51.50"}},
35 {{"1.2.3.4"}, {"171.238.15.199"}}};
37 std::string key
= "some 16-byte key";
39 for (const auto& p
: tests
) {
40 auto encrypted
= encryptCA(ComboAddress(p
.first
), key
);
41 BOOST_CHECK_EQUAL(encrypted
.toString(), p
.second
);
42 auto decrypted
= decryptCA(encrypted
, key
);
43 BOOST_CHECK_EQUAL(decrypted
.toString(), p
.first
);
46 // test from Frank Denis' test.cc
47 ComboAddress
address("192.168.69.42");
51 for (int n
= 0; n
< 16; ++n
) {
52 key2
.append(1, (char)n
+ 1);
55 for (unsigned int i
= 0; i
< 100000000UL; i
++) {
56 out
= encryptCA(address
, key2
);
57 // dec=decryptCA(out, key2);
58 // BOOST_CHECK(ip==dec);
62 ComboAddress
expected("93.155.197.186");
64 BOOST_CHECK_EQUAL(address
.toString(), expected
.toString());
67 BOOST_AUTO_TEST_CASE(test_ipcrypt6
)
69 ComboAddress
address("::1");
70 std::string key
= "0123456789ABCDEF";
71 auto encrypted
= encryptCA(address
, key
);
73 auto decrypted
= decryptCA(encrypted
, key
);
74 BOOST_CHECK_EQUAL(address
.toString(), decrypted
.toString());
77 BOOST_AUTO_TEST_SUITE_END()
79 #endif /* HAVE_IPCIPHER */