27 #include <unordered_map> 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& e) {
105 BOOST_THROW_EXCEPTION(Error(
"Cannot import private key: "s + e.what()));
Copyright (c) 2011-2015 Regents of the University of California.
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()
Base class of key parameters.
std::unordered_map< Name, shared_ptr< PrivateKey > > keys
shared_ptr< const Buffer > ConstBufferPtr