security: MemoryIdentityStorage: Implemented addIdentity, setDefaultIdentity.
diff --git a/ndn-cpp/security/identity/memory-identity-storage.cpp b/ndn-cpp/security/identity/memory-identity-storage.cpp
index a7acf84..1e4f0fc 100644
--- a/ndn-cpp/security/identity/memory-identity-storage.cpp
+++ b/ndn-cpp/security/identity/memory-identity-storage.cpp
@@ -6,6 +6,7 @@
*/
#include <stdexcept>
+#include "../security-exception.hpp"
#include "memory-identity-storage.hpp"
using namespace std;
@@ -20,17 +21,18 @@
bool
MemoryIdentityStorage::doesIdentityExist(const Name& identityName)
{
-#if 1
- throw std::runtime_error("MemoryIdentityStorage::doesIdentityExist not implemented");
-#endif
+ string identityUri = identityName.toUri();
+ return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end();
}
void
MemoryIdentityStorage::addIdentity(const Name& identityName)
{
-#if 1
- throw std::runtime_error("MemoryIdentityStorage::addIdentity not implemented");
-#endif
+ string identityUri = identityName.toUri();
+ if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
+ throw SecurityException("Identity already exists: " + identityUri);
+
+ identityStore_.push_back(identityUri);
}
bool
@@ -129,9 +131,7 @@
Name
MemoryIdentityStorage::getDefaultIdentity()
{
-#if 1
- throw std::runtime_error("MemoryIdentityStorage::getDefaultIdentity not implemented");
-#endif
+ return Name(defaultIdentity_);
}
Name
@@ -153,9 +153,12 @@
void
MemoryIdentityStorage::setDefaultIdentity(const Name& identityName)
{
-#if 1
- throw std::runtime_error("MemoryIdentityStorage::setDefaultIdentity not implemented");
-#endif
+ string identityUri = identityName.toUri();
+ if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
+ defaultIdentity_ = identityUri;
+ else
+ // The identity doesn't exist, so clear the default.
+ defaultIdentity_.clear();
}
void