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 | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 34 | finalBlockID_ = Name::Component(Blob(metaInfoStruct.finalBlockID.value, metaInfoStruct.finalBlockID.valueLength)); |
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 | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 53 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 54 | dataStruct.contentLength = content_.size(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 55 | if (content_.size() > 0) |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 56 | dataStruct.content = (unsigned char*)content_.buf(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 57 | else |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 58 | dataStruct.content = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 61 | void |
| 62 | Data::set(const struct ndn_Data& dataStruct) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 63 | { |
Jeff Thompson | 20af073 | 2013-09-12 17:01:45 -0700 | [diff] [blame] | 64 | signature_->set(dataStruct.signature); |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 65 | name_.set(dataStruct.name); |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 66 | metaInfo_.set(dataStruct.metaInfo); |
Jeff Thompson | 0899c0f | 2013-09-12 12:15:31 -0700 | [diff] [blame] | 67 | content_ = Blob(dataStruct.content, dataStruct.contentLength); |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 68 | |
| 69 | onChanged(); |
| 70 | } |
| 71 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 72 | SignedBlob |
| 73 | Data::wireEncode(WireFormat& wireFormat) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 74 | { |
| 75 | unsigned int signedPortionBeginOffset, signedPortionEndOffset; |
| 76 | Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset); |
| 77 | |
| 78 | wireEncoding_ = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset); |
| 79 | return wireEncoding_; |
| 80 | } |
| 81 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 82 | void |
| 83 | Data::wireDecode(const unsigned char* input, unsigned int inputLength, WireFormat& wireFormat) |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 84 | { |
| 85 | unsigned int signedPortionBeginOffset, signedPortionEndOffset; |
| 86 | wireFormat.decodeData(*this, input, inputLength, &signedPortionBeginOffset, &signedPortionEndOffset); |
| 87 | |
| 88 | wireEncoding_ = SignedBlob(input, inputLength, signedPortionBeginOffset, signedPortionEndOffset); |
| 89 | } |
| 90 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 91 | void |
| 92 | Data::onChanged() |
Jeff Thompson | b7aefa00 | 2013-09-16 18:22:00 -0700 | [diff] [blame] | 93 | { |
| 94 | wireEncoding_ = SignedBlob(); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | } |