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