NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
key-locator.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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 #ifndef NDN_KEY_LOCATOR_HPP
23 #define NDN_KEY_LOCATOR_HPP
24 
25 #include "ndn-cxx/name.hpp"
26 
27 namespace ndn {
28 
30 {
31 public:
32  class Error : public tlv::Error
33  {
34  public:
35  using tlv::Error::Error;
36  };
37 
38  enum
39 #ifndef DOXYGEN
40  [[deprecated]] // apparently doxygen can't handle this attribute on enums
41 #endif
42  Type {
49  };
50 
51 public: // constructors
56 
61  KeyLocator(const Name& name);
62 
65  explicit
66  KeyLocator(const Block& wire);
67 
68 public: // encode and decode
71  template<encoding::Tag TAG>
72  size_t
73  wireEncode(EncodingImpl<TAG>& encoder) const;
74 
75  const Block&
76  wireEncode() const;
77 
82  void
83  wireDecode(const Block& wire);
84 
85 public: // attributes
87  empty() const
88  {
89  return holds_alternative<monostate>(m_locator);
90  }
91 
92  uint32_t
93  getType() const;
94 
100  KeyLocator&
101  clear();
102 
106  const Name&
107  getName() const;
108 
113  KeyLocator&
114  setName(const Name& name);
115 
119  const Block&
120  getKeyDigest() const;
121 
127  KeyLocator&
128  setKeyDigest(const Block& keyDigest);
129 
135  KeyLocator&
136  setKeyDigest(const ConstBufferPtr& keyDigest);
137 
138 private: // non-member operators
139  // NOTE: the following "hidden friend" operators are available via
140  // argument-dependent lookup only and must be defined inline.
141 
142  friend bool
143  operator==(const KeyLocator& lhs, const KeyLocator& rhs)
144  {
145  return lhs.m_locator == rhs.m_locator;
146  }
147 
148  friend bool
149  operator!=(const KeyLocator& lhs, const KeyLocator& rhs)
150  {
151  return lhs.m_locator != rhs.m_locator;
152  }
153 
154 private:
155  // - monostate represents an empty KeyLocator, without any nested TLVs
156  // - Name is used when the nested TLV contains a name
157  // - Block is used when the nested TLV is a KeyDigest
158  // - in all other (unsupported) cases the nested TLV type is stored as uint32_t
159  variant<monostate, Name, Block, uint32_t> m_locator;
160 
161  mutable Block m_wire;
162 
163  friend std::ostream& operator<<(std::ostream&, const KeyLocator&);
164 };
165 
167 
168 std::ostream&
169 operator<<(std::ostream& os, const KeyLocator& keyLocator);
170 
171 } // namespace ndn
172 
173 #endif // NDN_KEY_LOCATOR_HPP
ndn::KeyLocator::KeyLocator_None
@ KeyLocator_None
KeyLocator is empty.
Definition: key-locator.hpp:44
ndn::KeyLocator::clear
KeyLocator & clear()
Reset KeyLocator to its default-constructed state.
Definition: key-locator.cpp:135
ndn::KeyLocator::operator<<
friend std::ostream & operator<<(std::ostream &, const KeyLocator &)
Definition: key-locator.cpp:193
ndn::KeyLocator::wireEncode
const Block & wireEncode() const
Definition: key-locator.cpp:74
ndn::NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Interest)
ndn::tlv::KeyDigest
@ KeyDigest
Definition: tlv.hpp:87
ndn::KeyLocator::getKeyDigest
const Block & getKeyDigest() const
Get nested KeyDigest element.
Definition: key-locator.cpp:162
ndn::KeyLocator::getType
uint32_t getType() const
Definition: key-locator.cpp:118
name.hpp
ndn::KeyLocator::Type
Type
Definition: key-locator.hpp:42
ndn::KeyLocator::empty
NDN_CXX_NODISCARD bool empty() const
Definition: key-locator.hpp:87
ndn::KeyLocator::setKeyDigest
KeyLocator & setKeyDigest(const Block &keyDigest)
Set nested KeyDigest element (whole TLV).
Definition: key-locator.cpp:173
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::KeyLocator::KeyLocator
KeyLocator()
Construct an empty KeyLocator.
ndn::KeyLocator::setName
KeyLocator & setName(const Name &name)
Set nested Name element.
Definition: key-locator.cpp:154
NDN_CXX_NODISCARD
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
ndn::KeyLocator::wireDecode
void wireDecode(const Block &wire)
Decode from wire encoding.
Definition: key-locator.cpp:90
ndn::KeyLocator::operator!=
friend bool operator!=(const KeyLocator &lhs, const KeyLocator &rhs)
Definition: key-locator.hpp:149
ndn::KeyLocator::Error
Definition: key-locator.hpp:33
ndn::KeyLocator::KeyLocator_Name
@ KeyLocator_Name
KeyLocator contains a Name.
Definition: key-locator.hpp:46
ndn::tlv::Name
@ Name
Definition: tlv.hpp:67
ndn::encoding::EncodingImpl
Definition: encoding-buffer-fwd.hpp:36
ndn::Block
Represents a TLV element of NDN packet format.
Definition: block.hpp:43
ndn::operator<<
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:322
ndn::name
Definition: name-component-types.hpp:33
ndn::KeyLocator::getName
const Name & getName() const
Get nested Name element.
Definition: key-locator.cpp:143
ndn::KeyLocator::operator==
friend bool operator==(const KeyLocator &lhs, const KeyLocator &rhs)
Definition: key-locator.hpp:143
ndn::tlv::Error
represents an error in TLV encoding or decoding
Definition: tlv.hpp:53
ndn::tlv::Invalid
@ Invalid
Definition: tlv.hpp:64
ndn::KeyLocator
Definition: key-locator.hpp:30
ndn::tlv::Error::Error
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
ndn::ConstBufferPtr
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:126
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::KeyLocator::KeyLocator_KeyDigest
@ KeyLocator_KeyDigest
KeyLocator contains a KeyDigest.
Definition: key-locator.hpp:48