From f5f56e1a1c4d9e9496fcb9d81131066a964ccd23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:15:43 +0200 Subject: Adding upstream version 2.4.1. Signed-off-by: Daniel Baumann --- src/lib/cryptolink/tests/crypto_unittests.cc | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/lib/cryptolink/tests/crypto_unittests.cc (limited to 'src/lib/cryptolink/tests/crypto_unittests.cc') 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 + +#include + +#include + +#include +#include + +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 data; + ASSERT_NO_THROW(data = rng->random(16)); + ASSERT_EQ(16, data.size()); + vector zero; + zero.resize(16); + EXPECT_NE(0, memcmp(&zero[0], &data[0], zero.size())); + + // Retry with the function (vs method) + vector 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())); +} -- cgit v1.2.3