security: Reorganizing source code to prepare for support of two version of NDN certificates
This commit also removes unused ndn_digestSha256 function and deprecates
crypto::sha256 in favor of crypto::computeSha256Digest in util/crypto.hpp.
Change-Id: I24ee50ff073a96b868633bdf2cfade412d3605f3
Refs: #3098
diff --git a/src/encoding/cryptopp/asn_ext.hpp b/src/encoding/cryptopp/asn_ext.hpp
index 8b6cafc..359aa8b 100644
--- a/src/encoding/cryptopp/asn_ext.hpp
+++ b/src/encoding/cryptopp/asn_ext.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-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -26,7 +26,7 @@
#define NDN_ASN_EXT_HPP
#include "../../common.hpp"
-#include "../../security/cryptopp.hpp"
+#include "../../security/v1/cryptopp.hpp"
#include "../../util/time.hpp"
diff --git a/src/encoding/oid.cpp b/src/encoding/oid.cpp
index 1e623a5..da5ee5c 100644
--- a/src/encoding/oid.cpp
+++ b/src/encoding/oid.cpp
@@ -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-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -17,47 +17,35 @@
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
*/
-#include "common.hpp"
-
#include "oid.hpp"
-#include "../security/cryptopp.hpp"
+#include "../security/v1/cryptopp.hpp"
#include <sstream>
namespace ndn {
-using std::string;
-using std::vector;
-
static const int OID_MAGIC_NUMBER = 40;
-OID::OID(const char* oid)
+Oid::Oid(const char* oid)
+ : Oid(std::string(oid))
{
- construct(oid);
}
-OID::OID(const string& oid)
+Oid::Oid(const std::string& oid)
{
- construct(oid);
-}
-
-void
-OID::construct(const std::string& oid)
-{
- string str = oid + ".";
+ std::string str = oid + ".";
size_t pos = 0;
size_t ppos = 0;
- while (string::npos != pos) {
+ while (std::string::npos != pos) {
ppos = pos;
pos = str.find_first_of('.', pos);
- if (pos == string::npos)
+ if (pos == std::string::npos)
break;
m_oid.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
@@ -66,12 +54,12 @@
}
}
-string
-OID::toString() const
+std::string
+Oid::toString() const
{
std::ostringstream convert;
- for (vector<int>::const_iterator it = m_oid.begin(); it != m_oid.end(); ++it) {
+ for (std::vector<int>::const_iterator it = m_oid.begin(); it != m_oid.end(); ++it) {
if (it != m_oid.begin())
convert << ".";
convert << *it;
@@ -81,10 +69,10 @@
}
bool
-OID::equal(const OID& oid) const
+Oid::equal(const Oid& oid) const
{
- vector<int>::const_iterator i = m_oid.begin();
- vector<int>::const_iterator j = oid.m_oid.begin();
+ std::vector<int>::const_iterator i = m_oid.begin();
+ std::vector<int>::const_iterator j = oid.m_oid.begin();
for (; i != m_oid.end() && j != oid.m_oid.end(); i++, j++) {
if (*i != *j)
@@ -127,7 +115,7 @@
}
void
-OID::encode(CryptoPP::BufferedTransformation& out) const
+Oid::encode(CryptoPP::BufferedTransformation& out) const
{
using namespace CryptoPP;
@@ -144,7 +132,7 @@
}
void
-OID::decode(CryptoPP::BufferedTransformation& in)
+Oid::decode(CryptoPP::BufferedTransformation& in)
{
using namespace CryptoPP;
@@ -176,10 +164,10 @@
}
namespace oid {
-const OID RSA("1.2.840.113549.1.1.1");
-const OID ECDSA("1.2.840.10045.2.1");
+const Oid RSA("1.2.840.113549.1.1.1");
+const Oid ECDSA("1.2.840.10045.2.1");
-const OID ATTRIBUTE_NAME("2.5.4.41");
-}
+const Oid ATTRIBUTE_NAME("2.5.4.41");
+} // namespace oid
} // namespace ndn
diff --git a/src/encoding/oid.hpp b/src/encoding/oid.hpp
index d5f99ca..2f89484 100644
--- a/src/encoding/oid.hpp
+++ b/src/encoding/oid.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-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,25 +28,23 @@
namespace CryptoPP {
class BufferedTransformation;
-}
+} // namespace CryptoPP
namespace ndn {
-class OID
+class Oid
{
public:
- OID()
- {
- }
+ Oid() = default;
explicit
- OID(const char* oid);
+ Oid(const char* oid);
explicit
- OID(const std::string& oid);
+ Oid(const std::string& oid);
explicit
- OID(const std::vector<int>& oid)
+ Oid(const std::vector<int>& oid)
: m_oid(oid)
{
}
@@ -67,13 +65,13 @@
toString() const;
bool
- operator==(const OID& oid) const
+ operator==(const Oid& oid) const
{
return equal(oid);
}
bool
- operator!=(const OID& oid) const
+ operator!=(const Oid& oid) const
{
return !equal(oid);
}
@@ -86,25 +84,27 @@
private:
- void
- construct(const std::string& value);
-
bool
- equal(const OID& oid) const;
+ equal(const Oid& oid) const;
private:
std::vector<int> m_oid;
};
+/**
+ * @deprecated Use Oid type instead
+ */
+typedef Oid OID;
+
namespace oid {
-//crypto algorithm
-extern const OID RSA;
-extern const OID ECDSA;
+// crypto algorithm
+extern const Oid RSA;
+extern const Oid ECDSA;
-//certificate entries
-extern const OID ATTRIBUTE_NAME;
-}
+// certificate entries
+extern const Oid ATTRIBUTE_NAME;
+} // namespace oid
-}
+} // namespace ndn
#endif // NDN_ENCODING_OID_HPP