NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 
78  const SignatureInfo&
80  {
81  return m_info;
82  }
83 
89  void
90  setInfo(const Block& info);
91 
95  void
96  setInfo(const SignatureInfo& info)
97  {
98  m_info = info;
99  }
100 
104  const Block&
105  getValue() const
106  {
107  m_value.encode(); // will do nothing if wire already exists
108  return m_value;
109  }
110 
116  void
117  setValue(const Block& value);
118 
122  uint32_t
123  getType() const
124  {
125  return m_info.getSignatureType();
126  }
127 
131  bool
133  {
134  return m_info.hasKeyLocator();
135  }
136 
142  const KeyLocator&
144  {
145  return m_info.getKeyLocator();
146  }
147 
151  void
152  setKeyLocator(const KeyLocator& keyLocator)
153  {
154  m_info.setKeyLocator(keyLocator);
155  }
156 
163  void
165  {
167  }
168 
169 public: // EqualityComparable concept
170  bool
171  operator==(const Signature& other) const
172  {
173  return getInfo() == other.getInfo() &&
174  getValue() == other.getValue();
175  }
176 
177  bool
178  operator!=(const Signature& other) const
179  {
180  return !(*this == other);
181  }
182 
183 protected:
185  mutable Block m_value;
186 };
187 
188 } // namespace ndn
189 
190 #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:96
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
Definition: signature.hpp:152
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-2016 Regents of the University of California.
bool hasKeyLocator() const
Check if SignatureInfo block has a KeyLocator.
Definition: signature.hpp:132
void unsetKeyLocator()
Unset KeyLocator.
Definition: signature.hpp:164
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:105
void unsetKeyLocator()
Unset KeyLocator.
bool operator!=(const Signature &other) const
Definition: signature.hpp:178
bool operator==(const Signature &other) const
Definition: signature.hpp:171
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:355
uint32_t getType() const
Get signature type.
Definition: signature.hpp:123
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:143
SignatureInfo m_info
Definition: signature.hpp:184
const SignatureInfo & getSignatureInfo() const
Get SignatureInfo.
Definition: signature.hpp:79
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