add EncryptionTLV Encoding and Decoding
Change-Id: I67f6f733e0a02b894e49155167600963c3b2964e
diff --git a/tests/unit-tests/dummy-test.t.cpp b/tests/unit-tests/dummy-test.t.cpp
deleted file mode 100644
index 0992583..0000000
--- a/tests/unit-tests/dummy-test.t.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2019, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#include "identity-management-fixture.hpp"
-#include "boost-test.hpp"
-
-namespace ndn {
-namespace ndncert {
-namespace tests {
-
-// See https://redmine.named-data.net/projects/nfd/wiki/UnitTesting on how to name a test suite.
-BOOST_AUTO_TEST_SUITE(TestSkeleton)
-
-BOOST_AUTO_TEST_CASE(Test1)
-{
- int i = 0;
-
- // For reference of available Boost.Test macros, see
- // http://www.boost.org/doc/libs/1_54_0/libs/test/doc/html/utf/testing-tools/reference.html
-
- BOOST_REQUIRE_NO_THROW(i = 1);
- BOOST_REQUIRE_EQUAL(i, 1);
-}
-
-// Use UnitTestTimeFixture to mock clocks.
-BOOST_FIXTURE_TEST_CASE(Test2, UnitTestTimeFixture)
-{
- // this->advanceClocks increments mock clocks.
- advanceClocks(time::milliseconds(500), 2);
-}
-
-BOOST_AUTO_TEST_SUITE_END()
-
-} // namespace tests
-} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/enc-tlv.t.cpp b/tests/unit-tests/enc-tlv.t.cpp
index 10e59d9..56817d3 100644
--- a/tests/unit-tests/enc-tlv.t.cpp
+++ b/tests/unit-tests/enc-tlv.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2017-2019, Regents of the University of California.
+ * Copyright (c) 2017-2020, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -18,9 +18,9 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#include "crypto-support/enc-tlv.hpp"
-#include "crypto-support/crypto-helper.hpp"
#include "boost-test.hpp"
+#include "crypto-support/crypto-helper.hpp"
+#include "crypto-support/enc-tlv.hpp"
namespace ndn {
namespace ndncert {
@@ -28,28 +28,20 @@
BOOST_AUTO_TEST_SUITE(TestEncTlv)
-BOOST_AUTO_TEST_CASE(Test0)
+BOOST_AUTO_TEST_CASE(EncodingDecoding)
{
- ECDHState aliceState;
- auto alicePub = aliceState.getRawSelfPubKey();
- BOOST_CHECK(aliceState.context->publicKeyLen != 0);
-
- ECDHState bobState;
- auto bobPub = bobState.getRawSelfPubKey();
- BOOST_CHECK(bobState.context->publicKeyLen != 0);
-
- auto aliceResult = aliceState.deriveSecret(bobPub, bobState.context->publicKeyLen);
- BOOST_CHECK(aliceState.context->sharedSecretLen != 0);
-
- auto bobResult = bobState.deriveSecret(alicePub, aliceState.context->publicKeyLen);
- BOOST_CHECK(bobState.context->sharedSecretLen != 0);
-
- BOOST_CHECK_EQUAL_COLLECTIONS(aliceResult, aliceResult + 32,
- bobResult, bobResult + 32);
+ const uint8_t key[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
+ 0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
+ const std::string plaintext = "alongstringalongstringalongstringalongstringalongstringalongstringalongstringalongstring";
+ const std::string associatedData = "test";
+ auto block = encodeBlockWithAesGcm128(tlv::Content, key, (uint8_t*)plaintext.c_str(), plaintext.size(),
+ (uint8_t*)associatedData.c_str(), associatedData.size());
+ auto decoded = decodeBlockWithAesGcm128(block, key, (uint8_t*)associatedData.c_str(), associatedData.size());
+ BOOST_CHECK_EQUAL(plaintext, std::string((char*)decoded.get<uint8_t>(), decoded.size()));
}
BOOST_AUTO_TEST_SUITE_END()
-} // namespace tests
-} // namespace ndncert
-} // namespace ndn
+} // namespace tests
+} // namespace ndncert
+} // namespace ndn