identity-storage: copying ndn.cxx extensions to get information about the stored data
Change-Id: Id272a4985a6caa3ddfdc177ebf1b318b351279f8
diff --git a/include/ndn-cpp/security/identity/basic-identity-storage.hpp b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
index 476df56..4954f01 100644
--- a/include/ndn-cpp/security/identity/basic-identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/basic-identity-storage.hpp
@@ -178,6 +178,22 @@
virtual void
setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
+
+ virtual std::vector<Name>
+ getAllIdentities(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllKeyNames(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllKeyNamesOfIdentity(const Name& identity, bool isDefault);
+
+ virtual std::vector<Name>
+ getAllCertificateNames(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllCertificateNamesOfKey(const Name& keyName, bool isDefault);
+
private:
virtual void
diff --git a/include/ndn-cpp/security/identity/identity-storage.hpp b/include/ndn-cpp/security/identity/identity-storage.hpp
index d54bc10..3c298c8 100644
--- a/include/ndn-cpp/security/identity/identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/identity-storage.hpp
@@ -184,6 +184,23 @@
*/
virtual void
setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0;
+
+
+ virtual std::vector<Name>
+ getAllIdentities(bool isDefault) = 0;
+
+ virtual std::vector<Name>
+ getAllKeyNames(bool isDefault) = 0;
+
+ virtual std::vector<Name>
+ getAllKeyNamesOfIdentity(const Name& identity, bool isDefault) = 0;
+
+ virtual std::vector<Name>
+ getAllCertificateNames(bool isDefault) = 0;
+
+ virtual std::vector<Name>
+ getAllCertificateNamesOfKey(const Name& keyName, bool isDefault) = 0;
+
};
}
diff --git a/include/ndn-cpp/security/identity/memory-identity-storage.hpp b/include/ndn-cpp/security/identity/memory-identity-storage.hpp
index 60837ff..5027a73 100644
--- a/include/ndn-cpp/security/identity/memory-identity-storage.hpp
+++ b/include/ndn-cpp/security/identity/memory-identity-storage.hpp
@@ -163,6 +163,21 @@
*/
virtual void
setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
+
+ virtual std::vector<Name>
+ getAllIdentities(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllKeyNames(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllKeyNamesOfIdentity(const Name& identity, bool isDefault);
+
+ virtual std::vector<Name>
+ getAllCertificateNames(bool isDefault);
+
+ virtual std::vector<Name>
+ getAllCertificateNamesOfKey(const Name& keyName, bool isDefault);
private:
class KeyRecord {
diff --git a/src/security/identity/basic-identity-storage.cpp b/src/security/identity/basic-identity-storage.cpp
index 46a98bf..5985499 100644
--- a/src/security/identity/basic-identity-storage.cpp
+++ b/src/security/identity/basic-identity-storage.cpp
@@ -629,7 +629,105 @@
sqlite3_finalize(statement);
}
+
+vector<Name>
+BasicIdentityStorage::getAllIdentities(bool isDefault)
+{
+ sqlite3_stmt *stmt;
+ if(isDefault)
+ sqlite3_prepare_v2 (database_, "SELECT identity_name FROM Identity WHERE default_identity=1", -1, &stmt, 0);
+ else
+ sqlite3_prepare_v2 (database_, "SELECT identity_name FROM Identity WHERE default_identity=0", -1, &stmt, 0);
+
+ vector<Name> nameList;
+ while(sqlite3_step (stmt) == SQLITE_ROW)
+ nameList.push_back(Name(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0))));
+ sqlite3_finalize (stmt);
+ return nameList;
}
+vector<Name>
+BasicIdentityStorage::getAllKeyNames(bool isDefault)
+{
+ sqlite3_stmt *stmt;
+ if(isDefault)
+ sqlite3_prepare_v2 (database_, "SELECT identity_name, key_identifier FROM Key WHERE default_key=1", -1, &stmt, 0);
+ else
+ sqlite3_prepare_v2 (database_, "SELECT identity_name, key_identifier FROM Key WHERE default_key=0", -1, &stmt, 0);
+
+ vector<Name> nameList;
+ while(sqlite3_step (stmt) == SQLITE_ROW)
+ {
+ Name keyName(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+ keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
+ nameList.push_back(keyName);
+ }
+ sqlite3_finalize (stmt);
+ return nameList;
+}
+
+vector<Name>
+BasicIdentityStorage::getAllKeyNamesOfIdentity(const Name& identity, bool isDefault)
+{
+ sqlite3_stmt *stmt;
+ if(isDefault)
+ sqlite3_prepare_v2 (database_, "SELECT key_identifier FROM Key WHERE default_key=1 and identity_name=?", -1, &stmt, 0);
+ else
+ sqlite3_prepare_v2 (database_, "SELECT key_identifier FROM Key WHERE default_key=0 and identity_name=?", -1, &stmt, 0);
+
+ sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size (), SQLITE_TRANSIENT);
+
+ vector<Name> nameList;
+ while(sqlite3_step (stmt) == SQLITE_ROW)
+ {
+ Name keyName(identity);
+ keyName.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+ nameList.push_back(keyName);
+ }
+ sqlite3_finalize (stmt);
+ return nameList;
+}
+
+vector<Name>
+BasicIdentityStorage::getAllCertificateNames(bool isDefault)
+{
+ sqlite3_stmt *stmt;
+ if(isDefault)
+ sqlite3_prepare_v2 (database_, "SELECT cert_name FROM Certificate WHERE default_cert=1", -1, &stmt, 0);
+ else
+ sqlite3_prepare_v2 (database_, "SELECT cert_name FROM Certificate WHERE default_cert=0", -1, &stmt, 0);
+
+ vector<Name> nameList;
+ while(sqlite3_step (stmt) == SQLITE_ROW)
+ nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+
+ sqlite3_finalize (stmt);
+ return nameList;
+}
+
+vector<Name>
+BasicIdentityStorage::getAllCertificateNamesOfKey(const Name& keyName, bool isDefault)
+{
+ sqlite3_stmt *stmt;
+ if(isDefault)
+ sqlite3_prepare_v2 (database_, "SELECT cert_name FROM Certificate WHERE default_cert=1 and identity_name=? and key_identifier=?", -1, &stmt, 0);
+ else
+ sqlite3_prepare_v2 (database_, "SELECT cert_name FROM Certificate WHERE default_cert=0 and identity_name=? and key_identifier=?", -1, &stmt, 0);
+
+ Name identity = keyName.getSubName(0, keyName.size()-1);
+ sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size (), SQLITE_TRANSIENT);
+ std::string baseKeyName = keyName.get(-1).toEscapedString();
+ sqlite3_bind_text(stmt, 2, baseKeyName.c_str(), baseKeyName.size(), SQLITE_TRANSIENT);
+
+ vector<Name> nameList;
+ while(sqlite3_step (stmt) == SQLITE_ROW)
+ nameList.push_back(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+
+ sqlite3_finalize (stmt);
+ return nameList;
+}
+
+} // namespace ndn
+
#endif // NDN_CPP_HAVE_SQLITE3
diff --git a/src/security/identity/memory-identity-storage.cpp b/src/security/identity/memory-identity-storage.cpp
index 26341fa..ee986f0 100644
--- a/src/security/identity/memory-identity-storage.cpp
+++ b/src/security/identity/memory-identity-storage.cpp
@@ -185,4 +185,36 @@
#endif
}
+
+std::vector<Name>
+MemoryIdentityStorage::getAllIdentities(bool isDefault)
+{
+ throw runtime_error("MemoryIdentityStorage::getAllIdentities not implemented");
+}
+
+std::vector<Name>
+MemoryIdentityStorage::getAllKeyNames(bool isDefault)
+{
+ throw runtime_error("MemoryIdentityStorage::getAllKeyNames not implemented");
+}
+
+std::vector<Name>
+MemoryIdentityStorage::getAllKeyNamesOfIdentity(const Name& identity, bool isDefault)
+{
+ throw runtime_error("MemoryIdentityStorage::getAllKeyNamesOfIdentity not implemented");
+}
+
+std::vector<Name>
+MemoryIdentityStorage::getAllCertificateNames(bool isDefault)
+{
+ throw runtime_error("MemoryIdentityStorage::getAllCertificateNames not implemented");
+}
+
+std::vector<Name>
+MemoryIdentityStorage::getAllCertificateNamesOfKey(const Name& keyName, bool isDefault)
+{
+ throw runtime_error("MemoryIdentityStorage::getAllCertificateNamesOfKey not implemented");
+}
+
+
}