blob: 9fd0f62a86613caab590009142ba99d56681a470 [file] [log] [blame]
Yingdi Yu4a557052014-07-09 16:40:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 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_INFO_HPP
23#define NDN_SIGNATURE_INFO_HPP
24
25#include "encoding/tlv.hpp"
26#include "key-locator.hpp"
27
28namespace ndn {
29
30class SignatureInfo
31{
32public:
33 class Error : public Tlv::Error
34 {
35 public:
36 explicit
37 Error(const std::string& what)
38 : Tlv::Error(what)
39 {
40 }
41 };
42
43 SignatureInfo();
44
45 explicit
46 SignatureInfo(Tlv::SignatureTypeValue type);
47
48 SignatureInfo(Tlv::SignatureTypeValue type, const KeyLocator& keyLocator);
49
50 /**
51 * @brief Generate SignatureInfo from a block
52 *
53 * @throws Tlv::Error if supplied block is not formatted correctly
54 */
55 explicit
56 SignatureInfo(const Block& block);
57
58 /// @brief Set SignatureType
59 void
60 setSignatureType(Tlv::SignatureTypeValue type);
61
62 /// @brief Get SignatureType
63 int32_t
64 getSignatureType() const
65 {
66 return m_type;
67 }
68
69 /// @brief Check if KeyLocator is set
70 bool
71 hasKeyLocator() const
72 {
73 return m_hasKeyLocator;
74 }
75
76 /// @brief Set KeyLocator
77 void
78 setKeyLocator(const KeyLocator& keyLocator);
79
80 /**
81 * @brief Get KeyLocator
82 *
83 * @throws SignatureInfo::Error if keyLocator does not exist
84 */
85 const KeyLocator&
86 getKeyLocator() const;
87
88 /// @brief Append signature type specific tlv block
89 void
90 appendTypeSpecificTlv(const Block& block);
91
92 /**
93 * @brief Get signature type specific tlv block
94 *
95 * @throws SignatureInfo::Error if the block does not exist
96 */
97 const Block&
98 getTypeSpecificTlv(uint32_t type) const;
99
100 /// @brief Encode to a wire format or estimate wire format
101 template<bool T>
102 size_t
103 wireEncode(EncodingImpl<T>& block) const;
104
105 /// @brief Encode to a wire format
106 const Block&
107 wireEncode() const;
108
109 /// @brief Decode from a wire format
110 void
111 wireDecode(const Block& wire);
112
113public: // EqualityComparable concept
114 bool
115 operator==(const SignatureInfo& rhs) const;
116
117 bool
118 operator!=(const SignatureInfo& rhs) const
119 {
120 return !(*this == rhs);
121 }
122
123private:
124 int32_t m_type;
125 bool m_hasKeyLocator;
126 KeyLocator m_keyLocator;
127 std::list<Block> m_otherTlvs;
128
129 mutable Block m_wire;
130};
131
132} // namespace ndn
133
134#endif // NDN_SIGNATURE_INFO_HPP