util: deprecate crypto::computeSha256Digest()
Use Sha256::computeDigest() instead.
Change-Id: I9db5b4839559c9c7930cdc24c78f35ca76b25b52
diff --git a/src/util/crypto.cpp b/src/util/crypto.cpp
deleted file mode 100644
index 3083e40..0000000
--- a/src/util/crypto.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- 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).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "crypto.hpp"
-#include "../encoding/buffer-stream.hpp"
-#include "../security/transform/buffer-source.hpp"
-#include "../security/transform/digest-filter.hpp"
-#include "../security/transform/stream-sink.hpp"
-
-namespace ndn {
-namespace crypto {
-
-ConstBufferPtr
-computeSha256Digest(const uint8_t* data, size_t dataLength)
-{
- namespace tr = security::transform;
- try {
- OBufferStream os;
- tr::bufferSource(data, dataLength) >> tr::digestFilter(DigestAlgorithm::SHA256)
- >> tr::streamSink(os);
- return os.buf();
- }
- catch (const tr::Error&) {
- return nullptr;
- }
-}
-
-} // namespace crypto
-} // namespace ndn
diff --git a/src/util/crypto.hpp b/src/util/crypto.hpp
index 860b17d..281e2f2 100644
--- a/src/util/crypto.hpp
+++ b/src/util/crypto.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).
@@ -22,14 +22,21 @@
#ifndef NDN_UTIL_CRYPTO_HPP
#define NDN_UTIL_CRYPTO_HPP
-#include "../common.hpp"
-#include "../encoding/buffer.hpp"
+/**
+ * @file
+ * @deprecated use <ndn-cxx/util/digest.hpp>
+ */
+
+#include "digest.hpp"
namespace ndn {
namespace crypto {
-/// @brief number of octets in a SHA256 digest
-const size_t SHA256_DIGEST_SIZE = 32;
+/**
+ * @brief number of octets in a SHA256 digest
+ * @deprecated use ndn::util::Sha256::DIGEST_SIZE
+ */
+DEPRECATED(const size_t SHA256_DIGEST_SIZE) = util::Sha256::DIGEST_SIZE;
/**
* @brief Compute the SHA-256 digest of data.
@@ -37,9 +44,15 @@
* @param data Pointer to the input byte array.
* @param dataLength The length of data.
* @return A pointer to a buffer of SHA256_DIGEST_SIZE bytes.
+ *
+ * @deprecated use ndn::util::Sha256::computeDigest()
*/
-ConstBufferPtr
-computeSha256Digest(const uint8_t* data, size_t dataLength);
+DEPRECATED()
+inline ConstBufferPtr
+computeSha256Digest(const uint8_t* data, size_t dataLength)
+{
+ return util::Sha256::computeDigest(data, dataLength);
+}
} // namespace crypto
} // namespace ndn
diff --git a/src/util/digest.cpp b/src/util/digest.cpp
index 55eb459..8053fdb 100644
--- a/src/util/digest.cpp
+++ b/src/util/digest.cpp
@@ -29,6 +29,8 @@
namespace ndn {
namespace util {
+const size_t Sha256::DIGEST_SIZE;
+
Sha256::Sha256()
{
reset();
@@ -130,6 +132,14 @@
return toHex(*buf);
}
+ConstBufferPtr
+Sha256::computeDigest(const uint8_t* buffer, size_t size)
+{
+ Sha256 sha256;
+ sha256.update(buffer, size);
+ return sha256.computeDigest();
+}
+
std::ostream&
operator<<(std::ostream& os, Sha256& digest)
{
diff --git a/src/util/digest.hpp b/src/util/digest.hpp
index 1c3c857..12dbd96 100644
--- a/src/util/digest.hpp
+++ b/src/util/digest.hpp
@@ -22,7 +22,6 @@
#ifndef NDN_UTIL_DIGEST_HPP
#define NDN_UTIL_DIGEST_HPP
-#include "crypto.hpp"
#include "../encoding/block.hpp"
#include "../encoding/buffer-stream.hpp"
#include "../security/transform/step-source.hpp"
@@ -56,6 +55,11 @@
};
/**
+ * @brief Length in bytes of a SHA-256 digest.
+ */
+ static const size_t DIGEST_SIZE = 32;
+
+ /**
* @brief Create an empty SHA-256 digest.
*/
Sha256();
@@ -156,16 +160,13 @@
toString();
/**
- * @brief Compute a one-time SHA-256 digest.
+ * @brief Stateless SHA-256 digest calculation.
* @param buffer the input buffer
* @param size the size of the input buffer
* @return SHA-256 digest of the input buffer
*/
static ConstBufferPtr
- computeDigest(const uint8_t* buffer, size_t size)
- {
- return crypto::computeSha256Digest(buffer, size);
- }
+ computeDigest(const uint8_t* buffer, size_t size);
private:
unique_ptr<security::transform::StepSource> m_input;
diff --git a/src/util/in-memory-storage.cpp b/src/util/in-memory-storage.cpp
index 69f2b5a..bc1beac 100644
--- a/src/util/in-memory-storage.cpp
+++ b/src/util/in-memory-storage.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).
*
@@ -22,8 +22,6 @@
#include "in-memory-storage.hpp"
#include "in-memory-storage-entry.hpp"
-#include "crypto.hpp"
-
#include "../security/signature-sha256-with-rsa.hpp"
namespace ndn {
@@ -423,9 +421,7 @@
{
Cache::index<byFullName>::type::iterator it = m_cache.get<byFullName>().end();
- const Data* ptr = NULL;
-
- return const_iterator(ptr, &m_cache, it);
+ return const_iterator(nullptr, &m_cache, it);
}
void