23 #include "ndn-cxx/security/pib/impl/key-impl.hpp"
31 Key::Key(weak_ptr<detail::KeyImpl> impl) noexcept
32 : m_impl(std::move(impl))
39 return lock()->getName();
45 return lock()->getIdentity();
51 return lock()->getKeyType();
57 return lock()->getPublicKey();
61 Key::addCertificate(
const Certificate& certificate)
const
63 lock()->addCertificate(certificate);
67 Key::removeCertificate(
const Name& certName)
const
69 lock()->removeCertificate(certName);
75 return lock()->getCertificate(certName);
81 return lock()->getCertificates();
85 Key::setDefaultCertificate(
const Name& certName)
const
87 return lock()->setDefaultCertificate(certName);
91 Key::setDefaultCertificate(
const Certificate& certificate)
const
93 return lock()->setDefaultCertificate(certificate);
99 return lock()->getDefaultCertificate();
102 Key::operator bool() const noexcept
104 return !m_impl.expired();
107 shared_ptr<detail::KeyImpl>
110 auto impl = m_impl.lock();
111 if (impl ==
nullptr) {
112 NDN_THROW(std::domain_error(
"Invalid PIB key instance"));
118 Key::equals(
const Key& other)
const noexcept
120 return !this->m_impl.owner_before(other.m_impl) &&
121 !other.m_impl.owner_before(this->m_impl);
126 inline namespace v2 {
131 return Name(identity)
147 NDN_THROW(std::invalid_argument(
"Key name `" + keyName.
toUri() +
"` "
148 "does not respect the naming conventions"));
Represents an absolute name.
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
size_t size() const noexcept
Returns the number of components.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
const Component & get(ssize_t i) const noexcept
Returns an immutable reference to the component at the specified index.
Represents a name component.
Container of certificates of a key.
KeyType getKeyType() const
Return the key type.
const Certificate & getDefaultCertificate() const
Return the default certificate for this key.
const Name & getIdentity() const
Return the name of the owning identity.
Key() noexcept
Default constructor.
span< const uint8_t > getPublicKey() const
Return the raw public key bits.
Certificate getCertificate(const Name &certName) const
Return the certificate with the given name.
const Name & getName() const
Return the name of the key.
const CertificateContainer & getCertificates() const
Return all the certificates of this key.
Represents an NDN certificate.
static const name::Component KEY_COMPONENT
static const size_t MIN_KEY_NAME_LENGTH
bool isValidKeyName(const Name &keyName)
Check if keyName follow the naming conventions for the key name.
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
Name constructKeyName(const Name &identity, const name::Component &keyId)
Construct key name based on the appropriate naming conventions.
KeyType
The type of a cryptographic key.