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-2022 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 
25 namespace ndn {
26 namespace security {
27 namespace pib {
28 
29 Identity::Identity() noexcept = default;
30 
31 Identity::Identity(weak_ptr<detail::IdentityImpl> impl) noexcept
32  : m_impl(std::move(impl))
33 {
34 }
35 
36 const Name&
38 {
39  return lock()->getName();
40 }
41 
42 Key
43 Identity::addKey(span<const uint8_t> key, const Name& keyName) const
44 {
45  return lock()->addKey(key, keyName);
46 }
47 
48 void
49 Identity::removeKey(const Name& keyName) const
50 {
51  lock()->removeKey(keyName);
52 }
53 
54 Key
55 Identity::getKey(const Name& keyName) const
56 {
57  return lock()->getKey(keyName);
58 }
59 
60 const KeyContainer&
62 {
63  return lock()->getKeys();
64 }
65 
66 Key
67 Identity::setDefaultKey(const Name& keyName) const
68 {
69  return lock()->setDefaultKey(keyName);
70 }
71 
72 Key
73 Identity::setDefaultKey(span<const uint8_t> key, const Name& keyName) const
74 {
75  return lock()->setDefaultKey(key, keyName);
76 }
77 
78 Key
80 {
81  return lock()->getDefaultKey();
82 }
83 
84 Identity::operator bool() const noexcept
85 {
86  return !m_impl.expired();
87 }
88 
89 shared_ptr<detail::IdentityImpl>
90 Identity::lock() const
91 {
92  auto impl = m_impl.lock();
93  if (impl == nullptr) {
94  NDN_THROW(std::domain_error("Invalid PIB identity instance"));
95  }
96  return impl;
97 }
98 
99 bool
100 Identity::equals(const Identity& other) const noexcept
101 {
102  return !this->m_impl.owner_before(other.m_impl) &&
103  !other.m_impl.owner_before(this->m_impl);
104 }
105 
106 } // namespace pib
107 } // namespace security
108 } // namespace ndn
Represents an absolute name.
Definition: name.hpp:44
Key getDefaultKey() const
Return the default key for this identity.
Definition: identity.cpp:79
const KeyContainer & getKeys() const
Return all the keys of this identity.
Definition: identity.cpp:61
const Name & getName() const
Return the name of the identity.
Definition: identity.cpp:37
Key getKey(const Name &keyName) const
Obtain a handle to the key with the given name.
Definition: identity.cpp:55
Identity() noexcept
Default constructor.
Container of keys of an identity.
Frontend handle for a key in the PIB.
Definition: key.hpp:51
#define NDN_THROW(e)
Definition: exception.hpp:61
@ Name
Definition: tlv.hpp:71
Definition: data.cpp:25