blob: 9e0f0638fcb1fed4d9380b526ee1ca4802b04def [file] [log] [blame]
Yingdi Yu4a557052014-07-09 16:40:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev74633892015-02-08 18:08:46 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Yingdi Yu4a557052014-07-09 16:40:37 -07004 *
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_INFO_HPP
23#define NDN_SIGNATURE_INFO_HPP
24
25#include "encoding/tlv.hpp"
26#include "key-locator.hpp"
Alexander Afanasyev1c6976d2014-07-13 11:40:50 -070027#include <list>
Yingdi Yu4a557052014-07-09 16:40:37 -070028
29namespace ndn {
30
31class SignatureInfo
32{
33public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060034 class Error : public tlv::Error
Yingdi Yu4a557052014-07-09 16:40:37 -070035 {
36 public:
37 explicit
38 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060039 : tlv::Error(what)
Yingdi Yu4a557052014-07-09 16:40:37 -070040 {
41 }
42 };
43
44 SignatureInfo();
45
46 explicit
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060047 SignatureInfo(tlv::SignatureTypeValue type);
Yingdi Yu4a557052014-07-09 16:40:37 -070048
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060049 SignatureInfo(tlv::SignatureTypeValue type, const KeyLocator& keyLocator);
Yingdi Yu4a557052014-07-09 16:40:37 -070050
51 /**
52 * @brief Generate SignatureInfo from a block
53 *
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060054 * @throws tlv::Error if supplied block is not formatted correctly
Yingdi Yu4a557052014-07-09 16:40:37 -070055 */
56 explicit
57 SignatureInfo(const Block& block);
58
59 /// @brief Set SignatureType
60 void
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060061 setSignatureType(tlv::SignatureTypeValue type);
Yingdi Yu4a557052014-07-09 16:40:37 -070062
63 /// @brief Get SignatureType
64 int32_t
65 getSignatureType() const
66 {
67 return m_type;
68 }
69
70 /// @brief Check if KeyLocator is set
71 bool
72 hasKeyLocator() const
73 {
74 return m_hasKeyLocator;
75 }
76
77 /// @brief Set KeyLocator
78 void
79 setKeyLocator(const KeyLocator& keyLocator);
80
Alexander Afanasyeva7c7f9d2014-07-13 11:51:52 -070081 /// @brief Unset KeyLocator
82 void
83 unsetKeyLocator();
84
Yingdi Yu4a557052014-07-09 16:40:37 -070085 /**
86 * @brief Get KeyLocator
87 *
88 * @throws SignatureInfo::Error if keyLocator does not exist
89 */
90 const KeyLocator&
91 getKeyLocator() const;
92
93 /// @brief Append signature type specific tlv block
94 void
95 appendTypeSpecificTlv(const Block& block);
96
97 /**
98 * @brief Get signature type specific tlv block
99 *
100 * @throws SignatureInfo::Error if the block does not exist
101 */
102 const Block&
103 getTypeSpecificTlv(uint32_t type) const;
104
105 /// @brief Encode to a wire format or estimate wire format
Alexander Afanasyev74633892015-02-08 18:08:46 -0800106 template<encoding::Tag TAG>
Yingdi Yu4a557052014-07-09 16:40:37 -0700107 size_t
Alexander Afanasyev74633892015-02-08 18:08:46 -0800108 wireEncode(EncodingImpl<TAG>& block) const;
Yingdi Yu4a557052014-07-09 16:40:37 -0700109
110 /// @brief Encode to a wire format
111 const Block&
112 wireEncode() const;
113
114 /// @brief Decode from a wire format
115 void
116 wireDecode(const Block& wire);
117
118public: // EqualityComparable concept
119 bool
120 operator==(const SignatureInfo& rhs) const;
121
122 bool
123 operator!=(const SignatureInfo& rhs) const
124 {
125 return !(*this == rhs);
126 }
127
128private:
129 int32_t m_type;
130 bool m_hasKeyLocator;
131 KeyLocator m_keyLocator;
132 std::list<Block> m_otherTlvs;
133
134 mutable Block m_wire;
135};
136
137} // namespace ndn
138
139#endif // NDN_SIGNATURE_INFO_HPP