blob: c0a2d88f2059b635f585eb24c07a7156e1d64247 [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"
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:
34 class Error : public Tlv::Error
35 {
36 public:
37 explicit
38 Error(const std::string& what)
39 : Tlv::Error(what)
40 {
41 }
42 };
43
44 SignatureInfo();
45
46 explicit
47 SignatureInfo(Tlv::SignatureTypeValue type);
48
49 SignatureInfo(Tlv::SignatureTypeValue type, const KeyLocator& keyLocator);
50
51 /**
52 * @brief Generate SignatureInfo from a block
53 *
54 * @throws Tlv::Error if supplied block is not formatted correctly
55 */
56 explicit
57 SignatureInfo(const Block& block);
58
59 /// @brief Set SignatureType
60 void
61 setSignatureType(Tlv::SignatureTypeValue type);
62
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
81 /**
82 * @brief Get KeyLocator
83 *
84 * @throws SignatureInfo::Error if keyLocator does not exist
85 */
86 const KeyLocator&
87 getKeyLocator() const;
88
89 /// @brief Append signature type specific tlv block
90 void
91 appendTypeSpecificTlv(const Block& block);
92
93 /**
94 * @brief Get signature type specific tlv block
95 *
96 * @throws SignatureInfo::Error if the block does not exist
97 */
98 const Block&
99 getTypeSpecificTlv(uint32_t type) const;
100
101 /// @brief Encode to a wire format or estimate wire format
102 template<bool T>
103 size_t
104 wireEncode(EncodingImpl<T>& block) const;
105
106 /// @brief Encode to a wire format
107 const Block&
108 wireEncode() const;
109
110 /// @brief Decode from a wire format
111 void
112 wireDecode(const Block& wire);
113
114public: // EqualityComparable concept
115 bool
116 operator==(const SignatureInfo& rhs) const;
117
118 bool
119 operator!=(const SignatureInfo& rhs) const
120 {
121 return !(*this == rhs);
122 }
123
124private:
125 int32_t m_type;
126 bool m_hasKeyLocator;
127 KeyLocator m_keyLocator;
128 std::list<Block> m_otherTlvs;
129
130 mutable Block m_wire;
131};
132
133} // namespace ndn
134
135#endif // NDN_SIGNATURE_INFO_HPP