blob: 98ffde0480c21434f3774b17d4a095462a7f2c9b [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 Thompson93034532013-10-08 11:52:43 -070034 finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value));
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 Thompson93034532013-10-08 11:52:43 -070053 content_.get(dataStruct.content);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070054}
55
Jeff Thompson0050abe2013-09-17 12:50:25 -070056void
57Data::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 Thompson93034532013-10-08 11:52:43 -070062 content_ = Blob(dataStruct.content);
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070063
64 onChanged();
65}
66
Jeff Thompson0050abe2013-09-17 12:50:25 -070067SignedBlob
68Data::wireEncode(WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070069{
Jeff Thompson97223af2013-09-24 17:01:27 -070070 size_t signedPortionBeginOffset, signedPortionEndOffset;
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070071 Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
72
73 wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
74 return wireEncoding_;
75}
76
Jeff Thompson0050abe2013-09-17 12:50:25 -070077void
Jeff Thompson97223af2013-09-24 17:01:27 -070078Data::wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070079{
Jeff Thompson97223af2013-09-24 17:01:27 -070080 size_t signedPortionBeginOffset, signedPortionEndOffset;
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070081 wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
82
83 wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
84}
85
Jeff Thompson0050abe2013-09-17 12:50:25 -070086void
87Data::onChanged()
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070088{
89 wireEncoding_ = SignedBlob();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070090}
91
92}