blob: 6b2f570f06ff2c3fa3464c1d75865664d09f14d7 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson5cae5e52013-07-10 19:41:20 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson5cae5e52013-07-10 19:41:20 -07005 * See COPYING for copyright and distribution information.
6 */
7
Jeff Thompson25b4e612013-10-10 16:03:24 -07008#include <ndn-cpp/common.hpp>
9#include <ndn-cpp/data.hpp>
10#include <ndn-cpp/sha256-with-rsa-signature.hpp>
11#include "c/data.h"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070012
13using namespace std;
14
15namespace ndn {
16
Jeff Thompson20af0732013-09-12 17:01:45 -070017Signature::~Signature()
Jeff Thompson5cae5e52013-07-10 19:41:20 -070018{
Jeff Thompson20af0732013-09-12 17:01:45 -070019}
Jeff Thompsonf4585af2013-09-11 14:56:59 -070020
Jeff Thompson0050abe2013-09-17 12:50:25 -070021void
22MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070023{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070024 metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
25 metaInfoStruct.type = type_;
26 metaInfoStruct.freshnessSeconds = freshnessSeconds_;
Jeff Thompson145e2252013-09-12 12:51:35 -070027 finalBlockID_.get(metaInfoStruct.finalBlockID);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070028}
29
Jeff Thompson0050abe2013-09-17 12:50:25 -070030void
31MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070032{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070033 timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
34 type_ = metaInfoStruct.type;
35 freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
Jeff Thompson93034532013-10-08 11:52:43 -070036 finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value));
Jeff Thompson5cae5e52013-07-10 19:41:20 -070037}
38
Jeff Thompson20af0732013-09-12 17:01:45 -070039Data::Data()
40: signature_(new Sha256WithRsaSignature())
41{
42}
43
44Data::Data(const Name& name)
45: name_(name), signature_(new Sha256WithRsaSignature())
46{
47}
48
Jeff Thompson0050abe2013-09-17 12:50:25 -070049void
50Data::get(struct ndn_Data& dataStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070051{
Jeff Thompson20af0732013-09-12 17:01:45 -070052 signature_->get(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070053 name_.get(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070054 metaInfo_.get(dataStruct.metaInfo);
Jeff Thompson93034532013-10-08 11:52:43 -070055 content_.get(dataStruct.content);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070056}
57
Jeff Thompson0050abe2013-09-17 12:50:25 -070058void
59Data::set(const struct ndn_Data& dataStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070060{
Jeff Thompson20af0732013-09-12 17:01:45 -070061 signature_->set(dataStruct.signature);
Jeff Thompson56ec9e22013-08-02 11:34:07 -070062 name_.set(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070063 metaInfo_.set(dataStruct.metaInfo);
Jeff Thompson93034532013-10-08 11:52:43 -070064 content_ = Blob(dataStruct.content);
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070065
66 onChanged();
67}
68
Jeff Thompson0050abe2013-09-17 12:50:25 -070069SignedBlob
70Data::wireEncode(WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070071{
Jeff Thompson97223af2013-09-24 17:01:27 -070072 size_t signedPortionBeginOffset, signedPortionEndOffset;
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070073 Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
74
75 wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);
76 return wireEncoding_;
77}
78
Jeff Thompson0050abe2013-09-17 12:50:25 -070079void
Jeff Thompson97223af2013-09-24 17:01:27 -070080Data::wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat)
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070081{
Jeff Thompson97223af2013-09-24 17:01:27 -070082 size_t signedPortionBeginOffset, signedPortionEndOffset;
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070083 wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset);
84
85 wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset);
86}
87
Jeff Thompson0050abe2013-09-17 12:50:25 -070088void
89Data::onChanged()
Jeff Thompsonb7aefa002013-09-16 18:22:00 -070090{
91 wireEncoding_ = SignedBlob();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070092}
93
94}