blob: 8dbdab6a84278cb99f12479ff9b14a462706726b [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include "common.hpp"
Jeff Thompson56ec9e22013-08-02 11:34:07 -07007#include "data.hpp"
Jeff Thompson20af0732013-09-12 17:01:45 -07008#include "sha256-with-rsa-signature.hpp"
Jeff Thompson5cae5e52013-07-10 19:41:20 -07009
10using namespace std;
11
12namespace ndn {
13
Jeff Thompson20af0732013-09-12 17:01:45 -070014Signature::~Signature()
Jeff Thompson5cae5e52013-07-10 19:41:20 -070015{
Jeff Thompson20af0732013-09-12 17:01:45 -070016}
Jeff Thompsonf4585af2013-09-11 14:56:59 -070017
Jeff Thompsonfec716d2013-09-11 13:54:36 -070018void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070019{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070020 metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
21 metaInfoStruct.type = type_;
22 metaInfoStruct.freshnessSeconds = freshnessSeconds_;
Jeff Thompson145e2252013-09-12 12:51:35 -070023 finalBlockID_.get(metaInfoStruct.finalBlockID);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070024}
25
Jeff Thompsonfec716d2013-09-11 13:54:36 -070026void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070027{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070028 timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
29 type_ = metaInfoStruct.type;
30 freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
Jeff Thompson145e2252013-09-12 12:51:35 -070031 finalBlockID_.setValue(Blob(metaInfoStruct.finalBlockID.value, metaInfoStruct.finalBlockID.valueLength));
Jeff Thompson5cae5e52013-07-10 19:41:20 -070032}
33
Jeff Thompson20af0732013-09-12 17:01:45 -070034Data::Data()
35: signature_(new Sha256WithRsaSignature())
36{
37}
38
39Data::Data(const Name& name)
40: name_(name), signature_(new Sha256WithRsaSignature())
41{
42}
43
Jeff Thompson1656e6a2013-08-29 18:01:48 -070044void Data::get(struct ndn_Data& dataStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070045{
Jeff Thompson20af0732013-09-12 17:01:45 -070046 signature_->get(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070047 name_.get(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070048 metaInfo_.get(dataStruct.metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070049
Jeff Thompson56ec9e22013-08-02 11:34:07 -070050 dataStruct.contentLength = content_.size();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070051 if (content_.size() > 0)
Jeff Thompson0899c0f2013-09-12 12:15:31 -070052 dataStruct.content = (unsigned char*)content_.buf();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070053 else
Jeff Thompson56ec9e22013-08-02 11:34:07 -070054 dataStruct.content = 0;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070055}
56
Jeff Thompson1656e6a2013-08-29 18:01:48 -070057void Data::set(const struct ndn_Data& dataStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070058{
Jeff Thompson20af0732013-09-12 17:01:45 -070059 signature_->set(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070060 name_.set(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070061 metaInfo_.set(dataStruct.metaInfo);
Jeff Thompson0899c0f2013-09-12 12:15:31 -070062 content_ = Blob(dataStruct.content, dataStruct.contentLength);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070063}
64
65}