blob: 387d2910881a5aa456ad439c7c3b824b0038532f [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 Thompson5cae5e52013-07-10 19:41:20 -07008
9using namespace std;
10
11namespace ndn {
12
Jeff Thompson1656e6a2013-08-29 18:01:48 -070013void Signature::get(struct ndn_Signature& signatureStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070014{
15 signatureStruct.digestAlgorithmLength = digestAlgorithm_.size();
16 if (digestAlgorithm_.size() > 0)
17 signatureStruct.digestAlgorithm = (unsigned char *)&digestAlgorithm_[0];
18 else
19 signatureStruct.digestAlgorithm = 0;
20
21 signatureStruct.witnessLength = witness_.size();
22 if (witness_.size() > 0)
23 signatureStruct.witness = (unsigned char *)&witness_[0];
24 else
25 signatureStruct.witness = 0;
26
27 signatureStruct.signatureLength = signature_.size();
28 if (signature_.size() > 0)
29 signatureStruct.signature = (unsigned char *)&signature_[0];
30 else
31 signatureStruct.signature = 0;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070032
33 publisherPublicKeyDigest_.get(signatureStruct.publisherPublicKeyDigest);
34 keyLocator_.get(signatureStruct.keyLocator);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070035}
36
Jeff Thompson1656e6a2013-08-29 18:01:48 -070037void Signature::set(const struct ndn_Signature& signatureStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070038{
39 setVector(digestAlgorithm_, signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength);
40 setVector(witness_, signatureStruct.witness, signatureStruct.witnessLength);
41 setVector(signature_, signatureStruct.signature, signatureStruct.signatureLength);
Jeff Thompsonf4585af2013-09-11 14:56:59 -070042 publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest);
43 keyLocator_.set(signatureStruct.keyLocator);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070044}
45
Jeff Thompsonfec716d2013-09-11 13:54:36 -070046void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070047{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070048 metaInfoStruct.timestampMilliseconds = timestampMilliseconds_;
49 metaInfoStruct.type = type_;
50 metaInfoStruct.freshnessSeconds = freshnessSeconds_;
Jeff Thompson145e2252013-09-12 12:51:35 -070051 finalBlockID_.get(metaInfoStruct.finalBlockID);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070052}
53
Jeff Thompsonfec716d2013-09-11 13:54:36 -070054void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070055{
Jeff Thompsonfec716d2013-09-11 13:54:36 -070056 timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds;
57 type_ = metaInfoStruct.type;
58 freshnessSeconds_ = metaInfoStruct.freshnessSeconds;
Jeff Thompson145e2252013-09-12 12:51:35 -070059 finalBlockID_.setValue(Blob(metaInfoStruct.finalBlockID.value, metaInfoStruct.finalBlockID.valueLength));
Jeff Thompson5cae5e52013-07-10 19:41:20 -070060}
61
Jeff Thompson1656e6a2013-08-29 18:01:48 -070062void Data::get(struct ndn_Data& dataStruct) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070063{
Jeff Thompson56ec9e22013-08-02 11:34:07 -070064 signature_.get(dataStruct.signature);
65 name_.get(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070066 metaInfo_.get(dataStruct.metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070067
Jeff Thompson56ec9e22013-08-02 11:34:07 -070068 dataStruct.contentLength = content_.size();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070069 if (content_.size() > 0)
Jeff Thompson0899c0f2013-09-12 12:15:31 -070070 dataStruct.content = (unsigned char*)content_.buf();
Jeff Thompson5cae5e52013-07-10 19:41:20 -070071 else
Jeff Thompson56ec9e22013-08-02 11:34:07 -070072 dataStruct.content = 0;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070073}
74
Jeff Thompson1656e6a2013-08-29 18:01:48 -070075void Data::set(const struct ndn_Data& dataStruct)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070076{
Jeff Thompson56ec9e22013-08-02 11:34:07 -070077 signature_.set(dataStruct.signature);
78 name_.set(dataStruct.name);
Jeff Thompsonfec716d2013-09-11 13:54:36 -070079 metaInfo_.set(dataStruct.metaInfo);
Jeff Thompson0899c0f2013-09-12 12:15:31 -070080 content_ = Blob(dataStruct.content, dataStruct.contentLength);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081}
82
83}