blob: 684a061c91e190cda7f031fc946dbe823a57b4b4 [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson5cae5e52013-07-10 19:41:20 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#include "common.hpp"
Jeff Thompson56ec9e22013-08-02 11:34:07 -07008#include "data.hpp"
Jeff Thompson20af0732013-09-12 17:01:45 -07009#include "sha256-with-rsa-signature.hpp"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070010
11using namespace std;
12
13namespace ndn {
14
Jeff Thompson20af0732013-09-12 17:01:45 -070015Signature::~Signature()
Jeff Thompson5cae5e52013-07-10 19:41:20 -070016{
Jeff Thompson20af0732013-09-12 17:01:45 -070017}
Jeff Thompsonf4585af2013-09-11 14:56:59 -070018
Jeff Thompson0050abe2013-09-17 12:50:25 -070019void
20MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070021{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070022 metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
23 metaInfoStruct.type = type_;
24 metaInfoStruct.freshnessSeconds = freshnessSeconds_;
Jeff Thompson145e2252013-09-12 12:51:35 -070025 finalBlockID_.get(metaInfoStruct.finalBlockID);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070026}
27
Jeff Thompson0050abe2013-09-17 12:50:25 -070028void
29MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070030{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070031 timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
32 type_ = metaInfoStruct.type;
33 freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070034 finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value, metaInfoStruct.finalBlockID.valueLength));
Jeff Thompson5cae5e52013-07-10 19:41:20 -070035}
36
Jeff Thompson20af0732013-09-12 17:01:45 -070037Data::Data()
38: signature_(new Sha256WithRsaSignature())
39{
40}
41
42Data::Data(const Name& name)
43: name_(name), signature_(new Sha256WithRsaSignature())
44{
45}
46
Jeff Thompson0050abe2013-09-17 12:50:25 -070047void
48Data::get(struct ndn_Data& dataStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070049{
Jeff Thompson20af0732013-09-12 17:01:45 -070050 signature_->get(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070051 name_.get(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070052 metaInfo_.get(dataStruct.metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070053
Jeff Thompson56ec9e22013-08-02 11:34:07 -070054 dataStruct.contentLength = content_.size();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070055 if (content_.size() > 0)
Jeff Thompson0899c0f2013-09-12 12:15:31 -070056 dataStruct.content = (unsigned char*)content_.buf();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070057 else
Jeff Thompson56ec9e22013-08-02 11:34:07 -070058 dataStruct.content = 0;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070059}
60
Jeff Thompson0050abe2013-09-17 12:50:25 -070061void
62Data::set(const struct ndn_Data& dataStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070063{
Jeff Thompson20af0732013-09-12 17:01:45 -070064 signature_->set(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070065 name_.set(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070066 metaInfo_.set(dataStruct.metaInfo);
Jeff Thompson0899c0f2013-09-12 12:15:31 -070067 content_ = Blob(dataStruct.content, dataStruct.contentLength);
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070068
69 onChanged();
70}
71
Jeff Thompson0050abe2013-09-17 12:50:25 -070072SignedBlob
73Data::wireEncode(WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070074{
75 unsigned int signedPortionBeginOffset, signedPortionEndOffset;
76 Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
77
78 wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
79 return wireEncoding_;
80}
81
Jeff Thompson0050abe2013-09-17 12:50:25 -070082void
83Data::wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070084{
85 unsigned int signedPortionBeginOffset, signedPortionEndOffset;
86 wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
87
88 wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
89}
90
Jeff Thompson0050abe2013-09-17 12:50:25 -070091void
92Data::onChanged()
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070093{
94 wireEncoding_ = SignedBlob();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070095}
96
97}