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 |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame^] | 7 | #define NDN_DATA_HPP |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include "name.hpp" |
| 10 | #include "publisher-public-key-digest.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 | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 87 | ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode(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 | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 91 | ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode() const |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 92 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 93 | return wireEncode(*WireFormat::getDefaultWireFormat()); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 94 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 95 | void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 99 | void wireDecode(const unsigned char *input, unsigned int inputLength) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 100 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 101 | wireDecode(input, inputLength, *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 102 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 103 | void wireDecode(const std::vector<unsigned char> &input, WireFormat &wireFormat) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 104 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 105 | wireDecode(&input[0], input.size(), wireFormat); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 106 | } |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 107 | void wireDecode(const std::vector<unsigned char> &input) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 108 | { |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 109 | wireDecode(&input[0], input.size()); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 |