ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
identity.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2023 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
23#include "ndn-cxx/security/pib/impl/identity-impl.hpp"
24
25namespace ndn::security::pib {
26
27Identity::Identity() noexcept = default;
28
29Identity::Identity(weak_ptr<IdentityImpl> impl) noexcept
30 : m_impl(std::move(impl))
31{
32}
33
34const Name&
36{
37 return lock()->getName();
38}
39
40Key
41Identity::addKey(span<const uint8_t> key, const Name& keyName) const
42{
43 return lock()->addKey(key, keyName);
44}
45
46void
47Identity::removeKey(const Name& keyName) const
48{
49 lock()->removeKey(keyName);
50}
51
52Key
53Identity::getKey(const Name& keyName) const
54{
55 return lock()->getKey(keyName);
56}
57
58const KeyContainer&
60{
61 return lock()->getKeys();
62}
63
64Key
65Identity::setDefaultKey(const Name& keyName) const
66{
67 return lock()->setDefaultKey(keyName);
68}
69
70Key
71Identity::setDefaultKey(span<const uint8_t> key, const Name& keyName) const
72{
73 return lock()->setDefaultKey(key, keyName);
74}
75
76Key
78{
79 return lock()->getDefaultKey();
80}
81
82Identity::operator bool() const noexcept
83{
84 return !m_impl.expired();
85}
86
87shared_ptr<IdentityImpl>
88Identity::lock() const
89{
90 auto impl = m_impl.lock();
91 if (impl == nullptr) {
92 NDN_THROW(std::domain_error("Invalid PIB identity instance"));
93 }
94 return impl;
95}
96
97bool
98Identity::equals(const Identity& other) const noexcept
99{
100 return !this->m_impl.owner_before(other.m_impl) &&
101 !other.m_impl.owner_before(this->m_impl);
102}
103
104} // namespace ndn::security::pib
Represents an absolute name.
Definition name.hpp:45
Key getDefaultKey() const
Return the default key for this identity.
Definition identity.cpp:77
const KeyContainer & getKeys() const
Return all the keys of this identity.
Definition identity.cpp:59
const Name & getName() const
Return the name of the identity.
Definition identity.cpp:35
Key getKey(const Name &keyName) const
Obtain a handle to the key with the given name.
Definition identity.cpp:53
Identity() noexcept
Default constructor.
Container of keys of an identity.
Frontend handle for a key in the PIB.
Definition key.hpp:45
#define NDN_THROW(e)
Definition exception.hpp:56
@ Name
Definition tlv.hpp:71
STL namespace.