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-2020 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 
38 class
39 #ifndef DOXYGEN // Older versions of doxygen can't parse deprecated decorators on classes
40 [[deprecated("use Data::get/setSignatureInfo and Data::get/setSignatureValue directly")]]
41 #endif // DOXYGEN
43 {
44 public:
45  class Error : public tlv::Error
46  {
47  public:
48  using tlv::Error::Error;
49  };
50 
51  Signature() = default;
52 
53  explicit
54  Signature(const Block& info, const Block& value = Block());
55 
56  explicit
57  Signature(const SignatureInfo& info, const Block& value = Block());
58 
61  explicit
62  operator bool() const
63  {
64  return m_info.getSignatureType() != -1;
65  }
66 
69  const SignatureInfo&
71  {
72  return m_info;
73  }
74 
77  const Block&
78  getInfo() const
79  {
80  return m_info.wireEncode();
81  }
82 
86  void
87  setInfo(const Block& info);
88 
91  void
92  setInfo(const SignatureInfo& info)
93  {
94  m_info = info;
95  }
96 
99  const Block&
100  getValue() const
101  {
102  return m_value;
103  }
104 
108  void
109  setValue(const Block& value);
110 
111 public: // SignatureInfo fields
116  getType() const;
117 
120  bool
122  {
123  return m_info.hasKeyLocator();
124  }
125 
129  const KeyLocator&
131  {
132  return m_info.getKeyLocator();
133  }
134 
137  void
138  setKeyLocator(const KeyLocator& keyLocator)
139  {
140  m_info.setKeyLocator(keyLocator);
141  }
142 
148  void
150  {
151  m_info.setKeyLocator(nullopt);
152  }
153 
154 protected:
156  mutable Block m_value;
157 };
158 
159 } // namespace ndn
160 
161 #endif // NDN_SIGNATURE_HPP
Definition: data.cpp:26
Represents a SignatureInfo or InterestSignatureInfo TLV element.
void setInfo(const SignatureInfo &info)
Set SignatureInfo.
Definition: signature.hpp:92
void setKeyLocator(const KeyLocator &keyLocator)
Set KeyLocator.
Definition: signature.hpp:138
Represents a TLV element of the NDN packet format.
Definition: block.hpp:42
bool hasKeyLocator() const
Check if KeyLocator exists in SignatureInfo.
Definition: signature.hpp:121
void unsetKeyLocator()
Unset KeyLocator.
Definition: signature.hpp:149
const Block & getInfo() const
Get SignatureInfo as wire format.
Definition: signature.hpp:78
const Block & getValue() const
Get SignatureValue.
Definition: signature.hpp:100
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:131
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:130
SignatureInfo m_info
Definition: signature.hpp:155
const SignatureInfo & getSignatureInfo() const
Get SignatureInfo.
Definition: signature.hpp:70
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
represents an error in TLV encoding or decoding
Definition: tlv.hpp:51
Holds SignatureInfo and SignatureValue in a Data packet.
Definition: signature.hpp:38