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) |
| 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 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 | { |
| 39 | setVector(digestAlgorithm_, signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength); |
| 40 | setVector(witness_, signatureStruct.witness, signatureStruct.witnessLength); |
| 41 | setVector(signature_, 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 | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 51 | |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 52 | metaInfoStruct.finalBlockIDLength = finalBlockID_.size(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 53 | if (finalBlockID_.size() > 0) |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 54 | metaInfoStruct.finalBlockID = (unsigned char *)&finalBlockID_[0]; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 55 | else |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 56 | metaInfoStruct.finalBlockID = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 59 | void MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 60 | { |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 61 | timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds; |
| 62 | type_ = metaInfoStruct.type; |
| 63 | freshnessSeconds_ = metaInfoStruct.freshnessSeconds; |
| 64 | setVector(finalBlockID_, metaInfoStruct.finalBlockID, metaInfoStruct.finalBlockIDLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 67 | void Data::get(struct ndn_Data& dataStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 68 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 69 | signature_.get(dataStruct.signature); |
| 70 | name_.get(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 71 | metaInfo_.get(dataStruct.metaInfo); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 72 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 73 | dataStruct.contentLength = content_.size(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 74 | if (content_.size() > 0) |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 75 | dataStruct.content = (unsigned char *)&content_[0]; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 76 | else |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 77 | dataStruct.content = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 80 | void Data::set(const struct ndn_Data& dataStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 82 | signature_.set(dataStruct.signature); |
| 83 | name_.set(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 84 | metaInfo_.set(dataStruct.metaInfo); |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 85 | setVector(content_, dataStruct.content, dataStruct.contentLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } |