encoding: remove duplicate buf() and get() methods from Buffer class
Change-Id: If885d4199d6c9df9b9b46664c3641c9a14a77eab
diff --git a/src/encoding/buffer.cpp b/src/encoding/buffer.cpp
index 0d9550b..9390079 100644
--- a/src/encoding/buffer.cpp
+++ b/src/encoding/buffer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 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).
*
@@ -35,14 +35,7 @@
"Buffer must be MoveAssignable with noexcept");
#endif // NDN_CXX_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE
-Buffer::Buffer()
-{
-}
-
-Buffer::Buffer(size_t size)
- : std::vector<uint8_t>(size, 0)
-{
-}
+Buffer::Buffer() = default;
Buffer::Buffer(const void* buf, size_t length)
: std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(buf),
diff --git a/src/encoding/buffer.hpp b/src/encoding/buffer.hpp
index 994fbf8..70ffec8 100644
--- a/src/encoding/buffer.hpp
+++ b/src/encoding/buffer.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2014 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).
*
@@ -30,104 +30,50 @@
namespace ndn {
-class Buffer;
-typedef shared_ptr<const Buffer> ConstBufferPtr;
-typedef shared_ptr<Buffer> BufferPtr;
-
/**
- * @brief Class representing a general-use automatically managed/resized buffer
+ * @brief General-purpose automatically managed/resized buffer
*
- * In most respect, Buffer class is equivalent to std::vector<uint8_t> and is in fact
- * uses it as a base class. In addition to that, it provides buf() and buf<T>() helper
- * method for easier access to the underlying data (buf<T>() casts pointer to the requested class)
+ * In most respect, the Buffer class is equivalent to a `std::vector<uint8_t>`, and it in fact
+ * uses the latter as a base class. In addition to that, it provides the get<T>() helper method
+ * that automatically casts the returned pointer to the requested type.
*/
class Buffer : public std::vector<uint8_t>
{
public:
- /** @brief Creates an empty buffer
+ using std::vector<uint8_t>::vector;
+
+ /** @brief Creates an empty Buffer
*/
Buffer();
- /** @brief Creates a buffer with pre-allocated size
- * @param size size of the buffer to be allocated
- */
- explicit
- Buffer(size_t size);
-
- /** @brief Create a buffer by copying contents from a buffer
- * @param buf const pointer to buffer
+ /** @brief Creates a Buffer by copying contents from a raw buffer
+ * @param buf const pointer to buffer to copy
* @param length length of the buffer to copy
*/
Buffer(const void* buf, size_t length);
- /** @brief Create a buffer by copying contents of the range [first, last)
- * @tparam InputIterator an InputIterator compatible with std::vector<uint8_t> constructor
- * @param first iterator to the first element to copy
- * @param last iterator to the element immediately following the last element to copy
- */
- template <class InputIterator>
- Buffer(InputIterator first, InputIterator last)
- : std::vector<uint8_t>(first, last)
- {
- }
-
- /** @return pointer to the first byte of the buffer
- */
- uint8_t*
- get()
- {
- return &front();
- }
-
- /** @return pointer to the first byte of the buffer
- *
- * This is same as \p .get()
- */
- uint8_t*
- buf()
- {
- return &front();
- }
-
- /** @return pointer to the first byte of the buffer and reinterpret_cast
- * it to the requested type T
+ /** @return pointer to the first byte of the buffer, cast to the requested type T
*/
template<class T>
T*
- get()
+ get() noexcept
{
- return reinterpret_cast<T*>(&front());
+ return reinterpret_cast<T*>(data());
}
- /** @return pointer to the first byte of the buffer
- *
- * This is same as \p .get()
- */
- const uint8_t*
- buf() const
- {
- return &front();
- }
-
- /** @return pointer to the first byte of the buffer
- */
- const uint8_t*
- get() const
- {
- return &front();
- }
-
- /** @return const pointer to the first byte of the buffer and reinterpret_cast
- * it to the requested type T
+ /** @return const pointer to the first byte of the buffer, cast to the requested type T
*/
template<class T>
const T*
- get() const
+ get() const noexcept
{
- return reinterpret_cast<const T*>(&front());
+ return reinterpret_cast<const T*>(data());
}
};
+using BufferPtr = shared_ptr<Buffer>;
+using ConstBufferPtr = shared_ptr<const Buffer>;
+
} // namespace ndn
#endif // NDN_ENCODING_BUFFER_HPP
diff --git a/src/key-locator.cpp b/src/key-locator.cpp
index 50453d9..9692ecc 100644
--- a/src/key-locator.cpp
+++ b/src/key-locator.cpp
@@ -177,7 +177,7 @@
// This function takes a constant reference of a shared pointer.
// It MUST NOT change the reference count of that shared pointer.
- return this->setKeyDigest(makeBinaryBlock(tlv::KeyDigest, keyDigest->get(), keyDigest->size()));
+ return this->setKeyDigest(makeBinaryBlock(tlv::KeyDigest, keyDigest->data(), keyDigest->size()));
}
bool
diff --git a/src/name-component.cpp b/src/name-component.cpp
index 1cdd8f9..5cf31aa 100644
--- a/src/name-component.cpp
+++ b/src/name-component.cpp
@@ -69,7 +69,7 @@
}
Component::Component(const Buffer& value)
- : Block(makeBinaryBlock(tlv::NameComponent, value.buf(), value.size()))
+ : Block(makeBinaryBlock(tlv::NameComponent, value.data(), value.size()))
{
}
diff --git a/src/security/pib/detail/key-impl.cpp b/src/security/pib/detail/key-impl.cpp
index e88bdac..c4c65c2 100644
--- a/src/security/pib/detail/key-impl.cpp
+++ b/src/security/pib/detail/key-impl.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).
@@ -63,7 +63,7 @@
m_key = m_pib->getKeyBits(m_keyName);
transform::PublicKey key;
- key.loadPkcs8(m_key.buf(), m_key.size());
+ key.loadPkcs8(m_key.data(), m_key.size());
m_keyType = key.getKeyType();
}
diff --git a/src/security/safe-bag.cpp b/src/security/safe-bag.cpp
index 8315acf..4c8a82d 100644
--- a/src/security/safe-bag.cpp
+++ b/src/security/safe-bag.cpp
@@ -64,7 +64,7 @@
// EncryptedKeyBag
totalLength += encoder.prependByteArrayBlock(tlv::security::EncryptedKeyBag,
- m_encryptedKeyBag.get(),
+ m_encryptedKeyBag.data(),
m_encryptedKeyBag.size());
// Certificate
diff --git a/src/security/transform/buffer-source.cpp b/src/security/transform/buffer-source.cpp
index b47e855..3f45c85 100644
--- a/src/security/transform/buffer-source.cpp
+++ b/src/security/transform/buffer-source.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).
*
@@ -38,7 +38,7 @@
}
BufferSource::BufferSource(const Buffer& buffer)
- : m_buf(buffer.buf())
+ : m_buf(buffer.data())
, m_size(buffer.size())
{
}
diff --git a/src/security/transform/private-key.cpp b/src/security/transform/private-key.cpp
index 8139a0f..84a1875 100644
--- a/src/security/transform/private-key.cpp
+++ b/src/security/transform/private-key.cpp
@@ -115,7 +115,7 @@
{
OBufferStream os;
streamSource(is) >> streamSink(os);
- this->loadPkcs1(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs1(os.buf()->data(), os.buf()->size());
}
void
@@ -123,7 +123,7 @@
{
OBufferStream os;
bufferSource(buf, size) >> base64Decode() >> streamSink(os);
- this->loadPkcs1(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs1(os.buf()->data(), os.buf()->size());
}
void
@@ -131,7 +131,7 @@
{
OBufferStream os;
streamSource(is) >> base64Decode() >> streamSink(os);
- this->loadPkcs1(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs1(os.buf()->data(), os.buf()->size());
}
void
@@ -181,7 +181,7 @@
{
OBufferStream os;
streamSource(is) >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pw, pwLen);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pw, pwLen);
}
void
@@ -189,7 +189,7 @@
{
OBufferStream os;
streamSource(is) >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pwCallback);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pwCallback);
}
void
@@ -197,7 +197,7 @@
{
OBufferStream os;
bufferSource(buf, size) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pw, pwLen);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pw, pwLen);
}
void
@@ -205,7 +205,7 @@
{
OBufferStream os;
bufferSource(buf, size) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pwCallback);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pwCallback);
}
void
@@ -213,7 +213,7 @@
{
OBufferStream os;
streamSource(is) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pw, pwLen);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pw, pwLen);
}
void
@@ -221,7 +221,7 @@
{
OBufferStream os;
streamSource(is) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size(), pwCallback);
+ this->loadPkcs8(os.buf()->data(), os.buf()->size(), pwCallback);
}
void
@@ -309,7 +309,7 @@
BOOST_THROW_EXCEPTION(Error("Cannot convert key to PKCS #1 format"));
auto buffer = make_shared<Buffer>(BIO_pending(membio));
- membio.read(buffer->buf(), buffer->size());
+ membio.read(buffer->data(), buffer->size());
return buffer;
}
@@ -327,7 +327,7 @@
BOOST_THROW_EXCEPTION(Error("Cannot convert key to PKCS #8 format"));
auto buffer = make_shared<Buffer>(BIO_pending(membio));
- membio.read(buffer->buf(), buffer->size());
+ membio.read(buffer->data(), buffer->size());
return buffer;
}
@@ -344,7 +344,7 @@
BOOST_THROW_EXCEPTION(Error("Cannot convert key to PKCS #8 format"));
auto buffer = make_shared<Buffer>(BIO_pending(membio));
- membio.read(buffer->buf(), buffer->size());
+ membio.read(buffer->data(), buffer->size());
return buffer;
}
@@ -366,7 +366,7 @@
BOOST_THROW_EXCEPTION(Error("Failed to estimate output length"));
auto out = make_shared<Buffer>(outlen);
- if (EVP_PKEY_decrypt(ctx, out->buf(), &outlen, cipherText, cipherLen) <= 0)
+ if (EVP_PKEY_decrypt(ctx, out->data(), &outlen, cipherText, cipherLen) <= 0)
BOOST_THROW_EXCEPTION(Error("Failed to decrypt ciphertext"));
out->resize(outlen);
diff --git a/src/security/transform/public-key.cpp b/src/security/transform/public-key.cpp
index 16dd3d1..1cf7e2e 100644
--- a/src/security/transform/public-key.cpp
+++ b/src/security/transform/public-key.cpp
@@ -98,7 +98,7 @@
{
OBufferStream os;
streamSource(is) >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs8(os.buf()->data(), os.buf()->size());
}
void
@@ -106,7 +106,7 @@
{
OBufferStream os;
bufferSource(buf, size) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs8(os.buf()->data(), os.buf()->size());
}
void
@@ -114,7 +114,7 @@
{
OBufferStream os;
streamSource(is) >> base64Decode() >> streamSink(os);
- this->loadPkcs8(os.buf()->buf(), os.buf()->size());
+ this->loadPkcs8(os.buf()->data(), os.buf()->size());
}
void
@@ -184,7 +184,7 @@
BOOST_THROW_EXCEPTION(Error("Failed to estimate output length"));
auto out = make_shared<Buffer>(outlen);
- if (EVP_PKEY_encrypt(ctx, out->buf(), &outlen, plainText, plainLen) <= 0)
+ if (EVP_PKEY_encrypt(ctx, out->data(), &outlen, plainText, plainLen) <= 0)
BOOST_THROW_EXCEPTION(Error("Failed to encrypt plaintext"));
out->resize(outlen);
diff --git a/src/security/v2/certificate.cpp b/src/security/v2/certificate.cpp
index dcd6ae0..dc48c3e 100644
--- a/src/security/v2/certificate.cpp
+++ b/src/security/v2/certificate.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).
@@ -159,9 +159,9 @@
os << "Public key bits:\n";
{
+ using namespace transform;
util::IndentedStream os2(os, " ");
- namespace t = ndn::security::transform;
- t::bufferSource(cert.getPublicKey().buf(), cert.getPublicKey().size()) >> t::base64Encode() >> t::streamSink(os2);
+ bufferSource(cert.getPublicKey().data(), cert.getPublicKey().size()) >> base64Encode() >> streamSink(os2);
}
os << "Signature Information:\n";
diff --git a/src/security/v2/key-chain.cpp b/src/security/v2/key-chain.cpp
index 9f14402..2d0820d 100644
--- a/src/security/v2/key-chain.cpp
+++ b/src/security/v2/key-chain.cpp
@@ -273,7 +273,7 @@
// set up key info in PIB
ConstBufferPtr pubKey = m_tpm->getPublicKey(keyName);
- Key key = identity.addKey(pubKey->buf(), pubKey->size(), keyName);
+ Key key = identity.addKey(pubKey->data(), pubKey->size(), keyName);
NDN_LOG_DEBUG("Requesting self-signing for newly created key " << key.getName());
selfSign(key);
@@ -386,7 +386,7 @@
try {
m_tpm->importPrivateKey(keyName,
- safeBag.getEncryptedKeyBag().buf(), safeBag.getEncryptedKeyBag().size(),
+ safeBag.getEncryptedKeyBag().data(), safeBag.getEncryptedKeyBag().size(),
pw, pwLen);
}
catch (const std::runtime_error&) {
@@ -407,9 +407,9 @@
{
using namespace transform;
PublicKey publicKey;
- publicKey.loadPkcs8(publicKeyBits.buf(), publicKeyBits.size());
+ publicKey.loadPkcs8(publicKeyBits.data(), publicKeyBits.size());
bufferSource(content, sizeof(content)) >> verifierFilter(DigestAlgorithm::SHA256, publicKey,
- sigBits->buf(), sigBits->size())
+ sigBits->data(), sigBits->size())
>> boolSink(isVerified);
}
if (!isVerified) {
@@ -419,7 +419,7 @@
}
Identity id = m_pib->addIdentity(identity);
- Key key = id.addKey(cert.getPublicKey().buf(), cert.getPublicKey().size(), keyName);
+ Key key = id.addKey(cert.getPublicKey().data(), cert.getPublicKey().size(), keyName);
key.addCertificate(cert);
}
@@ -559,7 +559,7 @@
certificate.setFreshnessPeriod(time::hours(1));
// set content
- certificate.setContent(key.getPublicKey().buf(), key.getPublicKey().size());
+ certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
// set signature-info
SignatureInfo signatureInfo;
diff --git a/src/security/verification-helpers.cpp b/src/security/verification-helpers.cpp
index 1d22373..8c42937 100644
--- a/src/security/verification-helpers.cpp
+++ b/src/security/verification-helpers.cpp
@@ -155,13 +155,13 @@
bool
verifySignature(const Data& data, const pib::Key& key)
{
- return verifySignature(parse(data), key.getPublicKey().buf(), key.getPublicKey().size());
+ return verifySignature(parse(data), key.getPublicKey().data(), key.getPublicKey().size());
}
bool
verifySignature(const Interest& interest, const pib::Key& key)
{
- return verifySignature(parse(interest), key.getPublicKey().buf(), key.getPublicKey().size());
+ return verifySignature(parse(interest), key.getPublicKey().data(), key.getPublicKey().size());
}
bool
@@ -209,7 +209,7 @@
return false;
// constant-time buffer comparison to mitigate timing attacks
- return CRYPTO_memcmp(result->buf(), digest, digestLen) == 0;
+ return CRYPTO_memcmp(result->data(), digest, digestLen) == 0;
}
bool
diff --git a/src/util/sha256.cpp b/src/util/sha256.cpp
index 7aeea64..034d12e 100644
--- a/src/util/sha256.cpp
+++ b/src/util/sha256.cpp
@@ -82,14 +82,14 @@
}
// constant-time buffer comparison to mitigate timing attacks
- return CRYPTO_memcmp(lhs.get(), rhs.get(), lhs.size()) == 0;
+ return CRYPTO_memcmp(lhs.data(), rhs.data(), lhs.size()) == 0;
}
Sha256&
Sha256::operator<<(Sha256& src)
{
auto buf = src.computeDigest();
- update(buf->get(), buf->size());
+ update(buf->data(), buf->size());
return *this;
}
diff --git a/src/util/string-helper.cpp b/src/util/string-helper.cpp
index 7665afc..8be94d0 100644
--- a/src/util/string-helper.cpp
+++ b/src/util/string-helper.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).
@@ -60,7 +60,7 @@
void
printHex(std::ostream& os, const Buffer& buffer, bool wantUpperCase)
{
- return printHex(os, buffer.buf(), buffer.size(), wantUpperCase);
+ return printHex(os, buffer.data(), buffer.size(), wantUpperCase);
}
std::string
@@ -74,7 +74,7 @@
std::string
toHex(const Buffer& buffer, bool wantUpperCase)
{
- return toHex(buffer.buf(), buffer.size(), wantUpperCase);
+ return toHex(buffer.data(), buffer.size(), wantUpperCase);
}
int
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index ecda82d..ee80dd1 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -115,7 +115,7 @@
certificate.setFreshnessPeriod(time::hours(1));
// set content
- certificate.setContent(key.getPublicKey().buf(), key.getPublicKey().size());
+ certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
// set signature-info
SignatureInfo info;
diff --git a/tests/unit-tests/data.t.cpp b/tests/unit-tests/data.t.cpp
index fabd22c..91d46f9 100644
--- a/tests/unit-tests/data.t.cpp
+++ b/tests/unit-tests/data.t.cpp
@@ -194,7 +194,7 @@
}
auto buf = sig.buf();
tlv::writeVarNumber(os, buf->size());
- os.write(reinterpret_cast<const char*>(buf->data()), buf->size());
+ os.write(buf->get<char>(), buf->size());
Block signatureValue(os.buf());
Signature signature(signatureInfo, signatureValue);
diff --git a/tests/unit-tests/encoding/encoding-buffer.t.cpp b/tests/unit-tests/encoding/encoding-buffer.t.cpp
index 00240b8..153b7e9 100644
--- a/tests/unit-tests/encoding/encoding-buffer.t.cpp
+++ b/tests/unit-tests/encoding/encoding-buffer.t.cpp
@@ -40,8 +40,6 @@
BOOST_AUTO_TEST_CASE(ConstructFromBlock)
{
auto buf = make_shared<Buffer>(10);
- std::memset(buf->get(), 0, 10);
-
Block block(0xab, buf);
block.encode();
diff --git a/tests/unit-tests/ims/in-memory-storage.t.cpp b/tests/unit-tests/ims/in-memory-storage.t.cpp
index 67d87f2..b493001 100644
--- a/tests/unit-tests/ims/in-memory-storage.t.cpp
+++ b/tests/unit-tests/ims/in-memory-storage.t.cpp
@@ -31,7 +31,7 @@
#include "make-interest-data.hpp"
#include "../unit-test-time-fixture.hpp"
-#include <boost/mpl/list.hpp>
+#include <boost/mpl/vector.hpp>
namespace ndn {
namespace tests {
@@ -41,10 +41,10 @@
BOOST_AUTO_TEST_SUITE(Ims)
BOOST_AUTO_TEST_SUITE(TestInMemoryStorage)
-using InMemoryStorages = boost::mpl::list<InMemoryStoragePersistent,
- InMemoryStorageFifo,
- InMemoryStorageLfu,
- InMemoryStorageLru>;
+using InMemoryStorages = boost::mpl::vector<InMemoryStoragePersistent,
+ InMemoryStorageFifo,
+ InMemoryStorageLfu,
+ InMemoryStorageLru>;
BOOST_AUTO_TEST_CASE_TEMPLATE(Insertion, T, InMemoryStorages)
{
@@ -395,7 +395,7 @@
ConstBufferPtr digest1 = util::Sha256::computeDigest(data->wireEncode().wire(), data->wireEncode().size());
shared_ptr<Interest> interest = makeInterest("");
- interest->setName(Name(name).appendImplicitSha256Digest(digest1->buf(), digest1->size()));
+ interest->setName(Name(name).appendImplicitSha256Digest(digest1->data(), digest1->size()));
interest->setMinSuffixComponents(0);
interest->setMaxSuffixComponents(0);
@@ -621,9 +621,9 @@
BOOST_CHECK_EQUAL(found3->getName(), "/c/a");
}
-using InMemoryStoragesLimited = boost::mpl::list<InMemoryStorageFifo,
- InMemoryStorageLfu,
- InMemoryStorageLru>;
+using InMemoryStoragesLimited = boost::mpl::vector<InMemoryStorageFifo,
+ InMemoryStorageLfu,
+ InMemoryStorageLru>;
BOOST_AUTO_TEST_CASE_TEMPLATE(SetCapacity, T, InMemoryStoragesLimited)
{
diff --git a/tests/unit-tests/security/digest-sha256.t.cpp b/tests/unit-tests/security/digest-sha256.t.cpp
index 7855058..f3d7bb7 100644
--- a/tests/unit-tests/security/digest-sha256.t.cpp
+++ b/tests/unit-tests/security/digest-sha256.t.cpp
@@ -41,7 +41,7 @@
char content[6] = "1234\n";
ConstBufferPtr buf = util::Sha256::computeDigest(reinterpret_cast<uint8_t*>(content), 5);
- BOOST_CHECK_EQUAL(toHex(buf->buf(), buf->size(), false),
+ BOOST_CHECK_EQUAL(toHex(buf->data(), buf->size(), false),
"a883dafc480d466ee04e0d6da986bd78eb1fdd2178d04693723da3a8f95d42f4");
}
diff --git a/tests/unit-tests/security/pib/detail/identity-impl.t.cpp b/tests/unit-tests/security/pib/detail/identity-impl.t.cpp
index 2f35d2f..0eaabdb 100644
--- a/tests/unit-tests/security/pib/detail/identity-impl.t.cpp
+++ b/tests/unit-tests/security/pib/detail/identity-impl.t.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,9 +22,9 @@
#include "security/pib/detail/identity-impl.hpp"
#include "security/pib/pib.hpp"
#include "security/pib/pib-memory.hpp"
-#include "../pib-data-fixture.hpp"
#include "boost-test.hpp"
+#include "../pib-data-fixture.hpp"
namespace ndn {
namespace security {
@@ -64,7 +64,7 @@
BOOST_REQUIRE_THROW(identity1.setDefaultKey(id1Key1Name), Pib::Error);
// add key
- identity1.addKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ identity1.addKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_NO_THROW(identity1.getKey(id1Key1Name));
// new key becomes default key when there is no default key
@@ -79,7 +79,7 @@
BOOST_CHECK_THROW(identity1.getDefaultKey(), Pib::Error);
// set default key directly
- BOOST_REQUIRE_NO_THROW(identity1.setDefaultKey(id1Key1.buf(), id1Key1.size(), id1Key1Name));
+ BOOST_REQUIRE_NO_THROW(identity1.setDefaultKey(id1Key1.data(), id1Key1.size(), id1Key1Name));
BOOST_REQUIRE_NO_THROW(identity1.getDefaultKey());
BOOST_CHECK_NO_THROW(identity1.getKey(id1Key1Name));
@@ -89,7 +89,7 @@
BOOST_CHECK(defaultKey1.getPublicKey() == id1Key1);
// add another key
- identity1.addKey(id1Key2.buf(), id1Key2.size(), id1Key2Name);
+ identity1.addKey(id1Key2.data(), id1Key2.size(), id1Key2Name);
BOOST_CHECK_EQUAL(identity1.getKeys().size(), 2);
// set default key through name
@@ -105,7 +105,7 @@
BOOST_CHECK_EQUAL(identity1.getKeys().size(), 1);
// set default key directly again, change the default setting
- BOOST_REQUIRE_NO_THROW(identity1.setDefaultKey(id1Key1.buf(), id1Key1.size(), id1Key1Name));
+ BOOST_REQUIRE_NO_THROW(identity1.setDefaultKey(id1Key1.data(), id1Key1.size(), id1Key1Name));
const Key& defaultKey3 = identity1.getDefaultKey();
BOOST_CHECK_EQUAL(defaultKey3.getName(), id1Key1Name);
BOOST_CHECK(defaultKey3.getPublicKey() == id1Key1);
@@ -126,10 +126,10 @@
auto pibImpl = make_shared<pib::PibMemory>();
IdentityImpl identity1(id1, pibImpl, true);
- identity1.addKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ identity1.addKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK(identity1.getKey(id1Key1Name).getPublicKey() == id1Key1);
- identity1.addKey(id1Key2.buf(), id1Key2.size(), id1Key1Name); // overwriting key should work
+ identity1.addKey(id1Key2.data(), id1Key2.size(), id1Key1Name); // overwriting key should work
BOOST_CHECK(identity1.getKey(id1Key1Name).getPublicKey() == id1Key2);
}
@@ -140,11 +140,11 @@
BOOST_CHECK_THROW(IdentityImpl(id1, pibImpl, false), Pib::Error);
IdentityImpl identity1(id1, pibImpl, true);
- identity1.addKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
- BOOST_CHECK_THROW(identity1.addKey(id2Key1.buf(), id2Key1.size(), id2Key1Name), std::invalid_argument);
+ identity1.addKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
+ BOOST_CHECK_THROW(identity1.addKey(id2Key1.data(), id2Key1.size(), id2Key1Name), std::invalid_argument);
BOOST_CHECK_THROW(identity1.removeKey(id2Key1Name), std::invalid_argument);
BOOST_CHECK_THROW(identity1.getKey(id2Key1Name), std::invalid_argument);
- BOOST_CHECK_THROW(identity1.setDefaultKey(id2Key1.buf(), id2Key1.size(), id2Key1Name), std::invalid_argument);
+ BOOST_CHECK_THROW(identity1.setDefaultKey(id2Key1.data(), id2Key1.size(), id2Key1Name), std::invalid_argument);
BOOST_CHECK_THROW(identity1.setDefaultKey(id2Key1Name), std::invalid_argument);
}
diff --git a/tests/unit-tests/security/pib/detail/key-impl.t.cpp b/tests/unit-tests/security/pib/detail/key-impl.t.cpp
index 5257113..ec51751 100644
--- a/tests/unit-tests/security/pib/detail/key-impl.t.cpp
+++ b/tests/unit-tests/security/pib/detail/key-impl.t.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).
@@ -36,14 +36,14 @@
BOOST_AUTO_TEST_SUITE(Security)
BOOST_AUTO_TEST_SUITE(Pib)
BOOST_AUTO_TEST_SUITE(Detail)
-BOOST_FIXTURE_TEST_SUITE(TestKeyImpl, ndn::security::tests::PibDataFixture)
+BOOST_FIXTURE_TEST_SUITE(TestKeyImpl, security::tests::PibDataFixture)
using security::Pib;
BOOST_AUTO_TEST_CASE(Basic)
{
auto pibImpl = make_shared<pib::PibMemory>();
- KeyImpl key11(id1Key1Name, id1Key1.buf(), id1Key1.size(), pibImpl);
+ KeyImpl key11(id1Key1Name, id1Key1.data(), id1Key1.size(), pibImpl);
BOOST_CHECK_EQUAL(key11.getName(), id1Key1Name);
BOOST_CHECK_EQUAL(key11.getIdentity(), id1);
@@ -60,7 +60,7 @@
BOOST_AUTO_TEST_CASE(CertificateOperation)
{
auto pibImpl = make_shared<pib::PibMemory>();
- KeyImpl key11(id1Key1Name, id1Key1.buf(), id1Key1.size(), pibImpl);
+ KeyImpl key11(id1Key1Name, id1Key1.data(), id1Key1.size(), pibImpl);
BOOST_CHECK_NO_THROW(KeyImpl(id1Key1Name, pibImpl));
// key does not have any certificate
@@ -141,10 +141,10 @@
auto pibImpl = make_shared<pib::PibMemory>();
BOOST_CHECK_THROW(KeyImpl(id1Key1Name, pibImpl), Pib::Error);
- KeyImpl(id1Key1Name, id1Key1.buf(), id1Key1.size(), pibImpl);
+ KeyImpl(id1Key1Name, id1Key1.data(), id1Key1.size(), pibImpl);
KeyImpl key1(id1Key1Name, pibImpl);
- KeyImpl(id1Key1Name, id1Key2.buf(), id1Key2.size(), pibImpl); // overwriting of the key should work
+ KeyImpl(id1Key1Name, id1Key2.data(), id1Key2.size(), pibImpl); // overwriting of the key should work
KeyImpl key2(id1Key1Name, pibImpl);
BOOST_CHECK(key1.getPublicKey() != key2.getPublicKey()); // key1 cached the original public key
@@ -173,12 +173,12 @@
auto pibImpl = make_shared<pib::PibMemory>();
BOOST_CHECK_THROW(KeyImpl(id1Key1Name, pibImpl), Pib::Error);
- KeyImpl key11(id1Key1Name, id1Key1.buf(), id1Key1.size(), pibImpl);
+ KeyImpl key11(id1Key1Name, id1Key1.data(), id1Key1.size(), pibImpl);
BOOST_CHECK_THROW(KeyImpl(Name("/wrong"), pibImpl), std::invalid_argument);
- BOOST_CHECK_THROW(KeyImpl(Name("/wrong"), id1Key1.buf(), id1Key1.size(), pibImpl), std::invalid_argument);
+ BOOST_CHECK_THROW(KeyImpl(Name("/wrong"), id1Key1.data(), id1Key1.size(), pibImpl), std::invalid_argument);
Buffer wrongKey;
- BOOST_CHECK_THROW(KeyImpl(id1Key2Name, wrongKey.buf(), wrongKey.size(), pibImpl), std::invalid_argument);
+ BOOST_CHECK_THROW(KeyImpl(id1Key2Name, wrongKey.data(), wrongKey.size(), pibImpl), std::invalid_argument);
key11.addCertificate(id1Key1Cert1);
BOOST_CHECK_THROW(key11.addCertificate(id1Key2Cert1), std::invalid_argument);
diff --git a/tests/unit-tests/security/pib/identity.t.cpp b/tests/unit-tests/security/pib/identity.t.cpp
index 239da12..6f631e5 100644
--- a/tests/unit-tests/security/pib/identity.t.cpp
+++ b/tests/unit-tests/security/pib/identity.t.cpp
@@ -82,12 +82,12 @@
BOOST_CHECK_NE(identity1, Identity());
BOOST_CHECK_EQUAL(Identity(), Identity());
- identity1.addKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ identity1.addKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_NO_THROW(identity2.getKey(id1Key1Name));
identity2.removeKey(id1Key1Name);
BOOST_CHECK_THROW(identity1.getKey(id1Key1Name), Pib::Error);
- identity1.setDefaultKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ identity1.setDefaultKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_NO_THROW(identity2.getDefaultKey());
}
diff --git a/tests/unit-tests/security/pib/key-container.t.cpp b/tests/unit-tests/security/pib/key-container.t.cpp
index 5b7961e..c04a415 100644
--- a/tests/unit-tests/security/pib/key-container.t.cpp
+++ b/tests/unit-tests/security/pib/key-container.t.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).
@@ -49,7 +49,7 @@
BOOST_CHECK_EQUAL(container.getLoadedKeys().size(), 0);
// add the first key
- Key key11 = container.add(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ Key key11 = container.add(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_EQUAL(key11.getName(), id1Key1Name);
BOOST_CHECK(key11.getPublicKey() == id1Key1);
BOOST_CHECK_EQUAL(container.size(), 1);
@@ -57,7 +57,7 @@
BOOST_CHECK(container.find(id1Key1Name) != container.end());
// add the same key again
- Key key12 = container.add(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ Key key12 = container.add(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_EQUAL(key12.getName(), id1Key1Name);
BOOST_CHECK(key12.getPublicKey() == id1Key1);
BOOST_CHECK_EQUAL(container.size(), 1);
@@ -65,7 +65,7 @@
BOOST_CHECK(container.find(id1Key1Name) != container.end());
// add the second key
- Key key21 = container.add(id1Key2.buf(), id1Key2.size(), id1Key2Name);
+ Key key21 = container.add(id1Key2.data(), id1Key2.size(), id1Key2Name);
BOOST_CHECK_EQUAL(key21.getName(), id1Key2Name);
BOOST_CHECK(key21.getPublicKey() == id1Key2);
BOOST_CHECK_EQUAL(container.size(), 2);
@@ -122,7 +122,7 @@
KeyContainer container(id1, pibImpl);
- BOOST_CHECK_THROW(container.add(id2Key1.buf(), id2Key1.size(), id2Key1Name), std::invalid_argument);
+ BOOST_CHECK_THROW(container.add(id2Key1.data(), id2Key1.size(), id2Key1Name), std::invalid_argument);
BOOST_CHECK_THROW(container.remove(id2Key1Name), std::invalid_argument);
BOOST_CHECK_THROW(container.get(id2Key1Name), std::invalid_argument);
}
@@ -132,8 +132,8 @@
auto pibImpl = make_shared<PibMemory>();
KeyContainer container(id1, pibImpl);
- container.add(id1Key1.buf(), id1Key1.size(), id1Key1Name);
- container.add(id1Key2.buf(), id1Key2.size(), id1Key2Name);
+ container.add(id1Key1.data(), id1Key1.size(), id1Key1Name);
+ container.add(id1Key2.data(), id1Key2.size(), id1Key2Name);
std::set<Name> keyNames;
keyNames.insert(id1Key1Name);
diff --git a/tests/unit-tests/security/pib/key.t.cpp b/tests/unit-tests/security/pib/key.t.cpp
index a3543a3..2a90b9c 100644
--- a/tests/unit-tests/security/pib/key.t.cpp
+++ b/tests/unit-tests/security/pib/key.t.cpp
@@ -54,7 +54,8 @@
else
BOOST_CHECK(true);
- auto keyImpl = make_shared<KeyImpl>(id1Key1Name, id1Key1.buf(), id1Key1.size(), make_shared<pib::PibMemory>());
+ auto keyImpl = make_shared<KeyImpl>(id1Key1Name, id1Key1.data(), id1Key1.size(),
+ make_shared<pib::PibMemory>());
key = Key(keyImpl);
BOOST_CHECK_EQUAL(static_cast<bool>(key), true);
@@ -76,7 +77,8 @@
{
using security::pib::detail::KeyImpl;
- auto keyImpl = make_shared<KeyImpl>(id1Key1Name, id1Key1.buf(), id1Key1.size(), make_shared<pib::PibMemory>());
+ auto keyImpl = make_shared<KeyImpl>(id1Key1Name, id1Key1.data(), id1Key1.size(),
+ make_shared<pib::PibMemory>());
Key key1(keyImpl);
Key key2(keyImpl);
BOOST_CHECK_EQUAL(key1, key2);
diff --git a/tests/unit-tests/security/pib/pib-impl.t.cpp b/tests/unit-tests/security/pib/pib-impl.t.cpp
index 2677e9d..265c111 100644
--- a/tests/unit-tests/security/pib/pib-impl.t.cpp
+++ b/tests/unit-tests/security/pib/pib-impl.t.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).
@@ -165,7 +165,7 @@
BOOST_CHECK_EQUAL(this->pib.hasIdentity(this->id1), false);
// add id1Key1, should be default, id1 should be added implicitly
- this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.buf(), this->id1Key1.size());
+ this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.data(), this->id1Key1.size());
BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), true);
BOOST_CHECK_EQUAL(this->pib.hasIdentity(this->id1), true);
const Buffer& keyBits = this->pib.getKeyBits(this->id1Key1Name);
@@ -174,7 +174,7 @@
BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id1), this->id1Key1Name);
// add id1Key2, should not be default
- this->pib.addKey(this->id1, this->id1Key2Name, this->id1Key2.buf(), this->id1Key2.size());
+ this->pib.addKey(this->id1, this->id1Key2Name, this->id1Key2.data(), this->id1Key2.size());
BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key2Name), true);
BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id1), this->id1Key1Name);
@@ -193,7 +193,7 @@
BOOST_CHECK_THROW(this->pib.getDefaultKeyOfIdentity(this->id1), Pib::Error);
// add id1Key2 back, should be default
- this->pib.addKey(this->id1, this->id1Key2Name, this->id1Key2.buf(), this->id1Key2.size());
+ this->pib.addKey(this->id1, this->id1Key2Name, this->id1Key2.data(), this->id1Key2.size());
BOOST_CHECK_NO_THROW(this->pib.getKeyBits(this->id1Key2Name));
BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id1), this->id1Key2Name);
@@ -275,11 +275,11 @@
this->pib.removeIdentity(this->id1);
BOOST_CHECK_THROW(this->pib.getDefaultIdentity(), Pib::Error);
- this->pib.addKey(this->id2, this->id2Key1Name, this->id2Key1.buf(), this->id2Key1.size());
+ this->pib.addKey(this->id2, this->id2Key1Name, this->id2Key1.data(), this->id2Key1.size());
BOOST_CHECK_EQUAL(this->pib.getDefaultIdentity(), this->id2);
BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id2), this->id2Key1Name);
- this->pib.addKey(this->id2, this->id2Key2Name, this->id2Key2.buf(), this->id2Key2.size());
+ this->pib.addKey(this->id2, this->id2Key2Name, this->id2Key2.data(), this->id2Key2.size());
BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id2), this->id2Key1Name);
this->pib.removeKey(this->id2Key1Name);
@@ -303,13 +303,13 @@
BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), false);
// add id1Key1
- this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.buf(), this->id1Key1.size());
+ this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.data(), this->id1Key1.size());
BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), true);
const Buffer& keyBits = this->pib.getKeyBits(this->id1Key1Name);
BOOST_CHECK(keyBits == this->id1Key1);
// check overwrite, add a key with the same name.
- this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key2.buf(), this->id1Key2.size());
+ this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key2.data(), this->id1Key2.size());
const Buffer& keyBits2 = this->pib.getKeyBits(this->id1Key1Name);
BOOST_CHECK(keyBits2 == this->id1Key2);
@@ -318,7 +318,7 @@
BOOST_CHECK_EQUAL(this->pib.hasCertificate(this->id1Key1Cert1.getName()), false);
// add id1Key1Cert1
- this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.buf(), this->id1Key1.size());
+ this->pib.addKey(this->id1, this->id1Key1Name, this->id1Key1.data(), this->id1Key1.size());
this->pib.addCertificate(this->id1Key1Cert1);
BOOST_CHECK_EQUAL(this->pib.hasCertificate(this->id1Key1Cert1.getName()), true);
diff --git a/tests/unit-tests/security/pib/pib.t.cpp b/tests/unit-tests/security/pib/pib.t.cpp
index de436b4..5ae91b5 100644
--- a/tests/unit-tests/security/pib/pib.t.cpp
+++ b/tests/unit-tests/security/pib/pib.t.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).
@@ -53,7 +53,7 @@
BOOST_CHECK(false);
// key
- Key key = id.addKey(id1Key1.buf(), id1Key1.size(), id1Key1Name);
+ Key key = id.addKey(id1Key1.data(), id1Key1.size(), id1Key1Name);
BOOST_CHECK_EQUAL(static_cast<bool>(key), true);
BOOST_CHECK_EQUAL(!key, false);
diff --git a/tests/unit-tests/security/tpm/back-end.t.cpp b/tests/unit-tests/security/tpm/back-end.t.cpp
index 9f7104d..ad8e39c 100644
--- a/tests/unit-tests/security/tpm/back-end.t.cpp
+++ b/tests/unit-tests/security/tpm/back-end.t.cpp
@@ -101,14 +101,14 @@
transform::PublicKey pubKey;
ConstBufferPtr pubKeyBits = key->derivePublicKey();
- pubKey.loadPkcs8(pubKeyBits->buf(), pubKeyBits->size());
+ pubKey.loadPkcs8(pubKeyBits->data(), pubKeyBits->size());
bool result;
{
using namespace transform;
- bufferSource(content, sizeof(content)) >> verifierFilter(DigestAlgorithm::SHA256, pubKey,
- sigBlock.value(), sigBlock.value_size())
- >> boolSink(result);
+ bufferSource(content, sizeof(content)) >>
+ verifierFilter(DigestAlgorithm::SHA256, pubKey, sigBlock.value(), sigBlock.value_size()) >>
+ boolSink(result);
}
BOOST_CHECK_EQUAL(result, true);
@@ -131,11 +131,11 @@
transform::PublicKey pubKey;
ConstBufferPtr pubKeyBits = key->derivePublicKey();
- pubKey.loadPkcs8(pubKeyBits->buf(), pubKeyBits->size());
+ pubKey.loadPkcs8(pubKeyBits->data(), pubKeyBits->size());
ConstBufferPtr cipherText = pubKey.encrypt(content, sizeof(content));
- ConstBufferPtr plainText = key->decrypt(cipherText->buf(), cipherText->size());
+ ConstBufferPtr plainText = key->decrypt(cipherText->data(), cipherText->size());
BOOST_CHECK_EQUAL_COLLECTIONS(content, content + sizeof(content),
plainText->begin(), plainText->end());
@@ -160,7 +160,7 @@
transform::PublicKey pubKey;
ConstBufferPtr pubKeyBits = key->derivePublicKey();
- pubKey.loadPkcs8(pubKeyBits->buf(), pubKeyBits->size());
+ pubKey.loadPkcs8(pubKeyBits->data(), pubKeyBits->size());
bool result;
{
@@ -219,14 +219,14 @@
sKey.savePkcs8(os, password.c_str(), password.size());
ConstBufferPtr privateKeyBuffer = os.buf();
- tpm.importKey(keyName, privateKeyBuffer->buf(), privateKeyBuffer->size(), password.c_str(), password.size());
+ tpm.importKey(keyName, privateKeyBuffer->data(), privateKeyBuffer->size(), password.c_str(), password.size());
BOOST_CHECK_EQUAL(tpm.hasKey(keyName), true);
ConstBufferPtr exportedKey = tpm.exportKey(keyName, password.c_str(), password.size());
BOOST_CHECK_EQUAL(tpm.hasKey(keyName), true);
transform::PrivateKey sKey2;
- sKey2.loadPkcs8(exportedKey->buf(), exportedKey->size(), password.c_str(), password.size());
+ sKey2.loadPkcs8(exportedKey->data(), exportedKey->size(), password.c_str(), password.size());
OBufferStream os2;
sKey.savePkcs1Base64(os2);
ConstBufferPtr pkcs1Buffer = os2.buf();
diff --git a/tests/unit-tests/security/transform/private-key.t.cpp b/tests/unit-tests/security/transform/private-key.t.cpp
index 6a6ba93..76c541f 100644
--- a/tests/unit-tests/security/transform/private-key.t.cpp
+++ b/tests/unit-tests/security/transform/private-key.t.cpp
@@ -143,7 +143,7 @@
checkPkcs8Encoding(ConstBufferPtr encoding, const std::string& password, ConstBufferPtr pkcs1)
{
PrivateKey sKey;
- sKey.loadPkcs8(encoding->buf(), encoding->size(), password.c_str(), password.size());
+ sKey.loadPkcs8(encoding->data(), encoding->size(), password.c_str(), password.size());
OBufferStream os;
sKey.savePkcs1(os);
BOOST_CHECK_EQUAL_COLLECTIONS(pkcs1->begin(), pkcs1->end(),
@@ -167,7 +167,7 @@
OBufferStream os;
bufferSource(sKeyPkcs1Base64, sKeyPkcs1Base64Len) >> base64Decode() >> streamSink(os);
ConstBufferPtr sKeyPkcs1Buf = os.buf();
- const uint8_t* sKeyPkcs1 = sKeyPkcs1Buf->buf();
+ const uint8_t* sKeyPkcs1 = sKeyPkcs1Buf->data();
size_t sKeyPkcs1Len = sKeyPkcs1Buf->size();
// load key in base64-encoded pkcs1 format
@@ -203,7 +203,7 @@
size_t sKeyPkcs8Base64Len = dataSet.privateKeyPkcs8.size();
OBufferStream os4;
bufferSource(sKeyPkcs8Base64, sKeyPkcs8Base64Len) >> base64Decode() >> streamSink(os4);
- const uint8_t* sKeyPkcs8 = os4.buf()->buf();
+ const uint8_t* sKeyPkcs8 = os4.buf()->data();
size_t sKeyPkcs8Len = os4.buf()->size();
std::string password("password");
@@ -309,7 +309,7 @@
OBufferStream os;
bufferSource(cipherTextBase64) >> base64Decode() >> streamSink(os);
- auto decrypted = sKey.decrypt(os.buf()->buf(), os.buf()->size());
+ auto decrypted = sKey.decrypt(os.buf()->data(), os.buf()->size());
BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
decrypted->begin(), decrypted->end());
}
@@ -331,7 +331,7 @@
const uint8_t plainText[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
auto cipherText = pKey.encrypt(plainText, sizeof(plainText));
- auto decrypted = sKey.decrypt(cipherText->buf(), cipherText->size());
+ auto decrypted = sKey.decrypt(cipherText->data(), cipherText->size());
BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
decrypted->begin(), decrypted->end());
}
@@ -348,7 +348,7 @@
OBufferStream os;
bufferSource("Y2lhbyFob2xhIWhlbGxvIQ==") >> base64Decode() >> streamSink(os);
- BOOST_CHECK_THROW(sKey.decrypt(os.buf()->buf(), os.buf()->size()), PrivateKey::Error);
+ BOOST_CHECK_THROW(sKey.decrypt(os.buf()->data(), os.buf()->size()), PrivateKey::Error);
}
using KeyParams = boost::mpl::vector<RsaKeyParams, EcKeyParams>;
@@ -358,7 +358,7 @@
unique_ptr<PrivateKey> sKey = generatePrivateKey(T());
PublicKey pKey;
ConstBufferPtr pKeyBits = sKey->derivePublicKey();
- pKey.loadPkcs8(pKeyBits->buf(), pKeyBits->size());
+ pKey.loadPkcs8(pKeyBits->data(), pKeyBits->size());
const uint8_t data[] = {0x01, 0x02, 0x03, 0x04};
OBufferStream os;
@@ -369,7 +369,7 @@
ConstBufferPtr sig = os.buf();
bool result = false;
BOOST_REQUIRE_NO_THROW(bufferSource(data, sizeof(data)) >>
- verifierFilter(DigestAlgorithm::SHA256, pKey, sig->buf(), sig->size()) >>
+ verifierFilter(DigestAlgorithm::SHA256, pKey, sig->data(), sig->size()) >>
boolSink(result));
BOOST_CHECK(result);
diff --git a/tests/unit-tests/security/transform/public-key.t.cpp b/tests/unit-tests/security/transform/public-key.t.cpp
index fee246f..20e071c 100644
--- a/tests/unit-tests/security/transform/public-key.t.cpp
+++ b/tests/unit-tests/security/transform/public-key.t.cpp
@@ -73,7 +73,7 @@
OBufferStream os;
bufferSource(pKeyPkcs8Base64, pKeyPkcs8Base64Len) >> base64Decode() >> streamSink(os);
ConstBufferPtr pKeyPkcs8Buf = os.buf();
- const uint8_t* pKeyPkcs8 = pKeyPkcs8Buf->buf();
+ const uint8_t* pKeyPkcs8 = pKeyPkcs8Buf->data();
size_t pKeyPkcs8Len = pKeyPkcs8Buf->size();
PublicKey pKey1;
@@ -119,7 +119,7 @@
OBufferStream os;
bufferSource("Y2lhbyFob2xhIWhlbGxvIQ==") >> base64Decode() >> streamSink(os);
- BOOST_CHECK_THROW(pKey.encrypt(os.buf()->buf(), os.buf()->size()), PublicKey::Error);
+ BOOST_CHECK_THROW(pKey.encrypt(os.buf()->data(), os.buf()->size()), PublicKey::Error);
}
BOOST_AUTO_TEST_SUITE_END() // TestPublicKey
diff --git a/tests/unit-tests/security/transform/signer-filter.t.cpp b/tests/unit-tests/security/transform/signer-filter.t.cpp
index 450f9ff..5db93a7 100644
--- a/tests/unit-tests/security/transform/signer-filter.t.cpp
+++ b/tests/unit-tests/security/transform/signer-filter.t.cpp
@@ -90,7 +90,7 @@
bufferSource(data, sizeof(data)) >> signerFilter(DigestAlgorithm::SHA256, sKey) >> streamSink(os2);
auto sig = os2.buf();
- BOOST_CHECK(verifySignature(data, sizeof(data), sig->buf(), sig->size(), pubKey->buf(), pubKey->size()));
+ BOOST_CHECK(verifySignature(data, sizeof(data), sig->data(), sig->size(), pubKey->data(), pubKey->size()));
}
BOOST_AUTO_TEST_CASE(Ecdsa)
@@ -127,7 +127,7 @@
bufferSource(data, sizeof(data)) >> signerFilter(DigestAlgorithm::SHA256, sKey) >> streamSink(os2);
auto sig = os2.buf();
- BOOST_CHECK(verifySignature(data, sizeof(data), sig->buf(), sig->size(), pubKey->buf(), pubKey->size()));
+ BOOST_CHECK(verifySignature(data, sizeof(data), sig->data(), sig->size(), pubKey->data(), pubKey->size()));
}
BOOST_AUTO_TEST_CASE(InvalidKey)
diff --git a/tests/unit-tests/security/transform/strip-space.t.cpp b/tests/unit-tests/security/transform/strip-space.t.cpp
index bea3191..431aed2 100644
--- a/tests/unit-tests/security/transform/strip-space.t.cpp
+++ b/tests/unit-tests/security/transform/strip-space.t.cpp
@@ -64,7 +64,7 @@
"velitessecillumdoloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproi"
"dent,suntinculpaquiofficiadeseruntmollitanimidestlaborum.");
ConstBufferPtr buf = os.buf();
- BOOST_CHECK_EQUAL(std::string(reinterpret_cast<const char*>(buf->get()), buf->size()), expected);
+ BOOST_CHECK_EQUAL(std::string(buf->get<char>(), buf->size()), expected);
}
BOOST_AUTO_TEST_SUITE_END() // TestStripSpace
diff --git a/tests/unit-tests/security/transform/verifier-filter.t.cpp b/tests/unit-tests/security/transform/verifier-filter.t.cpp
index 217cf87..ae2f2ee 100644
--- a/tests/unit-tests/security/transform/verifier-filter.t.cpp
+++ b/tests/unit-tests/security/transform/verifier-filter.t.cpp
@@ -85,7 +85,7 @@
auto pubKey = os1.buf();
PublicKey pKey;
- pKey.loadPkcs8(pubKey->buf(), pubKey->size());
+ pKey.loadPkcs8(pubKey->data(), pubKey->size());
PrivateKey sKey;
sKey.loadPkcs1Base64(reinterpret_cast<const uint8_t*>(privateKeyPkcs1.data()), privateKeyPkcs1.size());
@@ -94,11 +94,11 @@
bufferSource(data, sizeof(data)) >> signerFilter(DigestAlgorithm::SHA256, sKey) >> streamSink(os2);
auto sig = os2.buf();
- BOOST_CHECK_THROW(VerifierFilter(DigestAlgorithm::NONE, pKey, sig->buf(), sig->size()), Error);
+ BOOST_CHECK_THROW(VerifierFilter(DigestAlgorithm::NONE, pKey, sig->data(), sig->size()), Error);
bool result = false;
bufferSource(data, sizeof(data)) >>
- verifierFilter(DigestAlgorithm::SHA256, pKey, sig->buf(), sig->size()) >>
+ verifierFilter(DigestAlgorithm::SHA256, pKey, sig->data(), sig->size()) >>
boolSink(result);
BOOST_CHECK_EQUAL(result, true);
@@ -130,7 +130,7 @@
auto pubKey = os1.buf();
PublicKey pKey;
- pKey.loadPkcs8(pubKey->buf(), pubKey->size());
+ pKey.loadPkcs8(pubKey->data(), pubKey->size());
PrivateKey sKey;
sKey.loadPkcs1Base64(reinterpret_cast<const uint8_t*>(privateKeyPkcs1.data()), privateKeyPkcs1.size());
@@ -139,11 +139,11 @@
bufferSource(data, sizeof(data)) >> signerFilter(DigestAlgorithm::SHA256, sKey) >> streamSink(os2);
auto sig = os2.buf();
- BOOST_CHECK_THROW(VerifierFilter(DigestAlgorithm::NONE, pKey, sig->buf(), sig->size()), Error);
+ BOOST_CHECK_THROW(VerifierFilter(DigestAlgorithm::NONE, pKey, sig->data(), sig->size()), Error);
bool result = false;
bufferSource(data, sizeof(data)) >>
- verifierFilter(DigestAlgorithm::SHA256, pKey, sig->buf(), sig->size()) >>
+ verifierFilter(DigestAlgorithm::SHA256, pKey, sig->data(), sig->size()) >>
boolSink(result);
BOOST_CHECK_EQUAL(result, true);
diff --git a/tests/unit-tests/security/v2/validator.t.cpp b/tests/unit-tests/security/v2/validator.t.cpp
index 9945ef9..ac5ca86 100644
--- a/tests/unit-tests/security/v2/validator.t.cpp
+++ b/tests/unit-tests/security/v2/validator.t.cpp
@@ -275,7 +275,7 @@
certificate.setFreshnessPeriod(time::hours(1));
// set content
- certificate.setContent(requestedKey.getPublicKey().buf(), requestedKey.getPublicKey().size());
+ certificate.setContent(requestedKey.getPublicKey().data(), requestedKey.getPublicKey().size());
// set signature-info
SignatureInfo info;
diff --git a/tests/unit-tests/security/verification-helpers.t.cpp b/tests/unit-tests/security/verification-helpers.t.cpp
index d1654d7..41aed81 100644
--- a/tests/unit-tests/security/verification-helpers.t.cpp
+++ b/tests/unit-tests/security/verification-helpers.t.cpp
@@ -430,24 +430,24 @@
v2::Certificate cert(Block(dataset.cert.data(), dataset.cert.size()));
Buffer keyRaw = cert.getPublicKey();
v2::PublicKey key;
- key.loadPkcs8(keyRaw.buf(), keyRaw.size());
+ key.loadPkcs8(keyRaw.data(), keyRaw.size());
Data data(Block(dataset.goodData.data(), dataset.goodData.size()));
Data badSigData(Block(dataset.badSigData.data(), dataset.badSigData.size()));
Interest interest(Block(dataset.goodInterest.data(), dataset.goodInterest.size()));
Interest badSigInterest(Block(dataset.badSigInterest.data(), dataset.badSigInterest.size()));
BOOST_CHECK(verifySignature(data, key));
- BOOST_CHECK(verifySignature(data, keyRaw.buf(), keyRaw.size()));
+ BOOST_CHECK(verifySignature(data, keyRaw.data(), keyRaw.size()));
BOOST_CHECK(verifySignature(data, cert));
BOOST_CHECK(verifySignature(interest, key));
- BOOST_CHECK(verifySignature(interest, keyRaw.buf(), keyRaw.size()));
+ BOOST_CHECK(verifySignature(interest, keyRaw.data(), keyRaw.size()));
BOOST_CHECK(verifySignature(interest, cert));
BOOST_CHECK(!verifySignature(badSigData, key));
- BOOST_CHECK(!verifySignature(badSigData, keyRaw.buf(), keyRaw.size()));
+ BOOST_CHECK(!verifySignature(badSigData, keyRaw.data(), keyRaw.size()));
BOOST_CHECK(!verifySignature(badSigData, cert));
BOOST_CHECK(!verifySignature(badSigInterest, key));
- BOOST_CHECK(!verifySignature(badSigInterest, keyRaw.buf(), keyRaw.size()));
+ BOOST_CHECK(!verifySignature(badSigInterest, keyRaw.data(), keyRaw.size()));
BOOST_CHECK(!verifySignature(badSigInterest, cert));
Data unsignedData("/some/data");
diff --git a/tests/unit-tests/util/segment-fetcher.t.cpp b/tests/unit-tests/util/segment-fetcher.t.cpp
index d80f1ae..dfc2cd8 100644
--- a/tests/unit-tests/util/segment-fetcher.t.cpp
+++ b/tests/unit-tests/util/segment-fetcher.t.cpp
@@ -20,9 +20,9 @@
*/
#include "util/segment-fetcher.hpp"
+
#include "data.hpp"
-#include "encoding/block.hpp"
-#include "lp/nack-header.hpp"
+#include "lp/nack.hpp"
#include "util/dummy-client-face.hpp"
#include "boost-test.hpp"
@@ -44,26 +44,21 @@
public:
Fixture()
: face(io, m_keyChain)
- , nErrors(0)
- , nData(0)
- , dataSize(0)
{
}
- shared_ptr<Data>
+ static shared_ptr<Data>
makeDataSegment(const Name& baseName, uint64_t segment, bool isFinal)
{
const uint8_t buffer[] = "Hello, world!";
auto data = make_shared<Data>(Name(baseName).appendSegment(segment));
data->setContent(buffer, sizeof(buffer));
-
if (isFinal) {
data->setFinalBlockId(data->getName()[-1]);
}
- data = signData(data);
- return data;
+ return signData(data);
}
void
@@ -78,7 +73,7 @@
{
++nData;
dataSize = data->size();
- dataString = std::string(reinterpret_cast<const char*>(data->get()));
+ dataString = std::string(data->get<char>());
}
void
@@ -93,10 +88,10 @@
public:
DummyClientFace face;
- uint32_t nErrors;
- uint32_t lastError;
- uint32_t nData;
- size_t dataSize;
+ uint32_t nErrors = 0;
+ uint32_t lastError = 0;
+ uint32_t nData = 0;
+ size_t dataSize = 0;
std::string dataString;
};
@@ -148,7 +143,7 @@
BOOST_CHECK_EQUAL(dataSize, 14);
const uint8_t buffer[] = "Hello, world!";
- std::string bufferString = std::string(reinterpret_cast<const char*>(buffer));
+ std::string bufferString(reinterpret_cast<const char*>(buffer));
BOOST_CHECK_EQUAL(dataString, bufferString);
@@ -172,9 +167,7 @@
advanceClocks(time::milliseconds(10));
const uint8_t buffer[] = "Hello, world!";
-
- shared_ptr<Data> data = makeData("/hello/world/version0/no-segment");
-
+ auto data = makeData("/hello/world/version0/no-segment");
data->setContent(buffer, sizeof(buffer));
face.receive(*data);
diff --git a/tests/unit-tests/util/sha256.t.cpp b/tests/unit-tests/util/sha256.t.cpp
index 2fec00f..5775785 100644
--- a/tests/unit-tests/util/sha256.t.cpp
+++ b/tests/unit-tests/util/sha256.t.cpp
@@ -48,8 +48,8 @@
statefulSha256.update(input + 3, 1);
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(digest->size(), Sha256::DIGEST_SIZE);
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(ConstructFromStream)
@@ -63,8 +63,8 @@
BOOST_CHECK_EQUAL(sha.toString(), "315F5BDB76D078C43B8AC0064E4A0164612B1FCE77C869345BFC94C75894EDD3");
ConstBufferPtr digest = sha.computeDigest();
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(Compare)
@@ -98,8 +98,8 @@
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(InsertionOperatorString)
@@ -112,8 +112,8 @@
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(InsertionOperatorBlock)
@@ -138,8 +138,8 @@
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(InsertionOperatorUint64t)
@@ -154,8 +154,8 @@
ConstBufferPtr digest = statefulSha256.computeDigest();
BOOST_CHECK_EQUAL(statefulSha256.empty(), false);
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(Reset)
@@ -186,8 +186,8 @@
auto expected = fromHex("9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a");
ConstBufferPtr digest = Sha256::computeDigest(input, sizeof(input));
- BOOST_CHECK_EQUAL_COLLECTIONS(expected->buf(), expected->buf() + expected->size(),
- digest->buf(), digest->buf() + digest->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(expected->data(), expected->data() + expected->size(),
+ digest->data(), digest->data() + digest->size());
}
BOOST_AUTO_TEST_CASE(Print)
diff --git a/tools/ndnsec/cert-gen.cpp b/tools/ndnsec/cert-gen.cpp
index f63a2ea..dbab9cb 100644
--- a/tools/ndnsec/cert-gen.cpp
+++ b/tools/ndnsec/cert-gen.cpp
@@ -136,7 +136,7 @@
try {
Buffer keyContent = certRequest.getPublicKey();
t::PublicKey pubKey;
- pubKey.loadPkcs8(keyContent.buf(), keyContent.size());
+ pubKey.loadPkcs8(keyContent.data(), keyContent.size());
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
diff --git a/tools/ndnsec/sign-req.cpp b/tools/ndnsec/sign-req.cpp
index da330cf..a03a595 100644
--- a/tools/ndnsec/sign-req.cpp
+++ b/tools/ndnsec/sign-req.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).
@@ -99,7 +99,7 @@
certificate.setFreshnessPeriod(time::hours(1));
// set content
- certificate.setContent(key.getPublicKey().buf(), key.getPublicKey().size());
+ certificate.setContent(key.getPublicKey().data(), key.getPublicKey().size());
// set signature-info
SignatureInfo signatureInfo;