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 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 6 | #ifndef NDN_DATA_HPP |
| 7 | #define NDN_DATA_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
| 9 | #include "Name.hpp" |
| 10 | #include "PublisherPublicKeyDigest.hpp" |
| 11 | #include "Key.hpp" |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 12 | #include "c/data.h" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | class Signature { |
| 17 | public: |
| 18 | /** |
| 19 | * Set the signatureStruct to point to the values in this signature object, without copying any memory. |
| 20 | * WARNING: The resulting pointers in signatureStruct are invalid after a further use of this object which could reallocate memory. |
| 21 | * @param signatureStruct a C ndn_Signature struct where the name components array is already allocated. |
| 22 | */ |
| 23 | void get(struct ndn_Signature &signatureStruct) const; |
| 24 | |
| 25 | /** |
| 26 | * Clear this signature, and set the values by copying from the ndn_Signature struct. |
| 27 | * @param signatureStruct a C ndn_Signature struct |
| 28 | */ |
| 29 | void set(const struct ndn_Signature &signatureStruct); |
| 30 | |
| 31 | const std::vector<unsigned char> getDigestAlgorithm() const { return digestAlgorithm_; } |
| 32 | |
| 33 | const std::vector<unsigned char> getWitness() const { return witness_; } |
| 34 | |
| 35 | const std::vector<unsigned char> getSignature() const { return signature_; } |
| 36 | |
| 37 | private: |
| 38 | std::vector<unsigned char> digestAlgorithm_; /**< if empty, the default is 2.16.840.1.101.3.4.2.1 (sha-256) */ |
| 39 | std::vector<unsigned char> witness_; |
| 40 | std::vector<unsigned char> signature_; |
| 41 | }; |
| 42 | |
| 43 | class SignedInfo { |
| 44 | public: |
| 45 | SignedInfo() |
| 46 | { |
| 47 | type_ = ndn_ContentType_DATA; |
| 48 | freshnessSeconds_ = -1; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Set the signedInfoStruct to point to the values in this signed info object, without copying any memory. |
| 53 | * WARNING: The resulting pointers in signedInfoStruct are invalid after a further use of this object which could reallocate memory. |
| 54 | * @param signedInfoStruct a C ndn_SignedInfo struct where the name components array is already allocated. |
| 55 | */ |
| 56 | void get(struct ndn_SignedInfo &signedInfoStruct) const; |
| 57 | |
| 58 | /** |
| 59 | * Clear this signed info, and set the values by copying from the ndn_SignedInfo struct. |
| 60 | * @param signedInfoStruct a C ndn_SignedInfo struct |
| 61 | */ |
| 62 | void set(const struct ndn_SignedInfo &signedInfoStruct); |
| 63 | |
| 64 | const PublisherPublicKeyDigest &getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; } |
| 65 | |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 66 | double getTimestampMilliseconds() const { return timestampMilliseconds_; } |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 67 | |
| 68 | int getType() const { return type_; } |
| 69 | |
| 70 | int getFreshnessSeconds() const { return freshnessSeconds_; } |
| 71 | |
| 72 | const std::vector<unsigned char> getFinalBlockID() const { return finalBlockID_; } |
| 73 | |
| 74 | const KeyLocator &getKeyLocator() const { return keyLocator_; } |
| 75 | |
| 76 | private: |
| 77 | PublisherPublicKeyDigest publisherPublicKeyDigest_; |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 78 | double timestampMilliseconds_; /**< milliseconds since 1/1/1970. -1 for none */ |
| 79 | int type_; /**< default is ndn_ContentType_DATA. -1 for none */ |
| 80 | int freshnessSeconds_; /**< -1 for none */ |
| 81 | std::vector<unsigned char> finalBlockID_; /** size 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 82 | KeyLocator keyLocator_; |
| 83 | }; |
| 84 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 85 | class Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 86 | public: |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 87 | ptr_lib::shared_ptr<std::vector<unsigned char> > encode(WireFormat &wireFormat) const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 88 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 89 | return wireFormat.encodeData(*this); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 90 | } |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 91 | ptr_lib::shared_ptr<std::vector<unsigned char> > encode() const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 92 | { |
Jeff Thompson | b915b1d | 2013-07-31 10:53:13 -0700 | [diff] [blame] | 93 | return encode(BinaryXmlWireFormat::getInstance()); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 94 | } |
| 95 | void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) |
| 96 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 97 | wireFormat.decodeData(*this, input, inputLength); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 98 | } |
| 99 | void decode(const unsigned char *input, unsigned int inputLength) |
| 100 | { |
Jeff Thompson | b915b1d | 2013-07-31 10:53:13 -0700 | [diff] [blame] | 101 | decode(input, inputLength, BinaryXmlWireFormat::getInstance()); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 102 | } |
| 103 | void decode(const std::vector<unsigned char> &input, WireFormat &wireFormat) |
| 104 | { |
| 105 | decode(&input[0], input.size(), wireFormat); |
| 106 | } |
| 107 | void decode(const std::vector<unsigned char> &input) |
| 108 | { |
| 109 | decode(&input[0], input.size()); |
| 110 | } |
| 111 | |
| 112 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 113 | * Set the dataStruct to point to the values in this interest, without copying any memory. |
| 114 | * WARNING: The resulting pointers in dataStruct are invalid after a further use of this object which could reallocate memory. |
| 115 | * @param dataStruct a C ndn_Data struct where the name components array is already allocated. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 116 | */ |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 117 | void get(struct ndn_Data &dataStruct) const; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 120 | * Clear this data object, and set the values by copying from the ndn_Data struct. |
| 121 | * @param dataStruct a C ndn_Data struct |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 122 | */ |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame^] | 123 | void set(const struct ndn_Data &dataStruct); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 124 | |
| 125 | const Signature &getSignature() const { return signature_; } |
| 126 | |
| 127 | const Name &getName() const { return name_; } |
| 128 | |
| 129 | const SignedInfo &getSignedInfo() const { return signedInfo_; } |
| 130 | |
| 131 | const std::vector<unsigned char> getContent() const { return content_; } |
| 132 | |
| 133 | private: |
| 134 | Signature signature_; |
| 135 | Name name_; |
| 136 | SignedInfo signedInfo_; |
| 137 | std::vector<unsigned char> content_; |
| 138 | }; |
| 139 | |
| 140 | } |
| 141 | |
| 142 | #endif |