26 #include <boost/range/adaptor/map.hpp> 33 : m_hasDefaultIdentity(false)
40 static std::string scheme =
"pib-memory";
47 m_tpmLocator = tpmLocator;
59 return (m_identities.count(identity) > 0);
65 m_identities.insert(identity);
67 if (!m_hasDefaultIdentity) {
68 m_defaultIdentity = identity;
69 m_hasDefaultIdentity =
true;
76 m_identities.erase(identity);
77 if (identity == m_defaultIdentity) {
78 m_hasDefaultIdentity =
false;
79 m_defaultIdentity.
clear();
83 for (
const Name& keyName : keyNames) {
91 m_hasDefaultIdentity =
false;
92 m_defaultIdentity.
clear();
94 m_defaultKeys.clear();
96 m_defaultCerts.clear();
110 m_defaultIdentity = identityName;
111 m_hasDefaultIdentity =
true;
117 if (m_hasDefaultIdentity) {
118 return m_defaultIdentity;
121 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default identity"));
127 return (m_keys.count(keyName) > 0);
132 const uint8_t* key,
size_t keyLen)
136 m_keys[keyName] =
Buffer(key, keyLen);
138 if (m_defaultKeys.count(identity) == 0) {
139 m_defaultKeys[identity] = keyName;
148 m_keys.erase(keyName);
149 m_defaultKeys.erase(identity);
152 for (
const auto& certName : certNames) {
161 BOOST_THROW_EXCEPTION(
Pib::Error(
"Key `" + keyName.
toUri() +
"` not found"));
164 auto key = m_keys.find(keyName);
165 BOOST_ASSERT(key != m_keys.end());
173 for (
const auto& keyName : m_keys | boost::adaptors::map_keys) {
185 BOOST_THROW_EXCEPTION(
Pib::Error(
"Key `" + keyName.
toUri() +
"` not found"));
188 m_defaultKeys[identity] = keyName;
194 auto defaultKey = m_defaultKeys.find(identity);
195 if (defaultKey == m_defaultKeys.end()) {
196 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default key for identity `" + identity.
toUri() +
"`"));
199 return defaultKey->second;
205 return (m_certs.count(certName) > 0);
217 m_certs[certName] = certificate;
218 if (m_defaultCerts.count(keyName) == 0) {
219 m_defaultCerts[keyName] = certName;
226 m_certs.erase(certName);
228 if (defaultCert != m_defaultCerts.end() && defaultCert->second == certName) {
229 m_defaultCerts.erase(defaultCert);
237 BOOST_THROW_EXCEPTION(
Pib::Error(
"Certificate `" + certName.
toUri() +
"` does not exist"));
240 auto it = m_certs.find(certName);
247 std::set<Name> certNames;
248 for (
const auto& it : m_certs) {
250 certNames.insert(it.first);
260 BOOST_THROW_EXCEPTION(
Pib::Error(
"Certificate `" + certName.
toUri() +
"` does not exist"));
263 m_defaultCerts[keyName] = certName;
269 auto it = m_defaultCerts.find(keyName);
270 if (it == m_defaultCerts.end()) {
271 BOOST_THROW_EXCEPTION(
Pib::Error(
"No default certificate for key `" + keyName.
toUri() +
"`"));
274 auto certIt = m_certs.find(it->second);
275 BOOST_ASSERT(certIt != m_certs.end());
276 return certIt->second;
bool hasIdentity(const Name &identity) const override
Check the existence of an identity.
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Get URI representation of the name.
The certificate following the certificate format naming convention.
represents a semantic error
Name getDefaultKeyOfIdentity(const Name &identity) const override
const Name & getName() const
Get name.
void clearIdentities() override
Erasing all certificates, keys, and identities.
const Block & getContent() const
Get Content.
Name getIdentity() const
Get identity name.
static const std::string & getScheme()
void removeKey(const Name &keyName) override
Remove a key with keyName and related certificates.
void removeIdentity(const Name &identity) override
Remove an identity and related keys and certificates.
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
void addCertificate(const v2::Certificate &certificate) override
Add a certificate.
std::string getTpmLocator() const override
Get TPM Locator.
Name extractKeyNameFromCertName(const Name &certName)
Extract key name from the certificate name certName.
void setDefaultCertificateOfKey(const Name &keyName, const Name &certName) override
Set a cert with name certName as the default of a key with keyName.
std::set< Name > getIdentities() const override
Get the name of all the identities.
bool hasKey(const Name &keyName) const override
Check the existence of a key with keyName.
const uint8_t * value() const
Get pointer to TLV-VALUE.
PibMemory(const std::string &location="")
Create memory based PIB backend.
void setTpmLocator(const std::string &tpmLocator) override
Set the corresponding TPM information to tpmLocator.
void setDefaultKeyOfIdentity(const Name &identity, const Name &keyName) override
Set an key with keyName as the default key of an identity with name identity.
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
Name getKeyName() const
Get key name.
Name getDefaultIdentity() const override
Get the default identity.
void addKey(const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) override
Add a key.
Represents an absolute name.
v2::Certificate getCertificate(const Name &certName) const override
Get a certificate with name certName.
void setDefaultIdentity(const Name &identityName) override
Set an identity with name identityName as the default identity.
bool hasCertificate(const Name &certName) const override
Check the existence of a certificate with name certName.
void addIdentity(const Name &identity) override
Add an identity.
v2::Certificate getDefaultCertificateOfKey(const Name &keyName) const override
Buffer getKeyBits(const Name &keyName) const override
Get the key bits of a key with name keyName.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
General-purpose automatically managed/resized buffer.
void clear()
Remove all components.
std::set< Name > getKeysOfIdentity(const Name &identity) const override
Get all the key names of an identity with name identity.
std::set< Name > getCertificatesOfKey(const Name &keyName) const override
Get a list of certificate names of a key with id keyName.