27 #include <unordered_map> 35 class BackEndMem::Impl
38 std::unordered_map<Name, shared_ptr<PrivateKey>> keys;
51 static std::string scheme =
"tpm-memory";
56 BackEndMem::doHasKey(
const Name& keyName)
const 58 return (m_impl->keys.count(keyName) > 0);
62 BackEndMem::doGetKeyHandle(
const Name& keyName)
const 64 auto it = m_impl->keys.find(keyName);
65 if (it == m_impl->keys.end())
67 return make_unique<KeyHandleMem>(it->second);
71 BackEndMem::doCreateKey(
const Name& identityName,
const KeyParams& params)
74 unique_ptr<KeyHandle> keyHandle = make_unique<KeyHandleMem>(key);
78 m_impl->keys[keyHandle->getKeyName()] = key;
83 BackEndMem::doDeleteKey(
const Name& keyName)
85 m_impl->keys.erase(keyName);
89 BackEndMem::doExportKey(
const Name& keyName,
const char* pw,
size_t pwLen)
92 m_impl->keys[keyName]->savePkcs8(os, pw, pwLen);
97 BackEndMem::doImportKey(
const Name& keyName,
const uint8_t* buf,
size_t size,
const char* pw,
size_t pwLen)
100 auto key = make_shared<PrivateKey>();
101 key->loadPkcs8(buf, size, pw, pwLen);
102 m_impl->keys[keyName] = key;
104 catch (
const PrivateKey::Error&) {
#define NDN_THROW_NESTED(e)
BackEndMem(const std::string &location="")
Create memory-based TPM backend.
Represents an absolute name.
static void setKeyName(KeyHandle &keyHandle, const Name &identity, const KeyParams ¶ms)
Set the key name in keyHandle according to identity and params.
static const std::string & getScheme()
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Base class of key parameters.
implements an output stream that constructs ndn::Buffer
shared_ptr< const Buffer > ConstBufferPtr