blob: 1a31abb40b5607041121a73984604d26b2467c7b [file] [log] [blame]
Alexander Afanasyev4aac5572012-08-09 10:49:55 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070022#include "ndn-content-object-header.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070023
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024#include "ns3/log.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "../helper/ndn-encoding-helper.h"
26#include "../helper/ndn-decoding-helper.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070027
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070028#include "../helper/ccnb-parser/common.h"
29#include "../helper/ccnb-parser/visitors/void-depth-first-visitor.h"
30#include "../helper/ccnb-parser/visitors/name-components-visitor.h"
31#include "../helper/ccnb-parser/visitors/non-negative-integer-visitor.h"
32#include "../helper/ccnb-parser/visitors/timestamp-visitor.h"
33#include "../helper/ccnb-parser/visitors/string-visitor.h"
34#include "../helper/ccnb-parser/visitors/uint32t-blob-visitor.h"
35#include "../helper/ccnb-parser/visitors/content-type-visitor.h"
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070036
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037#include "../helper/ccnb-parser/syntax-tree/block.h"
38#include "../helper/ccnb-parser/syntax-tree/dtag.h"
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070039
40#include <boost/foreach.hpp>
41
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042NS_LOG_COMPONENT_DEFINE ("ndn.ContentObjectHeader");
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070043
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044namespace ns3 {
45namespace ndn {
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070046
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070047using namespace CcnbParser;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070048
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049const std::string ContentObjectHeader::Signature::DefaultDigestAlgorithm = "2.16.840.1.101.3.4.2.1";
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070050
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051NS_OBJECT_ENSURE_REGISTERED (ContentObjectHeader);
52NS_OBJECT_ENSURE_REGISTERED (ContentObjectTail);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053
54TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055ContentObjectHeader::GetTypeId (void)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 static TypeId tid = TypeId ("ns3::ndn::ContentObjectHeader")
58 .SetGroupName ("Ndn")
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059 .SetParent<Header> ()
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 .AddConstructor<ContentObjectHeader> ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070061 ;
62 return tid;
63}
64
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065ContentObjectHeader::ContentObjectHeader ()
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070066{
67}
68
69void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070ContentObjectHeader::SetName (const Ptr<NameComponents> &name)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070071{
72 m_name = name;
73}
74
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070075const NameComponents&
76ContentObjectHeader::GetName () const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 if (m_name==0) throw ContentObjectHeaderException();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079 return *m_name;
80}
81
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070082Ptr<const NameComponents>
83ContentObjectHeader::GetNamePtr () const
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070084{
85 return m_name;
86}
87
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088#define CCNB EncodingHelper // just to simplify writing
Alexander Afanasyev9568f952012-04-05 16:09:14 -070089
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070090void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091ContentObjectHeader::Serialize (Buffer::Iterator start) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070092{
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070093 size_t written = 0;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 written += CCNB::AppendBlockHeader (start, CCN_DTAG_ContentObject, CCN_DTAG); // <ContentObject>
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070095
96 // fake signature
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097 written += CCNB::AppendBlockHeader (start, CCN_DTAG_Signature, CCN_DTAG); // <Signature>
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -070098 // Signature ::= √DigestAlgorithm?
99 // Witness?
100 // √SignatureBits
101 if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm)
102 {
103 written += CCNB::AppendString (start, CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
104 }
105 written += CCNB::AppendTaggedBlob (start, CCN_DTAG_SignatureBits, GetSignature ().GetSignatureBits ()); // <SignatureBits />
106 written += CCNB::AppendCloser (start); // </Signature>
107
108 written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
109 written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>...
110 written += CCNB::AppendCloser (start); // </Name>
111
112 // fake signature
113 written += CCNB::AppendBlockHeader (start, CCN_DTAG_SignedInfo, CCN_DTAG); // <SignedInfo>
114 // SignedInfo ::= √PublisherPublicKeyDigest
115 // √Timestamp
116 // √Type?
117 // √FreshnessSeconds?
118 // FinalBlockID?
119 // KeyLocator?
120 written += CCNB::AppendTaggedBlob (start, CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>...
121 GetSignedInfo ().GetPublisherPublicKeyDigest ());
122
123 written += CCNB::AppendBlockHeader (start, CCN_DTAG_Timestamp, CCN_DTAG); // <Timestamp>...
124 written += CCNB::AppendTimestampBlob (start, GetSignedInfo ().GetTimestamp ());
125 written += CCNB::AppendCloser (start);
126
127 if (GetSignedInfo ().GetContentType () != DATA)
128 {
129 uint8_t type[3];
130 type[0] = (GetSignedInfo ().GetContentType () >> 16) & 0xFF;
131 type[1] = (GetSignedInfo ().GetContentType () >> 8 ) & 0xFF;
132 type[2] = (GetSignedInfo ().GetContentType () ) & 0xFF;
133
134 written += CCNB::AppendTaggedBlob (start, CCN_DTAG_Type, type, 3);
135 }
Alexander Afanasyevfaf95812012-06-05 21:28:11 -0700136 if (GetSignedInfo ().GetFreshness () > Seconds(0))
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700137 {
138 written += CCNB::AppendBlockHeader (start, CCN_DTAG_FreshnessSeconds, CCN_DTAG);
139 written += CCNB::AppendNumber (start, GetSignedInfo ().GetFreshness ().ToInteger (Time::S));
140 written += CCNB::AppendCloser (start);
141 }
Alexander Afanasyevfaf95812012-06-05 21:28:11 -0700142 if (GetSignedInfo ().GetKeyLocator () != 0)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700143 {
144 written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyLocator, CCN_DTAG); // <KeyLocator>
145 {
146 written += CCNB::AppendBlockHeader (start, CCN_DTAG_KeyName, CCN_DTAG); // <KeyName>
147 {
148 written += CCNB::AppendBlockHeader (start, CCN_DTAG_Name, CCN_DTAG); // <Name>
149 written += CCNB::AppendNameComponents (start, GetName()); // <Component>...</Component>...
150 written += CCNB::AppendCloser (start); // </Name>
151 }
152 written += CCNB::AppendCloser (start); // </KeyName>
153 }
154 written += CCNB::AppendCloser (start); // </KeyLocator>
155 }
156
157 written += CCNB::AppendCloser (start); // </SignedInfo>
158
159 written += CCNB::AppendBlockHeader (start, CCN_DTAG_Content, CCN_DTAG); // <Content>
160
161 // there are no closing tags !!!
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700162 // The closing tag is handled by ContentObjectTail
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163}
164
165uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700166ContentObjectHeader::GetSerializedSize () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700167{
168 size_t written = 0;
169 written += CCNB::EstimateBlockHeader (CCN_DTAG_ContentObject); // <ContentObject>
170
171 // fake signature
172 written += CCNB::EstimateBlockHeader (CCN_DTAG_Signature); // <Signature>
173 // Signature ::= DigestAlgorithm?
174 // Witness?
175 // SignatureBits
176 if (GetSignature ().GetDigestAlgorithm () != Signature::DefaultDigestAlgorithm)
177 {
178 written += CCNB::EstimateString (CCN_DTAG_DigestAlgorithm, GetSignature ().GetDigestAlgorithm ());
179 }
180 written += CCNB::EstimateTaggedBlob (CCN_DTAG_SignatureBits,
181 sizeof (GetSignature ().GetSignatureBits ())); // <SignatureBits />
182 written += 1; // </Signature>
183
184 written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name>
185 written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>...
186 written += 1; // </Name>
187
188 // fake signature
189 written += CCNB::EstimateBlockHeader (CCN_DTAG_SignedInfo); // <SignedInfo>
190 // SignedInfo ::= √PublisherPublicKeyDigest
191 // √Timestamp
192 // √Type?
193 // √FreshnessSeconds?
194 // FinalBlockID?
195 // KeyLocator?
196
197 written += CCNB::EstimateTaggedBlob (CCN_DTAG_PublisherPublicKeyDigest, // <PublisherPublicKeyDigest>...
198 sizeof (GetSignedInfo ().GetPublisherPublicKeyDigest ()));
199
200 written += CCNB::EstimateBlockHeader (CCN_DTAG_Timestamp); // <Timestamp>...
201 written += CCNB::EstimateTimestampBlob (GetSignedInfo ().GetTimestamp ());
202 written += 1;
203
204 if (GetSignedInfo ().GetContentType () != DATA)
205 {
206 written += CCNB::EstimateTaggedBlob (CCN_DTAG_Type, 3);
207 }
Alexander Afanasyevfaf95812012-06-05 21:28:11 -0700208 if (GetSignedInfo ().GetFreshness () > Seconds(0))
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700209 {
210 written += CCNB::EstimateBlockHeader (CCN_DTAG_FreshnessSeconds);
211 written += CCNB::EstimateNumber (GetSignedInfo ().GetFreshness ().ToInteger (Time::S));
212 written += 1;
213 }
214
Alexander Afanasyevfaf95812012-06-05 21:28:11 -0700215 if (GetSignedInfo ().GetKeyLocator () != 0)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700216 {
217 written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyLocator); // <KeyLocator>
218 {
219 written += CCNB::EstimateBlockHeader (CCN_DTAG_KeyName); // <KeyName>
220 {
221 written += CCNB::EstimateBlockHeader (CCN_DTAG_Name); // <Name>
222 written += CCNB::EstimateNameComponents (GetName()); // <Component>...</Component>...
223 written += 1; // </Name>
224 }
225 written += 1; // </KeyName>
226 }
227 written += 1; // </KeyLocator>
228 }
229
230 written += 1; // </SignedInfo>
231
232 written += CCNB::EstimateBlockHeader (CCN_DTAG_Content); // <Content>
233
234 // there are no closing tags !!!
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700235 // The closing tag is handled by ContentObjectTail
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700236 return written;
237}
238#undef CCNB
239
240class ContentObjectVisitor : public VoidDepthFirstVisitor
241{
242public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700243 virtual void visit (Dtag &n, boost::any param/*should be ContentObjectHeader* */)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700244 {
245 // uint32_t n.m_dtag;
246 // std::list<Ptr<Block> > n.m_nestedBlocks;
247 static NameComponentsVisitor nameComponentsVisitor;
248 static NonNegativeIntegerVisitor nonNegativeIntegerVisitor;
249 static TimestampVisitor timestampVisitor;
250 static StringVisitor stringVisitor;
251 static Uint32tBlobVisitor uint32tBlobVisitor;
252 static ContentTypeVisitor contentTypeVisitor;
253
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700254 ContentObjectHeader &contentObject = *(boost::any_cast<ContentObjectHeader*> (param));
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700255
256 switch (n.m_dtag)
257 {
258 case CCN_DTAG_ContentObject:
259 // process nested blocks
260 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
261 {
262 block->accept (*this, param);
263 }
264 break;
265 case CCN_DTAG_Name:
266 {
267 // process name components
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700268 Ptr<NameComponents> name = Create<NameComponents> ();
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700269
270 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
271 {
272 block->accept (nameComponentsVisitor, &(*name));
273 }
274 contentObject.SetName (name);
275 break;
276 }
277
278 case CCN_DTAG_Signature:
279 // process nested blocks
280 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
281 {
282 block->accept (*this, param);
283 }
284 break;
285
286 case CCN_DTAG_DigestAlgorithm:
287 NS_LOG_DEBUG ("DigestAlgorithm");
288 if (n.m_nestedTags.size ()!=1) // should be exactly one UDATA inside this tag
289 throw CcnbDecodingException ();
290
291 contentObject.GetSignature ().SetDigestAlgorithm
292 (boost::any_cast<std::string> ((*n.m_nestedTags.begin())->accept
293 (stringVisitor)));
294 break;
295
296 case CCN_DTAG_SignatureBits:
297 NS_LOG_DEBUG ("SignatureBits");
298 if (n.m_nestedTags.size ()!=1) // should be only one nested tag
299 throw CcnbDecodingException ();
300
301 contentObject.GetSignature ().SetSignatureBits
302 (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
303 (uint32tBlobVisitor)));
304 break;
305
306 case CCN_DTAG_SignedInfo:
307 // process nested blocks
308 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
309 {
310 block->accept (*this, param);
311 }
312 break;
313
314 case CCN_DTAG_PublisherPublicKeyDigest:
315 NS_LOG_DEBUG ("PublisherPublicKeyDigest");
316 if (n.m_nestedTags.size ()!=1) // should be only one nested tag
317 throw CcnbDecodingException ();
318
319 contentObject.GetSignedInfo ().SetPublisherPublicKeyDigest
320 (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
321 (uint32tBlobVisitor)));
322 break;
323
324 case CCN_DTAG_Timestamp:
325 NS_LOG_DEBUG ("Timestamp");
326 if (n.m_nestedTags.size()!=1) // should be exactly one nested tag
327 throw CcnbDecodingException ();
328
329 contentObject.GetSignedInfo ().SetTimestamp
330 (boost::any_cast<Time> ((*n.m_nestedTags.begin())->accept
331 (timestampVisitor)));
332 break;
333
334 case CCN_DTAG_Type:
335 NS_LOG_DEBUG ("Type");
336 if (n.m_nestedTags.size ()!=1) // should be only one nested tag
337 throw CcnbDecodingException ();
338
339 contentObject.GetSignedInfo ().SetContentType
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700340 (static_cast<ContentObjectHeader::ContentType>
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700341 (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
342 (contentTypeVisitor))));
343 break;
344
345 case CCN_DTAG_FreshnessSeconds:
346 NS_LOG_DEBUG ("FreshnessSeconds");
347
348 if (n.m_nestedTags.size()!=1) // should be exactly one nested tag
349 throw CcnbDecodingException ();
350
351 contentObject.GetSignedInfo ().SetFreshness
352 (Seconds
353 (boost::any_cast<uint32_t> ((*n.m_nestedTags.begin())->accept
354 (nonNegativeIntegerVisitor))));
355 break;
356
357 case CCN_DTAG_KeyLocator:
358 // process nested blocks
359 BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
360 {
361 block->accept (*this, param);
362 }
363 break;
364
365 case CCN_DTAG_KeyName:
366 {
367 if (n.m_nestedTags.size ()!=1) // should be exactly one nested tag
368 throw CcnbDecodingException ();
369
370 Ptr<BaseTag> nameTag = DynamicCast<BaseTag>(n.m_nestedTags.front ());
371 if (nameTag == 0)
372 throw CcnbDecodingException ();
373
374 // process name components
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700375 Ptr<NameComponents> name = Create<NameComponents> ();
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700376
377 BOOST_FOREACH (Ptr<Block> block, nameTag->m_nestedTags)
378 {
379 block->accept (nameComponentsVisitor, &(*name));
380 }
381 contentObject.GetSignedInfo ().SetKeyLocator (name);
382 break;
383 }
384
385 case CCN_DTAG_Content: // !!! HACK
386 // This hack was necessary for memory optimizations (i.e., content is virtual payload)
387 NS_ASSERT_MSG (n.m_nestedTags.size() == 0, "Parser should have stopped just after processing <Content> tag");
388 break;
389
390 default: // ignore all other stuff
391 break;
392 }
393 }
394};
395
396uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700397ContentObjectHeader::Deserialize (Buffer::Iterator start)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700398{
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700399 static ContentObjectVisitor contentObjectVisitor;
400
401 Buffer::Iterator i = start;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700402 Ptr<Block> root = Block::ParseBlock (i);
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700403 root->accept (contentObjectVisitor, this);
404
405 return i.GetDistanceFrom (start);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700406}
407
408TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700409ContentObjectHeader::GetInstanceTypeId (void) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700410{
411 return GetTypeId ();
412}
413
414void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700415ContentObjectHeader::Print (std::ostream &os) const
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700416{
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700417 os << "D: " << GetName ();
418 // os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700419}
420
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700421////////////////////////////////////////////////////////////////////////////////////////////////////
422
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700423ContentObjectTail::ContentObjectTail ()
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700424{
425}
426
427TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700428ContentObjectTail::GetTypeId (void)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700429{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700430 static TypeId tid = TypeId ("ns3::ndn::ContentObjectTail")
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700431 .SetParent<Trailer> ()
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700432 .AddConstructor<ContentObjectTail> ()
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700433 ;
434 return tid;
435}
436
437TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700438ContentObjectTail::GetInstanceTypeId (void) const
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700439{
440 return GetTypeId ();
441}
442
443void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700444ContentObjectTail::Print (std::ostream &os) const
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700445{
446 os << "</Content></ContentObject>";
447}
448
449uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700450ContentObjectTail::GetSerializedSize (void) const
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700451{
452 return 2;
453}
454
455void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700456ContentObjectTail::Serialize (Buffer::Iterator start) const
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700457{
458 Buffer::Iterator i = start;
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700459 i.Prev (2); // Trailer interface requires us to go backwards
460
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700461 i.WriteU8 (0x00); // </Content>
462 i.WriteU8 (0x00); // </ContentObject>
463}
464
465uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700466ContentObjectTail::Deserialize (Buffer::Iterator start)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700467{
468 Buffer::Iterator i = start;
Alexander Afanasyeve91ab752011-08-31 19:13:40 -0700469 i.Prev (2); // Trailer interface requires us to go backwards
470
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700471 uint8_t closing_tag_content = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700472 NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700473
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700474 uint8_t closing_tag_content_object = i.ReadU8 ();
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700475 NS_ASSERT_MSG (closing_tag_content_object==0, "Should be a closing tag </ContentObject> (0x00)");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700476
477 return 2;
478}
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700479
480///////////////////////////////////////////////////////////////////////
481///////////////////////////////////////////////////////////////////////
482///////////////////////////////////////////////////////////////////////
483
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700484ContentObjectHeader::SignedInfo::SignedInfo ()
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700485 : m_publisherPublicKeyDigest (0)
486 // , m_timestamp
487 , m_type (DATA)
488 // , m_freshness
489 // , FinalBlockID
490 // , KeyLocator
491{
492}
493
494void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700495ContentObjectHeader::SignedInfo::SetPublisherPublicKeyDigest (uint32_t digest)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700496{
497 m_publisherPublicKeyDigest = digest;
498}
499
500uint32_t
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700501ContentObjectHeader::SignedInfo::GetPublisherPublicKeyDigest () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700502{
503 return m_publisherPublicKeyDigest;
504}
505
506void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700507ContentObjectHeader::SignedInfo::SetTimestamp (const Time &timestamp)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700508{
509 m_timestamp = timestamp;
510}
511
512Time
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700513ContentObjectHeader::SignedInfo::GetTimestamp () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700514{
515 return m_timestamp;
516}
517
518void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700519ContentObjectHeader::SignedInfo::SetContentType (ContentObjectHeader::ContentType type)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700520{
521 m_type = type;
522}
523
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700524ContentObjectHeader::ContentType
525ContentObjectHeader::SignedInfo::GetContentType () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700526{
527 return m_type;
528}
529
530void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700531ContentObjectHeader::SignedInfo::SetFreshness (const Time &freshness)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700532{
533 m_freshness = freshness;
534}
535
536Time
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700537ContentObjectHeader::SignedInfo::GetFreshness () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700538{
539 return m_freshness;
540}
541
542void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700543ContentObjectHeader::SignedInfo::SetKeyLocator (Ptr<const NameComponents> keyLocator)
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700544{
545 m_keyLocator = keyLocator;
546}
547
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700548Ptr<const NameComponents>
549ContentObjectHeader::SignedInfo::GetKeyLocator () const
Alexander Afanasyev8c5046a2012-06-05 16:22:14 -0700550{
551 return m_keyLocator;
552}
553
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700554} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700555} // namespace ns3