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 | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 158 | * Encode this Data for a particular wire format. If wireFormat is the default wire format, also set the defaultWireEncoding |
| 159 | * field to the encoded result. |
| 160 | * Even though this is const, if wireFormat is the default wire format we update the defaultWireEncoding. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 161 | * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 162 | * @return The encoded byte array. |
| 163 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 164 | SignedBlob |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 165 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 168 | * Decode the input using a particular wire format and update this Data. If wireFormat is the default wire format, also |
| 169 | * set the defaultWireEncoding field to the input. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 170 | * @param input The input byte array to be decoded. |
| 171 | * @param inputLength The length of input. |
| 172 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 173 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 174 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 175 | wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 178 | * Decode the input using a particular wire format and update this Data. If wireFormat is the default wire format, also |
| 179 | * set the defaultWireEncoding field to the input. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 180 | * @param input The input byte array to be decoded. |
| 181 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 182 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 183 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 184 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 185 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 186 | wireDecode(&input[0], input.size(), wireFormat); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 187 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 190 | * Set the dataStruct to point to the values in this interest, without copying any memory. |
| 191 | * WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory. |
| 192 | * @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] | 193 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 194 | void |
| 195 | get(struct ndn_Data& dataStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 198 | * Clear this data object, and set the values by copying from the ndn_Data struct. |
| 199 | * @param dataStruct a C ndn_Data struct |
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 | void |
| 202 | set(const struct ndn_Data& dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 203 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 204 | const Signature* |
| 205 | getSignature() const { return signature_.get(); } |
| 206 | |
| 207 | Signature* |
| 208 | getSignature() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 209 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 210 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 211 | onChanged(); |
| 212 | return signature_.get(); |
| 213 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 214 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 215 | const Name& |
| 216 | getName() const { return name_; } |
| 217 | |
| 218 | Name& |
| 219 | getName() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 220 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 221 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 222 | onChanged(); |
| 223 | return name_; |
| 224 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 225 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 226 | const MetaInfo& |
| 227 | getMetaInfo() const { return metaInfo_; } |
| 228 | |
| 229 | MetaInfo& |
| 230 | getMetaInfo() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 231 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 232 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 233 | onChanged(); |
| 234 | return metaInfo_; |
| 235 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 236 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 237 | const Blob& |
| 238 | getContent() const { return content_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 239 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 240 | /** |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 241 | * Return a pointer to the defaultWireEncoding. It may be null. |
Jeff Thompson | b697c5d | 2013-09-17 17:58:37 -0700 | [diff] [blame] | 242 | */ |
| 243 | const SignedBlob& |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 244 | getDefaultWireEncoding() const { return defaultWireEncoding_; } |
Jeff Thompson | b697c5d | 2013-09-17 17:58:37 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 247 | * Set the signature to a copy of the given signature. |
| 248 | * @param signature The signature object which is cloned. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 249 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 250 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 251 | Data& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 252 | setSignature(const Signature& signature) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 253 | { |
| 254 | signature_ = signature.clone(); |
| 255 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 256 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 257 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 258 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 259 | /** |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 260 | * 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] | 261 | * @param name The Name which is copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 262 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 263 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 264 | virtual Data& |
| 265 | setName(const Name& name); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 266 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 267 | /** |
| 268 | * Set metaInfo to a copy of the given MetaInfo. |
| 269 | * @param metaInfo The MetaInfo which is copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 270 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 271 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 272 | Data& |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 273 | setMetainfo(const MetaInfo& metaInfo) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 274 | { |
| 275 | metaInfo_ = metaInfo; |
| 276 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 277 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 278 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 279 | |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 280 | /** |
| 281 | * Set the content to a copy of the data in the vector. |
| 282 | * @param content A vector whose contents are copied. |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 283 | * @return This Data so that you can chain calls to update values. |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 284 | */ |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 285 | Data& |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 286 | setContent(const std::vector<uint8_t>& content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 287 | { |
| 288 | content_ = content; |
| 289 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 290 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 291 | } |
Jeff Thompson | 3776d1c | 2013-09-17 14:22:51 -0700 | [diff] [blame] | 292 | |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 293 | Data& |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 294 | setContent(const uint8_t* content, size_t contentLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 295 | { |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 296 | content_ = Blob(content, contentLength); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 297 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 298 | return *this; |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 299 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 300 | |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 301 | Data& |
Jeff Thompson | 63631b7 | 2013-10-14 14:00:58 -0700 | [diff] [blame] | 302 | setContent(const Blob& content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 303 | { |
| 304 | content_ = content; |
| 305 | onChanged(); |
Jeff Thompson | 6d59197 | 2013-10-17 11:16:32 -0700 | [diff] [blame] | 306 | return *this; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 307 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 308 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 309 | private: |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 310 | /** |
| 311 | * Clear the wire encoding. |
| 312 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 313 | void |
| 314 | onChanged(); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 315 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 316 | ptr_lib::shared_ptr<Signature> signature_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 317 | Name name_; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 318 | MetaInfo metaInfo_; |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 319 | Blob content_; |
Jeff Thompson | f1ffba8 | 2013-10-19 17:57:12 -0700 | [diff] [blame^] | 320 | SignedBlob defaultWireEncoding_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
| 323 | } |
| 324 | |
| 325 | #endif |