blob: 4ee8e6472b06addef8158581be314c9053c02807 [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"
Yingdi Yu6be43f32015-06-09 14:19:54 -070027#include "security/validity-period.hpp"
Alexander Afanasyev1c6976d2014-07-13 11:40:50 -070028#include <list>
Yingdi Yu4a557052014-07-09 16:40:37 -070029
30namespace ndn {
31
32class SignatureInfo
33{
34public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060035 class Error : public tlv::Error
Yingdi Yu4a557052014-07-09 16:40:37 -070036 {
37 public:
38 explicit
39 Error(const std::string& what)
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060040 : tlv::Error(what)
Yingdi Yu4a557052014-07-09 16:40:37 -070041 {
42 }
43 };
44
45 SignatureInfo();
46
47 explicit
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060048 SignatureInfo(tlv::SignatureTypeValue type);
Yingdi Yu4a557052014-07-09 16:40:37 -070049
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060050 SignatureInfo(tlv::SignatureTypeValue type, const KeyLocator& keyLocator);
Yingdi Yu4a557052014-07-09 16:40:37 -070051
52 /**
53 * @brief Generate SignatureInfo from a block
54 *
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060055 * @throws tlv::Error if supplied block is not formatted correctly
Yingdi Yu4a557052014-07-09 16:40:37 -070056 */
57 explicit
58 SignatureInfo(const Block& block);
59
60 /// @brief Set SignatureType
61 void
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060062 setSignatureType(tlv::SignatureTypeValue type);
Yingdi Yu4a557052014-07-09 16:40:37 -070063
64 /// @brief Get SignatureType
65 int32_t
66 getSignatureType() const
67 {
68 return m_type;
69 }
70
71 /// @brief Check if KeyLocator is set
72 bool
73 hasKeyLocator() const
74 {
75 return m_hasKeyLocator;
76 }
77
78 /// @brief Set KeyLocator
79 void
80 setKeyLocator(const KeyLocator& keyLocator);
81
Alexander Afanasyeva7c7f9d2014-07-13 11:51:52 -070082 /// @brief Unset KeyLocator
83 void
84 unsetKeyLocator();
85
Yingdi Yu4a557052014-07-09 16:40:37 -070086 /**
87 * @brief Get KeyLocator
88 *
89 * @throws SignatureInfo::Error if keyLocator does not exist
90 */
91 const KeyLocator&
92 getKeyLocator() const;
93
Yingdi Yu6be43f32015-06-09 14:19:54 -070094 /// @brief Set ValidityPeriod
95 void
96 setValidityPeriod(const security::ValidityPeriod& validityPeriod);
97
98 /// @brief Unset ValidityPeriod
99 void
100 unsetValidityPeriod();
101
102 /// @brief Get ValidityPeriod
103 security::ValidityPeriod
104 getValidityPeriod() const;
105
Yingdi Yu4a557052014-07-09 16:40:37 -0700106 /// @brief Append signature type specific tlv block
107 void
108 appendTypeSpecificTlv(const Block& block);
109
110 /**
111 * @brief Get signature type specific tlv block
112 *
113 * @throws SignatureInfo::Error if the block does not exist
114 */
115 const Block&
116 getTypeSpecificTlv(uint32_t type) const;
117
118 /// @brief Encode to a wire format or estimate wire format
Alexander Afanasyev74633892015-02-08 18:08:46 -0800119 template<encoding::Tag TAG>
Yingdi Yu4a557052014-07-09 16:40:37 -0700120 size_t
Alexander Afanasyevd5c48e02015-06-24 11:58:14 -0700121 wireEncode(EncodingImpl<TAG>& encoder) const;
Yingdi Yu4a557052014-07-09 16:40:37 -0700122
123 /// @brief Encode to a wire format
124 const Block&
125 wireEncode() const;
126
127 /// @brief Decode from a wire format
128 void
129 wireDecode(const Block& wire);
130
131public: // EqualityComparable concept
132 bool
133 operator==(const SignatureInfo& rhs) const;
134
135 bool
136 operator!=(const SignatureInfo& rhs) const
137 {
138 return !(*this == rhs);
139 }
140
141private:
142 int32_t m_type;
143 bool m_hasKeyLocator;
144 KeyLocator m_keyLocator;
145 std::list<Block> m_otherTlvs;
146
147 mutable Block m_wire;
148};
149
150} // namespace ndn
151
152#endif // NDN_SIGNATURE_INFO_HPP