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();
112 m_defaultIdentity = identityName;
113 m_hasDefaultIdentity =
true;
119 if (m_hasDefaultIdentity) {
120 return m_defaultIdentity;
129 return m_keys.count(keyName) > 0;
137 m_keys[keyName] =
Buffer(key.begin(), key.end());
139 if (m_defaultKeys.count(identity) == 0) {
140 m_defaultKeys[identity] = keyName;
149 m_keys.erase(keyName);
150 m_defaultKeys.erase(identity);
153 for (
const auto& certName : certNames) {
165 auto key = m_keys.find(keyName);
166 BOOST_ASSERT(key != m_keys.end());
174 for (
const auto& keyName : m_keys | boost::adaptors::map_keys) {
189 m_defaultKeys[identity] = keyName;
195 auto defaultKey = m_defaultKeys.find(identity);
196 if (defaultKey == m_defaultKeys.end()) {
200 return defaultKey->second;
206 return (m_certs.count(certName) > 0);
212 const Name& certName = certificate.getName();
213 const Name& keyName = certificate.getKeyName();
215 addKey(certificate.getIdentity(), keyName, certificate.getContent().value_bytes());
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);
240 auto it = m_certs.find(certName);
247 std::set<Name> certNames;
248 for (
const auto& it : m_certs) {
250 certNames.insert(it.first);
263 m_defaultCerts[keyName] = certName;
269 auto it = m_defaultCerts.find(keyName);
270 if (it == m_defaultCerts.end()) {
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.
represents a semantic error
Name getDefaultKeyOfIdentity(const Name &identity) const override
void addCertificate(const Certificate &certificate) override
Add a certificate.
void clearIdentities() override
Erasing all certificates, keys, and identities.
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.
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.
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.
Certificate getCertificate(const Name &certName) const override
Get a certificate with name certName.
void removeCertificate(const Name &certName) override
Remove a certificate with name certName.
Name getDefaultIdentity() const override
Get the default identity.
Represents an absolute name.
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.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
Buffer getKeyBits(const Name &keyName) const override
Get the key bits of a key with name keyName.
Certificate getDefaultCertificateOfKey(const Name &keyName) const override
void addKey(const Name &identity, const Name &keyName, span< const uint8_t > key) override
Add a key.
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.