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 | |
| 13 | void Signature::get(struct ndn_Signature &signatureStruct) const |
| 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; |
| 32 | } |
| 33 | |
| 34 | void Signature::set(const struct ndn_Signature &signatureStruct) |
| 35 | { |
| 36 | setVector(digestAlgorithm_, signatureStruct.digestAlgorithm, signatureStruct.digestAlgorithmLength); |
| 37 | setVector(witness_, signatureStruct.witness, signatureStruct.witnessLength); |
| 38 | setVector(signature_, signatureStruct.signature, signatureStruct.signatureLength); |
| 39 | } |
| 40 | |
| 41 | void SignedInfo::get(struct ndn_SignedInfo &signedInfoStruct) const |
| 42 | { |
| 43 | publisherPublicKeyDigest_.get(signedInfoStruct.publisherPublicKeyDigest); |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 44 | signedInfoStruct.timestampMilliseconds = timestampMilliseconds_; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 45 | signedInfoStruct.type = type_; |
| 46 | signedInfoStruct.freshnessSeconds = freshnessSeconds_; |
| 47 | |
| 48 | signedInfoStruct.finalBlockIDLength = finalBlockID_.size(); |
| 49 | if (finalBlockID_.size() > 0) |
| 50 | signedInfoStruct.finalBlockID = (unsigned char *)&finalBlockID_[0]; |
| 51 | else |
| 52 | signedInfoStruct.finalBlockID = 0; |
| 53 | |
| 54 | keyLocator_.get(signedInfoStruct.keyLocator); |
| 55 | } |
| 56 | |
| 57 | void SignedInfo::set(const struct ndn_SignedInfo &signedInfoStruct) |
| 58 | { |
| 59 | publisherPublicKeyDigest_.set(signedInfoStruct.publisherPublicKeyDigest); |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 60 | timestampMilliseconds_ = signedInfoStruct.timestampMilliseconds; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 61 | type_ = signedInfoStruct.type; |
| 62 | freshnessSeconds_ = signedInfoStruct.freshnessSeconds; |
| 63 | setVector(finalBlockID_, signedInfoStruct.finalBlockID, signedInfoStruct.finalBlockIDLength); |
| 64 | keyLocator_.set(signedInfoStruct.keyLocator); |
| 65 | } |
| 66 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -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); |
| 71 | signedInfo_.get(dataStruct.signedInfo); |
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 | 56ec9e2 | 2013-08-02 11:34:07 -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); |
| 84 | signedInfo_.set(dataStruct.signedInfo); |
| 85 | setVector(content_, dataStruct.content, dataStruct.contentLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } |