Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include "common.hpp" |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 7 | #include "data.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 13 | void Signature::get(struct ndn_Signature& signatureStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 14 | { |
| 15 | signatureStruct.digestAlgorithmLength = digestAlgorithm_.size(); |
| 16 | if (digestAlgorithm_.size() > 0) |
Jeff Thompson | 4545d71 | 2013-09-12 14:40:12 -0700 | [diff] [blame] | 17 | signatureStruct.digestAlgorithm = (unsigned char *)digestAlgorithm_.buf(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 18 | else |
| 19 | signatureStruct.digestAlgorithm = 0; |
| 20 | |
| 21 | signatureStruct.witnessLength = witness_.size(); |
| 22 | if (witness_.size() > 0) |
Jeff Thompson | 4545d71 | 2013-09-12 14:40:12 -0700 | [diff] [blame] | 23 | signatureStruct.witness = (unsigned char *)witness_.buf(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 24 | else |
| 25 | signatureStruct.witness = 0; |
| 26 | |
| 27 | signatureStruct.signatureLength = signature_.size(); |
| 28 | if (signature_.size() > 0) |
Jeff Thompson | 4545d71 | 2013-09-12 14:40:12 -0700 | [diff] [blame] | 29 | signatureStruct.signature = (unsigned char *)signature_.buf(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 30 | else |
| 31 | signatureStruct.signature = 0; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 32 | |
| 33 | publisherPublicKeyDigest_.get(signatureStruct.publisherPublicKeyDigest); |
| 34 | keyLocator_.get(signatureStruct.keyLocator); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 37 | void Signature::set(const struct ndn_Signature& signatureStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 38 | { |
Jeff Thompson | 4545d71 | 2013-09-12 14:40:12 -0700 | [diff] [blame] | 39 | digestAlgorithm_ = Blob(signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength); |
| 40 | witness_ = Blob(signatureStruct.witness, signatureStruct.witnessLength); |
| 41 | signature_ = Blob(signatureStruct.signature, signatureStruct.signatureLength); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 42 | publisherPublicKeyDigest_.set(signatureStruct.publisherPublicKeyDigest); |
| 43 | keyLocator_.set(signatureStruct.keyLocator); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 46 | void MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 47 | { |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 48 | metaInfoStruct.timestampMilliseconds = timestampMilliseconds_; |
| 49 | metaInfoStruct.type = type_; |
| 50 | metaInfoStruct.freshnessSeconds = freshnessSeconds_; |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 51 | finalBlockID_.get(metaInfoStruct.finalBlockID); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 54 | void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 55 | { |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 56 | timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds; |
| 57 | type_ = metaInfoStruct.type; |
| 58 | freshnessSeconds_ = metaInfoStruct.freshnessSeconds; |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 59 | finalBlockID_.setValue(Blob(metaInfoStruct.finalBlockID.value, metaInfoStruct.finalBlockID.valueLength)); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 62 | void Data::get(struct ndn_Data& dataStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 63 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 64 | signature_.get(dataStruct.signature); |
| 65 | name_.get(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 66 | metaInfo_.get(dataStruct.metaInfo); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 67 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 68 | dataStruct.contentLength = content_.size(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 69 | if (content_.size() > 0) |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 70 | dataStruct.content = (unsigned char*)content_.buf(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 71 | else |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 72 | dataStruct.content = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 75 | void Data::set(const struct ndn_Data& dataStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 76 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 77 | signature_.set(dataStruct.signature); |
| 78 | name_.set(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 79 | metaInfo_.set(dataStruct.metaInfo); |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 80 | content_ = Blob(dataStruct.content, dataStruct.contentLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } |