All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
signature.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_SIGNATURE_HPP
8 #define NDN_SIGNATURE_HPP
9 
10 namespace ndn {
11 
15 class Signature
16 {
17 public:
18  class Error : public Tlv::Error
19  {
20  public:
21  explicit
22  Error(const std::string& what)
23  : Tlv::Error(what)
24  {
25  }
26  };
27 
28  enum {
29  Sha256 = 0,
31  };
32 
34  : m_type(-1)
35  {
36  }
37 
38  Signature(const Block& info, const Block& value = Block())
39  : m_value(value)
40  {
41  setInfo(info);
42  }
43 
44  operator bool() const
45  {
46  return m_type != -1;
47  }
48 
49  uint32_t
50  getType() const
51  {
52  return m_type;
53  }
54 
55  const Block&
56  getInfo() const
57  {
58  m_info.encode(); // will do nothing if wire already exists
59  return m_info;
60  }
61 
62  void
63  setInfo(const Block& info)
64  {
65  m_info = info;
66  if (m_info.hasWire() || m_info.hasValue())
67  {
68  m_info.parse();
69  const Block& signatureType = m_info.get(Tlv::SignatureType);
70  m_type = readNonNegativeInteger(signatureType);
71  }
72  else
73  {
74  m_type = -1;
75  }
76  }
77 
78  const Block&
79  getValue() const
80  {
81  m_value.encode(); // will do nothing if wire already exists
82  return m_value;
83  }
84 
85  void
86  setValue(const Block& value)
87  {
88  m_value = value;
89  }
90 
91  void
93  {
94  m_type = -1;
95  m_info.reset();
96  m_value.reset();
97  }
98 
99 public: // EqualityComparable concept
100  bool
101  operator==(const Signature& other) const
102  {
103  return getInfo() == other.getInfo() &&
104  getValue() == other.getValue();
105  }
106 
107  bool
108  operator!=(const Signature& other) const
109  {
110  return !(*this == other);
111  }
112 
113 protected:
114  int32_t m_type;
115 
116  mutable Block m_info;
117  mutable Block m_value;
118 };
119 
120 } // namespace ndn
121 
122 #endif // NDN_SIGNATURE_HPP
bool hasValue() const
Check if the Block has value block (no type and length are encoded)
Definition: block.hpp:294
int32_t m_type
Definition: signature.hpp:114
void setInfo(const Block &info)
Definition: signature.hpp:63
bool operator==(const Signature &other) const
Definition: signature.hpp:101
Class representing wire element of the NDN packet.
Definition: block.hpp:26
const Block & getValue() const
Definition: signature.hpp:79
uint64_t readNonNegativeInteger(const Block &block)
Error(const std::string &what)
Definition: signature.hpp:22
uint32_t getType() const
Definition: signature.hpp:50
void setValue(const Block &value)
Definition: signature.hpp:86
bool operator!=(const Signature &other) const
Definition: signature.hpp:108
const Block & get(uint32_t type) const
Get the first subelement of the requested type.
Definition: block.hpp:326
void reset()
Reset wire buffer of the element.
Definition: block.hpp:300
void parse() const
Parse wire buffer into subblocks.
Definition: block.cpp:265
const Block & getInfo() const
Definition: signature.hpp:56
void encode()
Encode subblocks into wire buffer.
Definition: block.cpp:298
SignatureType
Definition: tlv.hpp:66
bool hasWire() const
Check if the Block has fully encoded wire.
Definition: block.hpp:288
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:15