security: Implement BasicIdentityStorage::getCertificate
diff --git a/include/ndn-cpp/security/identity/basic-identity-storage.hpp b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
index d841548..488d95a 100644
--- a/include/ndn-cpp/security/identity/basic-identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
@@ -138,7 +138,7 @@
* @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
* @return The requested certificate. If not found, return a shared_ptr with a null pointer.
*/
- virtual ptr_lib::shared_ptr<Certificate>
+ virtual ptr_lib::shared_ptr<Data>
getCertificate(const Name &certificateName, bool allowAny = false);
diff --git a/include/ndn-cpp/security/identity/identity-storage.hpp b/include/ndn-cpp/security/identity/identity-storage.hpp
index d9b5e1a..fdf3d0c 100644
--- a/include/ndn-cpp/security/identity/identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/identity-storage.hpp
@@ -129,7 +129,7 @@
* @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
* @return The requested certificate. If not found, return a shared_ptr with a null pointer.
*/
- virtual ptr_lib::shared_ptr<Certificate>
+ virtual ptr_lib::shared_ptr<Data>
getCertificate(const Name &certificateName, bool allowAny = false) = 0;
diff --git a/include/ndn-cpp/security/identity/memory-identity-storage.hpp b/include/ndn-cpp/security/identity/memory-identity-storage.hpp
index 9b7dd5f..0fb09c0 100644
--- a/include/ndn-cpp/security/identity/memory-identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/memory-identity-storage.hpp
@@ -124,7 +124,7 @@
* @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
* @return The requested certificate. If not found, return a shared_ptr with a null pointer.
*/
- virtual ptr_lib::shared_ptr<Certificate>
+ virtual ptr_lib::shared_ptr<Data>
getCertificate(const Name &certificateName, bool allowAny = false);
diff --git a/ndn-cpp/security/identity/basic-identity-storage.cpp b/ndn-cpp/security/identity/basic-identity-storage.cpp
index 5055dc8..90cd9e6 100644
--- a/ndn-cpp/security/identity/basic-identity-storage.cpp
+++ b/ndn-cpp/security/identity/basic-identity-storage.cpp
@@ -15,10 +15,13 @@
#include <stdlib.h>
#include <sstream>
#include <fstream>
+#include <math.h>
#include <ndn-cpp/security/identity/basic-identity-storage.hpp>
#include "../../util/logging.hpp"
-#include <ndn-cpp/security//security-exception.hpp>
+#include <ndn-cpp/security/security-exception.hpp>
#include "ndn-cpp/data.hpp"
+#include <ndn-cpp/security/certificate/certificate.hpp>
+#include "../../c/util/time.h"
#if 0
#include "ndn.cxx/fields/signature-sha256-with-rsa.h"
@@ -496,10 +499,9 @@
#endif
}
-shared_ptr<Certificate>
+shared_ptr<Data>
BasicIdentityStorage::getCertificate(const Name &certificateName, bool allowAny)
{
-#if 0
if (doesCertificateExist(certificateName)) {
sqlite3_stmt *statement;
if (!allowAny) {
@@ -509,8 +511,8 @@
-1, &statement, 0);
sqlite3_bind_text(statement, 1, certificateName.toUri(), SQLITE_TRANSIENT);
- sqlite3_bind_int64(statement, 2, (sqlite3_int64)time::NowUnixTimestamp().total_seconds());
- sqlite3_bind_int64(statement, 3, (sqlite3_int64)time::NowUnixTimestamp().total_seconds());
+ sqlite3_bind_int64(statement, 2, (sqlite3_int64)floor(ndn_getNowMilliseconds() / 1000.0));
+ sqlite3_bind_int64(statement, 3, (sqlite3_int64)floor(ndn_getNowMilliseconds() / 1000.0));
}
else {
sqlite3_prepare_v2(database_,
@@ -521,21 +523,18 @@
int res = sqlite3_step(statement);
- shared_ptr<Certificate> certificate(new Certificate());
+ shared_ptr<Data> data;
if (res == SQLITE_ROW)
- certificate->wireDecode(sqlite3_column_blob(statement, 0), sqlite3_column_bytes(statement, 0));
+ data->wireDecode((const uint8_t*)sqlite3_column_blob(statement, 0), sqlite3_column_bytes(statement, 0));
sqlite3_finalize(statement);
- return certificate;
+ return data;
}
else {
_LOG_DEBUG("Certificate does not exist!");
- return shared_ptr<Certificate>();
+ return shared_ptr<Data>();
}
-#else
- throw logic_error("unimplemented");
-#endif
}
Name
diff --git a/ndn-cpp/security/identity/memory-identity-storage.cpp b/ndn-cpp/security/identity/memory-identity-storage.cpp
index 164862e..eb77865 100644
--- a/ndn-cpp/security/identity/memory-identity-storage.cpp
+++ b/ndn-cpp/security/identity/memory-identity-storage.cpp
@@ -123,7 +123,7 @@
#endif
}
-ptr_lib::shared_ptr<Certificate>
+ptr_lib::shared_ptr<Data>
MemoryIdentityStorage::getCertificate(const Name &certificateName, bool allowAny)
{
#if 1