Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "common.hpp" |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 8 | #include "data.hpp" |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 9 | #include "sha256-with-rsa-signature.hpp" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 10 | |
| 11 | using namespace std; |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 15 | Signature::~Signature() |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 16 | { |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 17 | } |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 18 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 19 | void |
| 20 | MetaInfo::get(struct ndn_MetaInfo& metaInfoStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 21 | { |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 22 | metaInfoStruct.timestampMilliseconds = timestampMilliseconds_; |
| 23 | metaInfoStruct.type = type_; |
| 24 | metaInfoStruct.freshnessSeconds = freshnessSeconds_; |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 25 | finalBlockID_.get(metaInfoStruct.finalBlockID); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 28 | void |
| 29 | MetaInfo::set(const struct ndn_MetaInfo& metaInfoStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 30 | { |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 31 | timestampMilliseconds_ = metaInfoStruct.timestampMilliseconds; |
| 32 | type_ = metaInfoStruct.type; |
| 33 | freshnessSeconds_ = metaInfoStruct.freshnessSeconds; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 34 | finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value)); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 37 | Data::Data() |
| 38 | : signature_(new Sha256WithRsaSignature()) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | Data::Data(const Name& name) |
| 43 | : name_(name), signature_(new Sha256WithRsaSignature()) |
| 44 | { |
| 45 | } |
| 46 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 47 | void |
| 48 | Data::get(struct ndn_Data& dataStruct) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 49 | { |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 50 | signature_->get(dataStruct.signature); |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 51 | name_.get(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 52 | metaInfo_.get(dataStruct.metaInfo); |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 53 | content_.get(dataStruct.content); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 56 | void |
| 57 | Data::set(const struct ndn_Data& dataStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 58 | { |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 59 | signature_->set(dataStruct.signature); |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 60 | name_.set(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 61 | metaInfo_.set(dataStruct.metaInfo); |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 62 | content_ = Blob(dataStruct.content); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 63 | |
| 64 | onChanged(); |
| 65 | } |
| 66 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 67 | SignedBlob |
| 68 | Data::wireEncode(WireFormat& wireFormat) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 69 | { |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 70 | size_t signedPortionBeginOffset, signedPortionEndOffset; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 71 | Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset); |
| 72 | |
| 73 | wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset); |
| 74 | return wireEncoding_; |
| 75 | } |
| 76 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 77 | void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 78 | Data::wireDecode(const uint8_t* input, size_t inputLength, WireFormat& wireFormat) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 79 | { |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 80 | size_t signedPortionBeginOffset, signedPortionEndOffset; |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 81 | wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset); |
| 82 | |
| 83 | wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset); |
| 84 | } |
| 85 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 86 | void |
| 87 | Data::onChanged() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 88 | { |
| 89 | wireEncoding_ = SignedBlob(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | } |