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 | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 86 | double |
| 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 |
| 99 | setTimestampMilliseconds(double 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 | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 106 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 107 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 108 | setFinalBlockID(const std::vector<uint8_t>& finalBlockID) { finalBlockID_ = Name::Component(finalBlockID); } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 109 | |
| 110 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 111 | setFinalBlockID(const uint8_t* finalBlockID, size_t finalBlockIdLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 112 | { |
Jeff Thompson | 85db6d7 | 2013-09-12 12:41:18 -0700 | [diff] [blame] | 113 | finalBlockID_ = Name::Component(finalBlockID, finalBlockIdLength); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 116 | private: |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 117 | double timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */ |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 118 | ndn_ContentType type_; /**< default is ndn_ContentType_DATA. -1 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 119 | int freshnessSeconds_; /**< -1 for none */ |
Jeff Thompson | 85db6d7 | 2013-09-12 12:41:18 -0700 | [diff] [blame] | 120 | Name::Component finalBlockID_; /** size 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 123 | class Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 124 | public: |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 125 | /** |
| 126 | * Create a new Data object with default values and where the signature is a blank Sha256WithRsaSignature. |
| 127 | */ |
| 128 | Data(); |
| 129 | |
| 130 | /** |
| 131 | * Create a new Data object with the given name and default values and where the signature is a blank Sha256WithRsaSignature. |
| 132 | * @param name A reference to the name which is copied. |
| 133 | */ |
| 134 | Data(const Name& name); |
Jeff Thompson | f5dbd27 | 2013-08-08 16:49:55 -0700 | [diff] [blame] | 135 | |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Encode this Data for a particular wire format. Also, set the wireEncoding field to the encoded result. |
| 138 | * This is not const because it updates the wireEncoding. |
| 139 | * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 140 | * @return The encoded byte array. |
| 141 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 142 | SignedBlob |
| 143 | wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input. |
| 147 | * @param input The input byte array to be decoded. |
| 148 | * @param inputLength The length of input. |
| 149 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 150 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 151 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 152 | wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * Decode the input using a particular wire format and update this Data. Also, set the wireEncoding field to the input. |
| 156 | * @param input The input byte array to be decoded. |
| 157 | * @param wireFormat A WireFormat object used to decode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 158 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 159 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 160 | wireDecode(const std::vector<uint8_t>& input, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 161 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 162 | wireDecode(&input[0], input.size(), wireFormat); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 163 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 164 | |
| 165 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 166 | * Set the dataStruct to point to the values in this interest, without copying any memory. |
| 167 | * WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory. |
| 168 | * @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] | 169 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 170 | void |
| 171 | get(struct ndn_Data& dataStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 172 | |
| 173 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 174 | * Clear this data object, and set the values by copying from the ndn_Data struct. |
| 175 | * @param dataStruct a C ndn_Data struct |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 176 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 177 | void |
| 178 | set(const struct ndn_Data& dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 179 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 180 | const Signature* |
| 181 | getSignature() const { return signature_.get(); } |
| 182 | |
| 183 | Signature* |
| 184 | getSignature() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 185 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 186 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 187 | onChanged(); |
| 188 | return signature_.get(); |
| 189 | } |
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 | const Name& |
| 192 | getName() const { return name_; } |
| 193 | |
| 194 | Name& |
| 195 | getName() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 196 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 197 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 198 | onChanged(); |
| 199 | return name_; |
| 200 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 201 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 202 | const MetaInfo& |
| 203 | getMetaInfo() const { return metaInfo_; } |
| 204 | |
| 205 | MetaInfo& |
| 206 | getMetaInfo() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 207 | { |
Jeff Thompson | 3352fc2 | 2013-09-17 12:07:14 -0700 | [diff] [blame] | 208 | // TODO: Should add an OnChanged listener instead of always calling onChanged. |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 209 | onChanged(); |
| 210 | return metaInfo_; |
| 211 | } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 212 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 213 | const Blob& |
| 214 | getContent() const { return content_; } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 215 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 216 | /** |
Jeff Thompson | b697c5d | 2013-09-17 17:58:37 -0700 | [diff] [blame] | 217 | * Return a pointer to the wireEncoding. It may be null. |
| 218 | */ |
| 219 | const SignedBlob& |
| 220 | getWireEncoding() const { return wireEncoding_; } |
| 221 | |
| 222 | /** |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 223 | * Set the signature to a copy of the given signature. |
| 224 | * @param signature The signature object which is cloned. |
| 225 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 226 | void |
| 227 | setSignature(const Signature& signature) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 228 | { |
| 229 | signature_ = signature.clone(); |
| 230 | onChanged(); |
| 231 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 232 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Set name to a copy of the given Name. |
| 235 | * @param name The Name which is copied. |
| 236 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 237 | void |
| 238 | setName(const Name& name) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 239 | { |
| 240 | name_ = name; |
| 241 | onChanged(); |
| 242 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 243 | |
Jeff Thompson | 0cd8c4a | 2013-09-13 17:46:40 -0700 | [diff] [blame] | 244 | /** |
| 245 | * Set metaInfo to a copy of the given MetaInfo. |
| 246 | * @param metaInfo The MetaInfo which is copied. |
| 247 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 248 | void |
| 249 | setMetainfo(const MetaInfo& metaInfo) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 250 | { |
| 251 | metaInfo_ = metaInfo; |
| 252 | onChanged(); |
| 253 | } |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 254 | |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 255 | /** |
| 256 | * Set the content to a copy of the data in the vector. |
| 257 | * @param content A vector whose contents are copied. |
| 258 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 259 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 260 | setContent(const std::vector<uint8_t>& content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 261 | { |
| 262 | content_ = content; |
| 263 | onChanged(); |
| 264 | } |
Jeff Thompson | 3776d1c | 2013-09-17 14:22:51 -0700 | [diff] [blame] | 265 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 266 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 267 | setContent(const uint8_t* content, size_t contentLength) |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 268 | { |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 269 | content_ = Blob(content, contentLength); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 270 | onChanged(); |
Jeff Thompson | 46bd45f | 2013-08-08 16:46:41 -0700 | [diff] [blame] | 271 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 272 | |
| 273 | /** |
| 274 | * Set content to point to an existing byte array. IMPORTANT: After calling this, |
| 275 | * if you keep a pointer to the array then you must treat the array as immutable and promise not to change it. |
| 276 | * @param content A pointer to a vector with the byte array. This takes another reference and does not copy the bytes. |
| 277 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 278 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 279 | setContent(const ptr_lib::shared_ptr<std::vector<uint8_t> > &content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 280 | { |
| 281 | content_ = content; |
| 282 | onChanged(); |
| 283 | } |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 284 | |
| 285 | void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 286 | setContent(const ptr_lib::shared_ptr<const std::vector<uint8_t> > &content) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 287 | { |
| 288 | content_ = content; |
| 289 | onChanged(); |
| 290 | } |
Jeff Thompson | c2b7b14 | 2013-09-12 15:29:04 -0700 | [diff] [blame] | 291 | |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 292 | private: |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 293 | /** |
| 294 | * Clear the wire encoding. |
| 295 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 296 | void |
| 297 | onChanged(); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 298 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 299 | ptr_lib::shared_ptr<Signature> signature_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 300 | Name name_; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 301 | MetaInfo metaInfo_; |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 302 | Blob content_; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 303 | SignedBlob wireEncoding_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | } |
| 307 | |
| 308 | #endif |