NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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; -*- */
22 #ifndef NDN_SIGNATURE_HPP
23 #define NDN_SIGNATURE_HPP
24 
25 #include "common.hpp"
26 #include "signature-info.hpp"
27 
28 namespace ndn {
29 
33 class Signature
34 {
35 public:
36  class Error : public tlv::Error
37  {
38  public:
39  explicit
40  Error(const std::string& what)
41  : tlv::Error(what)
42  {
43  }
44  };
45 
47  enum {
51  };
52 
53  Signature() = default;
54 
55  explicit
56  Signature(const Block& info, const Block& value = Block());
57 
58  explicit
59  Signature(const SignatureInfo& info, const Block& value = Block());
60 
61  operator bool() const
62  {
63  return m_info.getSignatureType() != -1;
64  }
65 
69  const Block&
70  getInfo() const
71  {
72  return m_info.wireEncode(); // will do nothing if wire already exists
73  }
74 
80  void
81  setInfo(const Block& info);
82 
86  void
87  setInfo(const SignatureInfo& info)
88  {
89  m_info = info;
90  }
91 
95  const Block&
96  getValue() const
97  {
98  m_value.encode(); // will do nothing if wire already exists
99  return m_value;
100  }
101 
107  void
108  setValue(const Block& value);
109 
113  uint32_t
114  getType() const
115  {
116  return m_info.getSignatureType();
117  }
118 
122  bool
124  {
125  return m_info.hasKeyLocator();
126  }
127 
133  const KeyLocator&
135  {
136  return m_info.getKeyLocator();
137  }
138 
142  void
143  setKeyLocator(const KeyLocator& keyLocator)
144  {
145  m_info.setKeyLocator(keyLocator);
146  }
147 
154  void
156  {
158  }
159 
160 public: // EqualityComparable concept
161  bool
162  operator==(const Signature& other) const
163  {
164  return getInfo() == other.getInfo() &&
165  getValue() == other.getValue();
166  }
167 
168  bool
169  operator!=(const Signature& other) const
170  {
171  return !(*this == other);
172  }
173 
174 protected:
176  mutable Block m_value;
177 };
178 
179 } // namespace ndn
180 
181 #endif // NDN_SIGNATURE_HPP
Copyright (c) 2011-2015 Regents of the University of California.
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Signature()=default
void setInfo(const SignatureInfo &info)
Set SignatureInfo.
Definition: signature.hpp:87
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
Definition: signature.hpp:143
void setInfo(const Block &info)
Set SignatureInfo from a block.
Definition: signature.cpp:44
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
Copyright (c) 2013-2015 Regents of the University of California.
bool hasKeyLocator() const
Check if SignatureInfo block has a KeyLocator.
Definition: signature.hpp:123
void unsetKeyLocator()
Unset KeyLocator.
Definition: signature.hpp:155
Error(const std::string &what)
Definition: signature.hpp:40
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Encode to a wire format or estimate wire format.
bool hasKeyLocator() const
Check if KeyLocator is set.
void setValue(const Block &value)
Get SignatureValue from a block.
Definition: signature.cpp:50
const Block & getInfo() const
Get SignatureInfo in the wire format.
Definition: signature.hpp:70
int32_t getSignatureType() const
Get SignatureType.
const Block & getValue() const
Get SignatureValue in the wire format.
Definition: signature.hpp:96
void unsetKeyLocator()
Unset KeyLocator.
bool operator!=(const Signature &other) const
Definition: signature.hpp:169
bool operator==(const Signature &other) const
Definition: signature.hpp:162
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:355
uint32_t getType() const
Get signature type.
Definition: signature.hpp:114
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:134
SignatureInfo m_info
Definition: signature.hpp:175
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:33