diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
commit | f5f56e1a1c4d9e9496fcb9d81131066a964ccd23 (patch) | |
tree | 49e44c6f87febed37efb953ab5485aa49f6481a7 /src/lib/cryptolink/tests/crypto_unittests.cc | |
parent | Initial commit. (diff) | |
download | isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.tar.xz isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.zip |
Adding upstream version 2.4.1.upstream/2.4.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/cryptolink/tests/crypto_unittests.cc')
-rw-r--r-- | src/lib/cryptolink/tests/crypto_unittests.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/lib/cryptolink/tests/crypto_unittests.cc b/src/lib/cryptolink/tests/crypto_unittests.cc new file mode 100644 index 0000000..9edb52d --- /dev/null +++ b/src/lib/cryptolink/tests/crypto_unittests.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2011-2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <config.h> + +#include <gtest/gtest.h> + +#include <util/encode/hex.h> + +#include <cryptolink/cryptolink.h> +#include <cryptolink/crypto_rng.h> + +using namespace std; +using namespace isc::cryptolink; + +// Test get version +TEST(CryptoLinkTest, Version) { + EXPECT_NO_THROW(CryptoLink::getVersion()); +} + +// Tests whether getCryptoLink() returns a singleton instance +TEST(CryptoLinkTest, Singleton) { + const CryptoLink& c1 = CryptoLink::getCryptoLink(); + const CryptoLink& c2 = CryptoLink::getCryptoLink(); + ASSERT_EQ(&c1, &c2); +} + +// Tests whether getRNG() returns a global value +TEST(CryptoLinkTest, GlobalRNG) { + CryptoLink& c = CryptoLink::getCryptoLink(); + RNGPtr rng1 = c.getRNG(); + RNGPtr rng2 = c.getRNG(); + ASSERT_EQ(rng1, rng2); +} + +// Tests whether RNG works +TEST(CryptoLinkTest, RNG) { + RNGPtr rng = CryptoLink::getCryptoLink().getRNG(); + vector<uint8_t> data; + ASSERT_NO_THROW(data = rng->random(16)); + ASSERT_EQ(16, data.size()); + vector<uint8_t> zero; + zero.resize(16); + EXPECT_NE(0, memcmp(&zero[0], &data[0], zero.size())); + + // Retry with the function (vs method) + vector<uint8_t> dataf; + ASSERT_NO_THROW(dataf = random(16)); + ASSERT_EQ(16, dataf.size()); + EXPECT_NE(0, memcmp(&zero[0], &dataf[0], zero.size())); + EXPECT_NE(0, memcmp(&data[0], &dataf[0], zero.size())); +} |