security: add missing out-of-line destructors for transform classes
Change-Id: I8306b8e10953e55e056b4eb5fcb76ec8f395f5c4
diff --git a/src/security/tpm/back-end.cpp b/src/security/tpm/back-end.cpp
index 72ef5fd..364b8bb 100644
--- a/src/security/tpm/back-end.cpp
+++ b/src/security/tpm/back-end.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -22,10 +22,12 @@
#include "back-end.hpp"
#include "key-handle.hpp"
#include "tpm.hpp"
-#include "../transform.hpp"
+#include "../pib/key.hpp"
+#include "../transform/buffer-source.hpp"
+#include "../transform/digest-filter.hpp"
+#include "../transform/stream-sink.hpp"
#include "../../encoding/buffer-stream.hpp"
#include "../../util/random.hpp"
-#include "../pib/key.hpp"
namespace ndn {
namespace security {
diff --git a/src/security/transform.hpp b/src/security/transform.hpp
index 8ecfed5..bc38619 100644
--- a/src/security/transform.hpp
+++ b/src/security/transform.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -23,20 +23,23 @@
#define NDN_CXX_SECURITY_TRANSFORM_HPP
#include "transform/buffer-source.hpp"
-#include "transform/stream-source.hpp"
#include "transform/step-source.hpp"
+#include "transform/stream-source.hpp"
#include "transform/bool-sink.hpp"
#include "transform/stream-sink.hpp"
-#include "transform/strip-space.hpp"
-#include "transform/hex-encode.hpp"
-#include "transform/hex-decode.hpp"
-#include "transform/base64-encode.hpp"
#include "transform/base64-decode.hpp"
+#include "transform/base64-encode.hpp"
+#include "transform/hex-decode.hpp"
+#include "transform/hex-encode.hpp"
+#include "transform/strip-space.hpp"
+
+#include "transform/block-cipher.hpp"
#include "transform/digest-filter.hpp"
#include "transform/hmac-filter.hpp"
-#include "transform/block-cipher.hpp"
+#include "transform/private-key.hpp"
+#include "transform/public-key.hpp"
#include "transform/signer-filter.hpp"
#include "transform/verifier-filter.hpp"
diff --git a/src/security/transform/base64-decode.cpp b/src/security/transform/base64-decode.cpp
index 8b047bc..5033b63 100644
--- a/src/security/transform/base64-decode.cpp
+++ b/src/security/transform/base64-decode.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,7 +20,6 @@
*/
#include "base64-decode.hpp"
-#include "../../encoding/buffer.hpp"
#include "../detail/openssl.hpp"
namespace ndn {
@@ -59,12 +58,14 @@
static const size_t BUFFER_LENGTH = 1024;
Base64Decode::Base64Decode(bool expectNewlineEvery64Bytes)
- : m_impl(new Impl)
+ : m_impl(make_unique<Impl>())
{
if (!expectNewlineEvery64Bytes)
BIO_set_flags(m_impl->m_base64, BIO_FLAGS_BASE64_NO_NL);
}
+Base64Decode::~Base64Decode() = default;
+
void
Base64Decode::preTransform()
{
@@ -114,7 +115,7 @@
// OpenSSL base64 BIO cannot give us the number bytes of partial decoded result,
// so we just try to read a chunk.
auto buffer = make_unique<OBuffer>(BUFFER_LENGTH);
- int rLen = BIO_read(m_impl->m_base64, &(*buffer)[0], buffer->size());
+ int rLen = BIO_read(m_impl->m_base64, buffer->data(), buffer->size());
if (rLen <= 0)
return;
diff --git a/src/security/transform/base64-decode.hpp b/src/security/transform/base64-decode.hpp
index ea69b8d..203716f 100644
--- a/src/security/transform/base64-decode.hpp
+++ b/src/security/transform/base64-decode.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -44,8 +44,9 @@
explicit
Base64Decode(bool expectNewlineEvery64Bytes = true);
-private:
+ ~Base64Decode();
+private:
/**
* @brief Read partial transformation results into output buffer and write them into next module.
*/
diff --git a/src/security/transform/base64-encode.cpp b/src/security/transform/base64-encode.cpp
index 60bc25f..d9a8a7a 100644
--- a/src/security/transform/base64-encode.cpp
+++ b/src/security/transform/base64-encode.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,7 +20,6 @@
*/
#include "base64-encode.hpp"
-#include "../../encoding/buffer.hpp"
#include "../detail/openssl.hpp"
namespace ndn {
@@ -53,12 +52,14 @@
};
Base64Encode::Base64Encode(bool needBreak)
- : m_impl(new Impl)
+ : m_impl(make_unique<Impl>())
{
if (!needBreak)
BIO_set_flags(m_impl->m_base64, BIO_FLAGS_BASE64_NO_NL);
}
+Base64Encode::~Base64Encode() = default;
+
void
Base64Encode::preTransform()
{
@@ -109,7 +110,7 @@
// there is something to read from BIO
auto buffer = make_unique<OBuffer>(nRead);
- int rLen = BIO_read(m_impl->m_sink, &(*buffer)[0], nRead);
+ int rLen = BIO_read(m_impl->m_sink, buffer->data(), nRead);
if (rLen < 0)
return;
diff --git a/src/security/transform/base64-encode.hpp b/src/security/transform/base64-encode.hpp
index d62b5d8..34ad577 100644
--- a/src/security/transform/base64-encode.hpp
+++ b/src/security/transform/base64-encode.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -42,6 +42,8 @@
explicit
Base64Encode(bool needBreak = true);
+ ~Base64Encode();
+
private:
/**
* @brief Read partial transformation result (if exists) from BIO
diff --git a/src/security/transform/block-cipher.cpp b/src/security/transform/block-cipher.cpp
index 327aba6..b1bb091 100644
--- a/src/security/transform/block-cipher.cpp
+++ b/src/security/transform/block-cipher.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -48,21 +48,24 @@
BIO* m_sink; // BIO_f_cipher alone does not work without a sink
};
+
BlockCipher::BlockCipher(BlockCipherAlgorithm algo, CipherOperator op,
const uint8_t* key, size_t keyLen,
const uint8_t* iv, size_t ivLen)
- : m_impl(new Impl)
+ : m_impl(make_unique<Impl>())
{
switch (algo) {
case BlockCipherAlgorithm::AES_CBC:
initializeAesCbc(key, keyLen, iv, ivLen, op);
break;
default:
- BOOST_THROW_EXCEPTION(Error(getIndex(), "Cipher algorithm " +
- boost::lexical_cast<std::string>(algo) + " is not supported"));
+ BOOST_THROW_EXCEPTION(Error(getIndex(), "Unsupported block cipher algorithm " +
+ boost::lexical_cast<std::string>(algo)));
}
}
+BlockCipher::~BlockCipher() = default;
+
void
BlockCipher::preTransform()
{
@@ -113,7 +116,7 @@
// there is something to read from BIO
auto buffer = make_unique<OBuffer>(nRead);
- int rLen = BIO_read(m_impl->m_sink, &(*buffer)[0], nRead);
+ int rLen = BIO_read(m_impl->m_sink, buffer->data(), nRead);
if (rLen < 0)
return;
diff --git a/src/security/transform/block-cipher.hpp b/src/security/transform/block-cipher.hpp
index 320e184..ee56682 100644
--- a/src/security/transform/block-cipher.hpp
+++ b/src/security/transform/block-cipher.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -52,6 +52,8 @@
const uint8_t* key, size_t keyLen,
const uint8_t* iv, size_t ivLen);
+ ~BlockCipher();
+
private:
/**
* @brief Read partial transformation result (if exists) from BIO
diff --git a/src/security/transform/digest-filter.cpp b/src/security/transform/digest-filter.cpp
index 862d784..44fe429 100644
--- a/src/security/transform/digest-filter.cpp
+++ b/src/security/transform/digest-filter.cpp
@@ -71,6 +71,8 @@
boost::lexical_cast<std::string>(algo)));
}
+DigestFilter::~DigestFilter() = default;
+
size_t
DigestFilter::convert(const uint8_t* buf, size_t size)
{
diff --git a/src/security/transform/digest-filter.hpp b/src/security/transform/digest-filter.hpp
index 0ccc81b..a9c023e 100644
--- a/src/security/transform/digest-filter.hpp
+++ b/src/security/transform/digest-filter.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -41,6 +41,8 @@
explicit
DigestFilter(DigestAlgorithm algo);
+ ~DigestFilter();
+
private:
/**
* @brief Append data @p buf into digest calculation
diff --git a/src/security/transform/hmac-filter.cpp b/src/security/transform/hmac-filter.cpp
index e150a79..07a1796 100644
--- a/src/security/transform/hmac-filter.cpp
+++ b/src/security/transform/hmac-filter.cpp
@@ -68,8 +68,9 @@
#endif // OPENSSL_VERSION_NUMBER < 0x1010000fL
};
+
HmacFilter::HmacFilter(DigestAlgorithm algo, const uint8_t* key, size_t keyLen)
- : m_impl(new Impl)
+ : m_impl(make_unique<Impl>())
{
BOOST_ASSERT(key != nullptr);
BOOST_ASSERT(keyLen > 0);
@@ -82,6 +83,8 @@
BOOST_THROW_EXCEPTION(Error(getIndex(), "Cannot initialize HMAC"));
}
+HmacFilter::~HmacFilter() = default;
+
size_t
HmacFilter::convert(const uint8_t* buf, size_t size)
{
@@ -97,7 +100,7 @@
auto buffer = make_unique<OBuffer>(EVP_MAX_MD_SIZE);
unsigned int mdLen = 0;
- if (HMAC_Final(*m_impl, &(*buffer)[0], &mdLen) == 0)
+ if (HMAC_Final(*m_impl, buffer->data(), &mdLen) == 0)
BOOST_THROW_EXCEPTION(Error(getIndex(), "Failed to finalize HMAC"));
buffer->erase(buffer->begin() + mdLen, buffer->end());
diff --git a/src/security/transform/hmac-filter.hpp b/src/security/transform/hmac-filter.hpp
index 002fda8..d0770b3 100644
--- a/src/security/transform/hmac-filter.hpp
+++ b/src/security/transform/hmac-filter.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -35,13 +35,14 @@
class HmacFilter : public Transform
{
public:
-
/**
* @brief Create a HMAC module to generate HMAC using algorithm @p algo and @p key
* @pre @p key must not be nullptr, and @p size must be a positive integer.
*/
HmacFilter(DigestAlgorithm algo, const uint8_t* key, size_t keyLen);
+ ~HmacFilter();
+
private:
/**
* @brief write data @p buf into HMAC signer
diff --git a/src/security/transform/verifier-filter.cpp b/src/security/transform/verifier-filter.cpp
index 1a7eebe..6e54c34 100644
--- a/src/security/transform/verifier-filter.cpp
+++ b/src/security/transform/verifier-filter.cpp
@@ -20,6 +20,7 @@
*/
#include "verifier-filter.hpp"
+#include "public-key.hpp"
#include "../detail/openssl-helper.hpp"
#include <boost/lexical_cast.hpp>
@@ -56,9 +57,10 @@
size_t m_sigLen;
};
+
VerifierFilter::VerifierFilter(DigestAlgorithm algo, const PublicKey& key,
const uint8_t* sig, size_t sigLen)
- : m_impl(new Impl(key, sig, sigLen))
+ : m_impl(make_unique<Impl>(key, sig, sigLen))
{
const EVP_MD* md = detail::digestAlgorithmToEvpMd(algo);
if (md == nullptr)
@@ -70,6 +72,8 @@
boost::lexical_cast<std::string>(algo)));
}
+VerifierFilter::~VerifierFilter() = default;
+
size_t
VerifierFilter::convert(const uint8_t* buf, size_t size)
{
diff --git a/src/security/transform/verifier-filter.hpp b/src/security/transform/verifier-filter.hpp
index 4bc63e3..e08cc7d 100644
--- a/src/security/transform/verifier-filter.hpp
+++ b/src/security/transform/verifier-filter.hpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -23,26 +23,29 @@
#define NDN_CXX_SECURITY_TRANSFORM_VERIFIER_FILTER_HPP
#include "transform-base.hpp"
-#include "public-key.hpp"
#include "../security-common.hpp"
namespace ndn {
namespace security {
namespace transform {
+class PublicKey;
+
/**
- * @brief The module to verify signature.
+ * @brief The module to verify signatures.
*
- * The next module is usually SinkBool.
+ * The next module in the chain is usually BoolSink.
*/
class VerifierFilter : public Transform
{
public:
/**
- * @brief Create a verifier module to verify signature @p sig using algorithm @p algo and @p key
+ * @brief Create a verifier module to verify signature @p sig using algorithm @p algo and key @p key
*/
VerifierFilter(DigestAlgorithm algo, const PublicKey& key, const uint8_t* sig, size_t sigLen);
+ ~VerifierFilter();
+
private:
/**
* @brief Write data @p buf into verifier
diff --git a/src/security/v2/key-chain.cpp b/src/security/v2/key-chain.cpp
index 2e5e4ad..b63287d 100644
--- a/src/security/v2/key-chain.cpp
+++ b/src/security/v2/key-chain.cpp
@@ -38,6 +38,7 @@
#include "../transform/bool-sink.hpp"
#include "../transform/buffer-source.hpp"
#include "../transform/private-key.hpp"
+#include "../transform/public-key.hpp"
#include "../transform/verifier-filter.hpp"
#include "../../encoding/buffer-stream.hpp"
diff --git a/src/security/verification-helpers.cpp b/src/security/verification-helpers.cpp
index f8fd3d2..1d22373 100644
--- a/src/security/verification-helpers.cpp
+++ b/src/security/verification-helpers.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -21,14 +21,18 @@
#include "verification-helpers.hpp"
-#include "data.hpp"
-#include "interest.hpp"
-#include "encoding/buffer-stream.hpp"
-#include "security/pib/key.hpp"
-#include "security/pib/key.hpp"
-#include "security/transform.hpp"
-#include "security/v2/certificate.hpp"
-#include "security/detail/openssl.hpp"
+#include "detail/openssl.hpp"
+#include "pib/key.hpp"
+#include "transform/bool-sink.hpp"
+#include "transform/buffer-source.hpp"
+#include "transform/digest-filter.hpp"
+#include "transform/public-key.hpp"
+#include "transform/stream-sink.hpp"
+#include "transform/verifier-filter.hpp"
+#include "v2/certificate.hpp"
+#include "../data.hpp"
+#include "../interest.hpp"
+#include "../encoding/buffer-stream.hpp"
namespace ndn {
namespace security {
diff --git a/tests/unit-tests/security/transform/block-cipher.t.cpp b/tests/unit-tests/security/transform/block-cipher.t.cpp
index ccc5d2b..6a6b722 100644
--- a/tests/unit-tests/security/transform/block-cipher.t.cpp
+++ b/tests/unit-tests/security/transform/block-cipher.t.cpp
@@ -84,6 +84,17 @@
auto buf2 = os2.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
buf2->begin(), buf2->end());
+
+ // invalid key length
+ const uint8_t badKey[] = {0x00, 0x01, 0x02, 0x03};
+ BOOST_CHECK_THROW(BlockCipher(BlockCipherAlgorithm::AES_CBC, CipherOperator::ENCRYPT,
+ badKey, sizeof(badKey), badKey, sizeof(badKey)), Error);
+}
+
+BOOST_AUTO_TEST_CASE(InvalidAlgorithm)
+{
+ BOOST_CHECK_THROW(BlockCipher(BlockCipherAlgorithm::NONE, CipherOperator::ENCRYPT,
+ nullptr, 0, nullptr, 0), Error);
}
BOOST_AUTO_TEST_SUITE_END() // TestBlockCipher
diff --git a/tests/unit-tests/security/transform/digest-filter.t.cpp b/tests/unit-tests/security/transform/digest-filter.t.cpp
index c6e296f..a3f0314 100644
--- a/tests/unit-tests/security/transform/digest-filter.t.cpp
+++ b/tests/unit-tests/security/transform/digest-filter.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -19,11 +19,12 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
+#include "security/transform/digest-filter.hpp"
+
+#include "encoding/buffer-stream.hpp"
#include "security/transform/buffer-source.hpp"
#include "security/transform/step-source.hpp"
-#include "security/transform/digest-filter.hpp"
#include "security/transform/stream-sink.hpp"
-#include "encoding/buffer-stream.hpp"
#include "boost-test.hpp"
@@ -36,34 +37,33 @@
BOOST_AUTO_TEST_SUITE(Transform)
BOOST_AUTO_TEST_SUITE(TestDigestFilter)
+static const uint8_t in[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+};
+static const uint8_t out[] = {
+ 0x3e, 0x14, 0xfd, 0x66, 0x9a, 0x79, 0x80, 0x65,
+ 0xc4, 0x0d, 0x61, 0xf8, 0x6a, 0xc7, 0x98, 0x29,
+ 0xc0, 0x6b, 0x90, 0x8f, 0xbb, 0x19, 0xa0, 0x85,
+ 0xf7, 0xfa, 0x7b, 0x2d, 0xd6, 0x8c, 0xd5, 0xa3
+};
+
BOOST_AUTO_TEST_CASE(Basic)
{
- uint8_t in[128] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t out[] = {
- 0x3e, 0x14, 0xfd, 0x66, 0x9a, 0x79, 0x80, 0x65,
- 0xc4, 0x0d, 0x61, 0xf8, 0x6a, 0xc7, 0x98, 0x29,
- 0xc0, 0x6b, 0x90, 0x8f, 0xbb, 0x19, 0xa0, 0x85,
- 0xf7, 0xfa, 0x7b, 0x2d, 0xd6, 0x8c, 0xd5, 0xa3
- };
-
OBufferStream os;
bufferSource(in, sizeof(in)) >> digestFilter(DigestAlgorithm::SHA256) >> streamSink(os);
@@ -73,32 +73,6 @@
BOOST_AUTO_TEST_CASE(StepByStep)
{
- uint8_t in[128] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t out[] = {
- 0x3e, 0x14, 0xfd, 0x66, 0x9a, 0x79, 0x80, 0x65,
- 0xc4, 0x0d, 0x61, 0xf8, 0x6a, 0xc7, 0x98, 0x29,
- 0xc0, 0x6b, 0x90, 0x8f, 0xbb, 0x19, 0xa0, 0x85,
- 0xf7, 0xfa, 0x7b, 0x2d, 0xd6, 0x8c, 0xd5, 0xa3
- };
-
StepSource source;
OBufferStream os;
source >> digestFilter(DigestAlgorithm::SHA256) >> streamSink(os);
@@ -116,7 +90,7 @@
BOOST_AUTO_TEST_CASE(EmptyInput)
{
- uint8_t out[] = {
+ const uint8_t out[] = {
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
@@ -132,11 +106,9 @@
BOOST_CHECK_EQUAL_COLLECTIONS(out, out + sizeof(out), buf->begin(), buf->end());
}
-BOOST_AUTO_TEST_CASE(Error)
+BOOST_AUTO_TEST_CASE(InvalidAlgorithm)
{
- OBufferStream os;
- BOOST_REQUIRE_THROW(stepSource() >> digestFilter(DigestAlgorithm::NONE) >> streamSink(os),
- transform::Error);
+ BOOST_CHECK_THROW(DigestFilter{DigestAlgorithm::NONE}, Error);
}
BOOST_AUTO_TEST_SUITE_END() // TestDigestFilter
diff --git a/tests/unit-tests/security/transform/hmac-filter.t.cpp b/tests/unit-tests/security/transform/hmac-filter.t.cpp
index ccb5feb..e1ae73d 100644
--- a/tests/unit-tests/security/transform/hmac-filter.t.cpp
+++ b/tests/unit-tests/security/transform/hmac-filter.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -19,11 +19,12 @@
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
*/
+#include "security/transform/hmac-filter.hpp"
+
+#include "encoding/buffer-stream.hpp"
#include "security/transform/buffer-source.hpp"
#include "security/transform/step-source.hpp"
-#include "security/transform/hmac-filter.hpp"
#include "security/transform/stream-sink.hpp"
-#include "encoding/buffer-stream.hpp"
#include "boost-test.hpp"
@@ -36,25 +37,23 @@
BOOST_AUTO_TEST_SUITE(Transform)
BOOST_AUTO_TEST_SUITE(TestHmacFilter)
+static const uint8_t key[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+};
+static const uint8_t data[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+};
+static const uint8_t digest[] = {
+ 0x9f, 0x3a, 0xa2, 0x88, 0x26, 0xb3, 0x74, 0x85,
+ 0xca, 0x05, 0x01, 0x4d, 0x71, 0x42, 0xb3, 0xea,
+ 0x3f, 0xfb, 0xda, 0x5a, 0x35, 0xbf, 0xd2, 0x0f,
+ 0x2f, 0x9c, 0x8f, 0xcc, 0x6d, 0x30, 0x48, 0x54
+};
+
BOOST_AUTO_TEST_CASE(Basic)
{
- uint8_t key[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t data[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t digest[32] = {
- 0x9f, 0x3a, 0xa2, 0x88, 0x26, 0xb3, 0x74, 0x85,
- 0xca, 0x05, 0x01, 0x4d, 0x71, 0x42, 0xb3, 0xea,
- 0x3f, 0xfb, 0xda, 0x5a, 0x35, 0xbf, 0xd2, 0x0f,
- 0x2f, 0x9c, 0x8f, 0xcc, 0x6d, 0x30, 0x48, 0x54
- };
-
OBufferStream os;
bufferSource(data, sizeof(data)) >> hmacFilter(DigestAlgorithm::SHA256, key, sizeof(key)) >> streamSink(os);
@@ -64,23 +63,6 @@
BOOST_AUTO_TEST_CASE(StepByStep)
{
- uint8_t key[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t data[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t digest[32] = {
- 0x9f, 0x3a, 0xa2, 0x88, 0x26, 0xb3, 0x74, 0x85,
- 0xca, 0x05, 0x01, 0x4d, 0x71, 0x42, 0xb3, 0xea,
- 0x3f, 0xfb, 0xda, 0x5a, 0x35, 0xbf, 0xd2, 0x0f,
- 0x2f, 0x9c, 0x8f, 0xcc, 0x6d, 0x30, 0x48, 0x54
- };
-
OBufferStream os;
StepSource source;
source >> hmacFilter(DigestAlgorithm::SHA256, key, sizeof(key)) >> streamSink(os);
@@ -98,12 +80,7 @@
BOOST_AUTO_TEST_CASE(EmptyInput)
{
- uint8_t key[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t digest[32] = {
+ const uint8_t digest[] = {
0x07, 0xEF, 0xF8, 0xB3, 0x26, 0xB7, 0x79, 0x8C,
0x9C, 0xCF, 0xCB, 0xDB, 0xE5, 0x79, 0x48, 0x9A,
0xC7, 0x85, 0xA7, 0x99, 0x5A, 0x04, 0x61, 0x8B,
@@ -119,16 +96,9 @@
BOOST_CHECK_EQUAL_COLLECTIONS(digest, digest + sizeof(digest), buf->begin(), buf->end());
}
-BOOST_AUTO_TEST_CASE(Error)
+BOOST_AUTO_TEST_CASE(InvalidAlgorithm)
{
- uint8_t key[16] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- OBufferStream os;
- BOOST_REQUIRE_THROW(stepSource() >> hmacFilter(DigestAlgorithm::NONE, key, sizeof(key)) >> streamSink(os),
- transform::Error);
+ BOOST_CHECK_THROW(HmacFilter(DigestAlgorithm::NONE, key, sizeof(key)), Error);
}
BOOST_AUTO_TEST_SUITE_END() // TestHmacFilter
diff --git a/tests/unit-tests/security/transform/verifier-filter.t.cpp b/tests/unit-tests/security/transform/verifier-filter.t.cpp
index a877889..4464c4e 100644
--- a/tests/unit-tests/security/transform/verifier-filter.t.cpp
+++ b/tests/unit-tests/security/transform/verifier-filter.t.cpp
@@ -26,6 +26,7 @@
#include "security/transform/bool-sink.hpp"
#include "security/transform/buffer-source.hpp"
#include "security/transform/private-key.hpp"
+#include "security/transform/public-key.hpp"
#include "security/transform/signer-filter.hpp"
#include "security/transform/stream-sink.hpp"