24 #include "../transform/private-key.hpp" 25 #include "../../encoding/buffer-stream.hpp" 26 #include <unordered_map> 37 std::unordered_map<Name, shared_ptr<PrivateKey>>
keys;
50 static std::string scheme =
"tpm-memory";
55 BackEndMem::doHasKey(
const Name& keyName)
const 57 return (m_impl->keys.count(keyName) > 0);
61 BackEndMem::doGetKeyHandle(
const Name& keyName)
const 63 auto it = m_impl->keys.find(keyName);
64 if (it == m_impl->keys.end())
66 return make_unique<KeyHandleMem>(it->second);
70 BackEndMem::doCreateKey(
const Name& identityName,
const KeyParams& params)
73 unique_ptr<KeyHandle> keyHandle = make_unique<KeyHandleMem>(key);
77 m_impl->keys[keyHandle->getKeyName()] = key;
82 BackEndMem::doDeleteKey(
const Name& keyName)
84 m_impl->keys.erase(keyName);
88 BackEndMem::doExportKey(
const Name& keyName,
const char* pw,
size_t pwLen)
91 m_impl->keys[keyName]->savePkcs8(os, pw, pwLen);
96 BackEndMem::doImportKey(
const Name& keyName,
const uint8_t* buf,
size_t size,
const char* pw,
size_t pwLen)
99 auto key = make_shared<PrivateKey>();
100 key->loadPkcs8(buf, size, pw, pwLen);
101 m_impl->keys[keyName] = key;
103 catch (
const PrivateKey::Error& e) {
104 BOOST_THROW_EXCEPTION(
Error(std::string(
"Cannot import private key: ") + e.what()));
Copyright (c) 2011-2015 Regents of the University of California.
BackEndMem(const std::string &location="")
Create memory-based TPM backend.
Catch-all error for security policy errors that don't fit in other categories.
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
std::unordered_map< Name, shared_ptr< PrivateKey > > keys
shared_ptr< const Buffer > ConstBufferPtr