27 #include <unordered_map> 29 #include <boost/lexical_cast.hpp> 40 std::unordered_map<Name, shared_ptr<PrivateKey>>
keys;
44 : m_impl(make_unique<
Impl>())
53 static std::string scheme =
"tpm-memory";
58 BackEndMem::doHasKey(
const Name& keyName)
const 60 return (m_impl->keys.count(keyName) > 0);
64 BackEndMem::doGetKeyHandle(
const Name& keyName)
const 66 auto it = m_impl->keys.find(keyName);
67 if (it == m_impl->keys.end())
69 return make_unique<KeyHandleMem>(it->second);
73 BackEndMem::doCreateKey(
const Name& identityName,
const KeyParams& params)
81 NDN_THROW(std::invalid_argument(
"Memory-based TPM does not support creating a key of type " +
82 boost::lexical_cast<std::string>(params.
getKeyType())));
86 unique_ptr<KeyHandle> keyHandle = make_unique<KeyHandleMem>(key);
95 keyHandle->setKeyName(keyName);
102 BackEndMem::doDeleteKey(
const Name& keyName)
104 m_impl->keys.erase(keyName);
108 BackEndMem::doExportKey(
const Name& keyName,
const char* pw,
size_t pwLen)
111 m_impl->keys[keyName]->savePkcs8(os, pw, pwLen);
116 BackEndMem::doImportKey(
const Name& keyName, span<const uint8_t> pkcs8,
const char* pw,
size_t pwLen)
118 auto key = make_shared<PrivateKey>();
120 key->loadPkcs8(pkcs8, pw, pwLen);
129 BackEndMem::doImportKey(
const Name& keyName, shared_ptr<transform::PrivateKey> key)
#define NDN_THROW_NESTED(e)
Copyright (c) 2011-2015 Regents of the University of California.
RSA key, supports sign/verify and encrypt/decrypt operations.
Name constructHmacKeyName(const transform::PrivateKey &key, const Name &identity, const KeyParams ¶ms) const
Construct and return the name of a HMAC key, based on identity and params.
BackEndMem(const std::string &location="")
Create memory-based TPM backend.
HMAC key, supports sign/verify operations.
Name constructAsymmetricKeyName(const KeyHandle &key, const Name &identity, const KeyParams ¶ms) const
Construct and return the name of a RSA or EC key, based on identity and params.
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
Represents an absolute name.
KeyType getKeyType() const
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 for key parameters.
implements an output stream that constructs ndn::Buffer
std::unordered_map< Name, shared_ptr< PrivateKey > > keys
shared_ptr< const Buffer > ConstBufferPtr