NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2017 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 
22 #include "identity.hpp"
23 #include "detail/identity-impl.hpp"
24 
25 namespace ndn {
26 namespace security {
27 namespace pib {
28 
29 Identity::Identity() = default;
30 
31 Identity::Identity(weak_ptr<detail::IdentityImpl> impl)
32  : m_impl(impl)
33 {
34 }
35 
36 const Name&
38 {
39  return lock()->getName();
40 }
41 
42 Key
43 Identity::addKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
44 {
45  return lock()->addKey(key, keyLen, keyName);
46 }
47 
48 void
49 Identity::removeKey(const Name& keyName) const
50 {
51  return 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 const Key&
67 Identity::setDefaultKey(const Name& keyName) const
68 {
69  return lock()->setDefaultKey(keyName);
70 }
71 
72 const Key&
73 Identity::setDefaultKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
74 {
75  return lock()->setDefaultKey(key, keyLen, keyName);
76 }
77 
78 const Key&
80 {
81  return lock()->getDefaultKey();
82 }
83 
84 Identity::operator bool() const
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 
94  if (impl == nullptr)
95  BOOST_THROW_EXCEPTION(std::domain_error("Invalid Identity instance"));
96 
97  return impl;
98 }
99 
100 bool
101 operator!=(const Identity& lhs, const Identity& rhs)
102 {
103  return lhs.m_impl.owner_before(rhs.m_impl) || rhs.m_impl.owner_before(lhs.m_impl);
104 }
105 
106 std::ostream&
107 operator<<(std::ostream& os, const Identity& id)
108 {
109  if (id) {
110  os << id.getName();
111  }
112  else {
113  os << "(empty)";
114  }
115  return os;
116 }
117 
118 } // namespace pib
119 } // namespace security
120 } // namespace ndn
std::ostream & operator<<(std::ostream &os, const Identity &id)
Definition: identity.cpp:107
Key getKey(const Name &keyName) const
Get a key with id keyName.
Definition: identity.cpp:55
Copyright (c) 2011-2015 Regents of the University of California.
const Key & setDefaultKey(const Name &keyName) const
Set an existing key with keyName as the default key.
Definition: identity.cpp:67
void removeKey(const Name &keyName) const
Remove a key with keyName.
Definition: identity.cpp:49
Identity()
Default Constructor.
Container of keys of an identity.
A frontend handle of a key instance.
Definition: key.hpp:49
Represents an absolute name.
Definition: name.hpp:42
const Key & getDefaultKey() const
Get the default key for this Identity.
Definition: identity.cpp:79
const Name & getName() const
Get the name of the identity.
Definition: identity.cpp:37
bool operator!=(const Identity &lhs, const Identity &rhs)
Definition: identity.cpp:101
A frontend handle of an Identity.
Definition: identity.hpp:42
const KeyContainer & getKeys() const
Get all keys for this identity.
Definition: identity.cpp:61
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE size_t keyLen
Definition: identity.hpp:115