23 #include "../pib-impl.hpp"
25 #include "../../transform/public-key.hpp"
36 , m_isDefaultCertificateLoaded(false)
37 , m_certificates(keyName, impl)
40 BOOST_ASSERT(impl !=
nullptr);
42 if (m_impl->hasKey(m_keyName)) {
43 BOOST_THROW_EXCEPTION(
Pib::Error(
"Cannot overwrite existing key " + m_keyName.
toUri()));
51 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Invalid key bits"));
55 m_impl->addKey(m_identity, m_keyName, key, keyLen);
61 , m_isDefaultCertificateLoaded(false)
62 , m_certificates(keyName, impl)
65 BOOST_ASSERT(impl !=
nullptr);
67 m_key = m_impl->getKeyBits(m_keyName);
79 if (m_certificates.
find(certificate.
getName()) != m_certificates.
end()) {
80 BOOST_THROW_EXCEPTION(
Pib::Error(
"Cannot overwrite existing certificate " + certificate.
getName().
toUri()));
83 m_certificates.
add(certificate);
91 if (m_isDefaultCertificateLoaded && m_defaultCertificate.
getName() == certName)
92 m_isDefaultCertificateLoaded =
false;
94 m_certificates.
remove(certName);
102 return m_certificates.
get(certName);
110 return m_certificates;
118 m_defaultCertificate = m_certificates.
get(certName);
119 m_impl->setDefaultCertificateOfKey(m_keyName, certName);
120 m_isDefaultCertificateLoaded =
true;
121 return m_defaultCertificate;
136 if (!m_isDefaultCertificateLoaded) {
137 m_defaultCertificate = m_impl->getDefaultCertificateOfKey(m_keyName);
138 m_isDefaultCertificateLoaded =
true;
141 BOOST_ASSERT(m_impl->getDefaultCertificateOfKey(m_keyName).wireEncode() == m_defaultCertificate.
wireEncode());
143 return m_defaultCertificate;
Copyright (c) 2013-2016 Regents of the University of California.
KeyImpl(const Name &keyName, const uint8_t *key, size_t keyLen, shared_ptr< PibImpl > impl)
Create a KeyImpl with keyName.
The certificate following the certificate format naming convention.
represents a semantic error
void remove(const Name &certName)
Remove a certificate with certName from the container.
const v2::Certificate & setDefaultCertificate(const Name &certName)
Set an existing one with certName as the default certificate.
const Name & getName() const
Get name of the Data packet.
std::string toUri() const
Encode this name as a URI.
const CertificateContainer & getCertificates() const
Get all the certificates for this key.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
Container of certificates of a key.
const_iterator find(const Name &certName) const
bool isConsistent() const
Check if the container is consistent with the backend storage.
const_iterator end() const
Name abstraction to represent an absolute name.
void removeCertificate(const Name &certName)
Remove a certificate with certName.
void add(const v2::Certificate &certificate)
Add certificate into the container.
v2::Certificate getCertificate(const Name &certName) const
Get a certificate with certName.
v2::Certificate get(const Name &certName) const
Get a certificate with certName from the container.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
void addCertificate(const v2::Certificate &certificate)
Add certificate.
const v2::Certificate & getDefaultCertificate() const
Get the default certificate for this Key.