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-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 #ifndef NDN_SIGNATURE_HPP
23 #define NDN_SIGNATURE_HPP
24 
25 #include "signature-info.hpp"
26 
27 namespace ndn {
28 
37 class Signature
38 {
39 public:
40  class Error : public tlv::Error
41  {
42  public:
43  explicit
44  Error(const std::string& what)
45  : tlv::Error(what)
46  {
47  }
48  };
49 
50  Signature() = default;
51 
52  explicit
53  Signature(const Block& info, const Block& value = Block());
54 
55  explicit
56  Signature(const SignatureInfo& info, const Block& value = Block());
57 
60  explicit
61  operator bool() const
62  {
63  return m_info.getSignatureType() != -1;
64  }
65 
68  const SignatureInfo&
70  {
71  return m_info;
72  }
73 
76  const Block&
77  getInfo() const
78  {
79  return m_info.wireEncode();
80  }
81 
85  void
86  setInfo(const Block& info);
87 
90  void
91  setInfo(const SignatureInfo& info)
92  {
93  m_info = info;
94  }
95 
98  const Block&
99  getValue() const
100  {
101  return m_value;
102  }
103 
107  void
108  setValue(const Block& value);
109 
110 public: // SignatureInfo fields
115  getType() const;
116 
119  bool
121  {
122  return m_info.hasKeyLocator();
123  }
124 
128  const KeyLocator&
130  {
131  return m_info.getKeyLocator();
132  }
133 
136  void
137  setKeyLocator(const KeyLocator& keyLocator)
138  {
139  m_info.setKeyLocator(keyLocator);
140  }
141 
147  void
149  {
151  }
152 
153 protected:
155  mutable Block m_value;
156 };
157 
158 bool
159 operator==(const Signature& lhs, const Signature& rhs);
160 
161 inline bool
162 operator!=(const Signature& lhs, const Signature& rhs)
163 {
164  return !(lhs == rhs);
165 }
166 
167 } // namespace ndn
168 
169 #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:91
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
Definition: signature.hpp:137
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:280
bool hasKeyLocator() const
Check if KeyLocator exists in SignatureInfo.
Definition: signature.hpp:120
void unsetKeyLocator()
Unset KeyLocator.
Definition: signature.hpp:148
Error(const std::string &what)
Definition: signature.hpp:44
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:77
int32_t getSignatureType() const
Get SignatureType.
const Block & getValue() const
Get SignatureValue.
Definition: signature.hpp:99
void unsetKeyLocator()
Unset KeyLocator.
SignatureTypeValue
Definition: tlv.hpp:111
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:328
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:129
SignatureInfo m_info
Definition: signature.hpp:154
const SignatureInfo & getSignatureInfo() const
Get SignatureInfo.
Definition: signature.hpp:69
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:37