NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
signature.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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_SIGNATURE_HPP
23 #define NDN_SIGNATURE_HPP
24 
26 
27 namespace ndn {
28 
37 class Signature
38 {
39 public:
40  class Error : public tlv::Error
41  {
42  public:
43  using tlv::Error::Error;
44  };
45 
46  Signature() = default;
47 
48  explicit
49  Signature(const Block& info, const Block& value = Block());
50 
51  explicit
52  Signature(const SignatureInfo& info, const Block& value = Block());
53 
56  explicit
57  operator bool() const
58  {
59  return m_info.getSignatureType() != -1;
60  }
61 
64  const SignatureInfo&
66  {
67  return m_info;
68  }
69 
72  const Block&
73  getInfo() const
74  {
75  return m_info.wireEncode();
76  }
77 
81  void
82  setInfo(const Block& info);
83 
86  void
87  setInfo(const SignatureInfo& info)
88  {
89  m_info = info;
90  }
91 
94  const Block&
95  getValue() const
96  {
97  return m_value;
98  }
99 
103  void
104  setValue(const Block& value);
105 
106 public: // SignatureInfo fields
111  getType() const;
112 
115  bool
117  {
118  return m_info.hasKeyLocator();
119  }
120 
124  const KeyLocator&
126  {
127  return m_info.getKeyLocator();
128  }
129 
132  void
133  setKeyLocator(const KeyLocator& keyLocator)
134  {
135  m_info.setKeyLocator(keyLocator);
136  }
137 
143  void
145  {
147  }
148 
149 protected:
151  mutable Block m_value;
152 };
153 
154 bool
155 operator==(const Signature& lhs, const Signature& rhs);
156 
157 inline bool
158 operator!=(const Signature& lhs, const Signature& rhs)
159 {
160  return !(lhs == rhs);
161 }
162 
163 } // namespace ndn
164 
165 #endif // NDN_SIGNATURE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Signature()=default
Represents a SignatureInfo TLV element.
void setInfo(const SignatureInfo &info)
Set SignatureInfo.
Definition: signature.hpp:87
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
Definition: signature.hpp:133
void setInfo(const Block &info)
Decode SignatureInfo from wire format.
Definition: signature.cpp:53
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:262
bool hasKeyLocator() const
Check if KeyLocator exists in SignatureInfo.
Definition: signature.hpp:116
void unsetKeyLocator()
Unset KeyLocator.
Definition: signature.hpp:144
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
tlv::SignatureTypeValue getType() const
Get SignatureType.
Definition: signature.cpp:44
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
bool hasKeyLocator() const
Check if KeyLocator exists.
void setValue(const Block &value)
Set SignatureValue.
Definition: signature.cpp:59
const Block & getInfo() const
Get SignatureInfo as wire format.
Definition: signature.hpp:73
int32_t getSignatureType() const
Get SignatureType.
const Block & getValue() const
Get SignatureValue.
Definition: signature.hpp:95
void unsetKeyLocator()
Unset KeyLocator.
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:126
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:313
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:125
SignatureInfo m_info
Definition: signature.hpp:150
const SignatureInfo & getSignatureInfo() const
Get SignatureInfo.
Definition: signature.hpp:65
represents an error in TLV encoding or decoding
Definition: tlv.hpp:52
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37