Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 8 | #ifndef NDN_DATA_HPP |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 9 | #define NDN_DATA_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 10 | |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 11 | #include "common.hpp" |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 12 | #include "name.hpp" |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 13 | #include "util/signed-blob.hpp" |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 14 | #include "c/data-types.h" |
| 15 | #include "encoding/wire-format.hpp" |
| 16 | |
| 17 | struct ndn_MetaInfo; |
| 18 | struct ndn_Signature; |
| 19 | struct ndn_Data; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 20 | |
| 21 | namespace ndn { |
| 22 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 23 | /** |
Jeff Thompson | 1fe62d4 | 2013-09-27 16:49:45 -0700 | [diff] [blame] | 24 | * A Signature is an abstract base class providing methods to work with the signature information in a Data packet. |
Jeff Thompson | fd2a7ef | 2013-09-27 16:50:54 -0700 | [diff] [blame] | 25 | * You must create an object of a subclass, for example Sha256WithRsaSignature. |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 26 | */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 27 | class Signature { |
| 28 | public: |
| 29 | /** |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 30 | * Return a pointer to a new Signature which is a copy of this signature. |
| 31 | * This is pure virtual, the subclass must implement it. |
| 32 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 33 | virtual ptr_lib::shared_ptr<Signature> |
| 34 | clone() const = 0; |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * The virtual destructor. |
| 38 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 39 | virtual |
| 40 | ~Signature(); |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 43 | * Set the signatureStruct to point to the values in this signature object, without copying any memory. |
| 44 | * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 45 | * This is pure virtual, the subclass must implement it. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 46 | * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated. |
| 47 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 48 | virtual void |
| 49 | get(struct ndn_Signature& signatureStruct) const = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Clear this signature, and set the values by copying from the ndn_Signature struct. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 53 | * This is pure virtual, the subclass must implement it. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 54 | * @param signatureStruct a C ndn_Signature struct |
| 55 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 56 | virtual void |
| 57 | set(const struct ndn_Signature& signatureStruct) = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 60 | /** |
| 61 | * An MetaInfo holds the meta info which is signed inside the data packet. |
| 62 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 63 | class MetaInfo { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 64 | public: |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 65 | MetaInfo() |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 66 | { |
| 67 | type_ = ndn_ContentType_DATA; |
| 68 | freshnessSeconds_ = -1; |
| 69 | } |
| 70 | |
| 71 | /** |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 72 | * Set the metaInfoStruct to point to the values in this meta info object, without copying any memory. |
| 73 | * WARNING: The resulting pointers in metaInfoStruct are invalid after a further use of this object which could reallocate memory. |
| 74 | * @param metaInfoStruct a C ndn_MetaInfo struct where the name components array is already allocated. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 75 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 76 | void |
| 77 | get(struct ndn_MetaInfo& metaInfoStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 80 | * Clear this meta info, and set the values by copying from the ndn_MetaInfo struct. |
| 81 | * @param metaInfoStruct a C ndn_MetaInfo struct |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 82 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 83 | void |
| 84 | set(const struct ndn_MetaInfo& metaInfoStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 85 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 86 | MillisecondsSince1970 |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 87 | getTimestampMilliseconds() const { return timestampMilliseconds_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 88 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 89 | ndn_ContentType |
| 90 | getType() const { return type_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 91 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 92 | int |
| 93 | getFreshnessSeconds() const { return freshnessSeconds_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 94 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 95 | const Name::Component& |
| 96 | getFinalBlockID() const { return finalBlockID_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 97 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 98 | void |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 99 | setTimestampMilliseconds(MillisecondsSince1970 timestampMilliseconds) { timestampMilliseconds_ = timestampMilliseconds; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 100 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 101 | void |
| 102 | setType(ndn_ContentType type) { type_ = type; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 103 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 104 | void |
| 105 | setFreshnessSeconds(int freshnessSeconds) { freshnessSeconds_ = freshnessSeconds; } |
Jeff Thompson | 70d0e46 | 2013-10-14 13:44:32 -0700 | [diff] [blame] | 106 | |
| 107 | void |
| 108 | setFinalBlockID(const Blob& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 109 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 110 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 111 | setFinalBlockID(const std::vector<uint8_t>& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 112 | |
| 113 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 114 | setFinalBlockID(const uint8_t* finalBlockID, size_t finalBlockIdLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 115 | { |
Jeff Thompson | 85db6d7 | 2013-09-12 12:41:18 -0700 | [diff] [blame] | 116 | finalBlockID_ = Name::Component(finalBlockID, finalBlockIdLength); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 119 | private: |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 120 | MillisecondsSince1970 timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */ |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 121 | ndn_ContentType type_; /**< default is ndn_ContentType_DATA. -1 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 122 | int freshnessSeconds_; /**< -1 for none */ |
Jeff Thompson | 85db6d7 | 2013-09-12 12:41:18 -0700 | [diff] [blame] | 123 | Name::Component finalBlockID_; /** size 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 126 | class Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 127 | public: |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Create a new Data object with default values and where the signature is a blank Sha256WithRsaSignature. |
| 130 | */ |
| 131 | Data(); |
| 132 | |
| 133 | /** |
| 134 | * Create a new Data object with the given name and default values and where the signature is a blank Sha256WithRsaSignature. |
| 135 | * @param name A reference to the name which is copied. |
| 136 | */ |
| 137 | Data(const Name& name); |
Jeff Thompson | f5dbd27 | 2013-08-08 16:49:55 -0700 | [diff] [blame] | 138 | |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 139 | /** |
Jeff Thompson | 25bfdca | 2013-10-16 17:05:41 -0700 | [diff] [blame] | 140 | * The copy constructor: Create a deep copy of the given data object, including a clone of the signature object. |
| 141 | * @param data The data object to copy. |
| 142 | */ |
| 143 | Data(const Data& data); |
| 144 | |
| 145 | /** |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 146 | * The virtual destructor. |
| 147 | */ |
Jeff Thompson | 25bfdca | 2013-10-16 17:05:41 -0700 | [diff] [blame] | 148 | virtual ~Data(); |
| 149 | |
| 150 | /** |
| 151 | * The assignment operator: Copy fields and make a clone of the signature. |
| 152 | * @param data The other object to copy from. |
| 153 | * @return A reference to this object. |
| 154 | */ |
| 155 | Data& operator=(const Data& data); |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 158 | * Encode this Data for a particular wire format. Also, set the wireEncoding field to the encoded result. |
| 159 | * This is not const because it updates the wireEncoding. |
| 160 | * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 161 | * @return The encoded byte array. |
| 162 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 163 | SignedBlob |
| 164 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input. |
| 168 | * @param input The input byte array to be decoded. |
| 169 | * @param inputLength The length of input. |
| 170 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 171 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 172 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 173 | wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input. |
| 177 | * @param input The input byte array to be decoded. |
| 178 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 179 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 180 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 181 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 182 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 183 | wireDecode(&input[0], input.size(), wireFormat); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 184 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 187 | * Set the dataStruct to point to the values in this interest, without copying any memory. |
| 188 | * WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory. |
| 189 | * @param dataStruct a C ndn_Data struct where the name components array is already allocated. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 190 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 191 | void |
| 192 | get(struct ndn_Data& dataStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 193 | |
| 194 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 195 | * Clear this data object, and set the values by copying from the ndn_Data struct. |
| 196 | * @param dataStruct a C ndn_Data struct |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 197 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 198 | void |
| 199 | set(const struct ndn_Data& dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 200 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 201 | const Signature* |
| 202 | getSignature() const { return signature_.get(); } |
| 203 | |
| 204 | Signature* |
| 205 | getSignature() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 206 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 207 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 208 | onChanged(); |
| 209 | return signature_.get(); |
| 210 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 211 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 212 | const Name& |
| 213 | getName() const { return name_; } |
| 214 | |
| 215 | Name& |
| 216 | getName() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 217 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 218 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 219 | onChanged(); |
| 220 | return name_; |
| 221 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 222 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 223 | const MetaInfo& |
| 224 | getMetaInfo() const { return metaInfo_; } |
| 225 | |
| 226 | MetaInfo& |
| 227 | getMetaInfo() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 228 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 229 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 230 | onChanged(); |
| 231 | return metaInfo_; |
| 232 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 233 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 234 | const Blob& |
| 235 | getContent() const { return content_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 236 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 237 | /** |
Jeff Thompson | b697c5d | 2013-09-17 17:58:37 -0700 | [diff] [blame] | 238 | * Return a pointer to the wireEncoding. It may be null. |
| 239 | */ |
| 240 | const SignedBlob& |
| 241 | getWireEncoding() const { return wireEncoding_; } |
| 242 | |
| 243 | /** |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 244 | * Set the signature to a copy of the given signature. |
| 245 | * @param signature The signature object which is cloned. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 246 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 247 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 248 | Data& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 249 | setSignature(const Signature& signature) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 250 | { |
| 251 | signature_ = signature.clone(); |
| 252 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 253 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 254 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 255 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 256 | /** |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 257 | * Set name to a copy of the given Name. This is virtual so that a subclass can override to validate the name. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 258 | * @param name The Name which is copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 259 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 260 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 261 | virtual Data& |
| 262 | setName(const Name& name); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 263 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 264 | /** |
| 265 | * Set metaInfo to a copy of the given MetaInfo. |
| 266 | * @param metaInfo The MetaInfo which is copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 267 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 268 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 269 | Data& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 270 | setMetainfo(const MetaInfo& metaInfo) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 271 | { |
| 272 | metaInfo_ = metaInfo; |
| 273 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 274 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 275 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 276 | |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Set the content to a copy of the data in the vector. |
| 279 | * @param content A vector whose contents are copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 280 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 281 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 282 | Data& |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 283 | setContent(const std::vector<uint8_t>& content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 284 | { |
| 285 | content_ = content; |
| 286 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 287 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 288 | } |
Jeff Thompson | 3776d1c | 2013-09-17 14:22:51 -0700 | [diff] [blame] | 289 | |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 290 | Data& |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 291 | setContent(const uint8_t* content, size_t contentLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 292 | { |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 293 | content_ = Blob(content, contentLength); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 294 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 295 | return *this; |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 296 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 297 | |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 298 | Data& |
Jeff Thompson | 63631b7 | 2013-10-14 14:00:58 -0700 | [diff] [blame] | 299 | setContent(const Blob& content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 300 | { |
| 301 | content_ = content; |
| 302 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 303 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 304 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 305 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 306 | private: |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Clear the wire encoding. |
| 309 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 310 | void |
| 311 | onChanged(); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 312 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 313 | ptr_lib::shared_ptr<Signature> signature_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 314 | Name name_; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 315 | MetaInfo metaInfo_; |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 316 | Blob content_; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 317 | SignedBlob wireEncoding_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | } |
| 321 | |
| 322 | #endif |