blob: 0b0dd3e57fe527f5582cf9e480c711e435f47bff [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
Jeff Thompson56ec9e22013-08-02 11:34:07 -07006#ifndef NDN_DATA_HPP
7#define NDN_DATA_HPP
Jeff Thompson5cae5e52013-07-10 19:41:20 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "name.hpp"
10#include "publisher-public-key-digest.hpp"
11#include "key.hpp"
Jeff Thompson56ec9e22013-08-02 11:34:07 -070012#include "c/data.h"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070013
14namespace ndn {
15
16class Signature {
17public:
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
37private:
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
43class SignedInfo {
44public:
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 Thompson210b92f2013-07-11 15:16:03 -070066 double getTimestampMilliseconds() const { return timestampMilliseconds_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070067
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
76private:
77 PublisherPublicKeyDigest publisherPublicKeyDigest_;
Jeff Thompson210b92f2013-07-11 15:16:03 -070078 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 Thompson5cae5e52013-07-10 19:41:20 -070082 KeyLocator keyLocator_;
83};
84
Jeff Thompson56ec9e22013-08-02 11:34:07 -070085class Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070086public:
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070087 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode(WireFormat &wireFormat) const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070088 {
Jeff Thompson56ec9e22013-08-02 11:34:07 -070089 return wireFormat.encodeData(*this);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070090 }
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070091 ptr_lib::shared_ptr<std::vector<unsigned char> > wireEncode() const
Jeff Thompson5cae5e52013-07-10 19:41:20 -070092 {
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070093 return wireEncode(*WireFormat::getDefaultWireFormat());
Jeff Thompson5cae5e52013-07-10 19:41:20 -070094 }
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070095 void wireDecode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070096 {
Jeff Thompson56ec9e22013-08-02 11:34:07 -070097 wireFormat.decodeData(*this, input, inputLength);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070098 }
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070099 void wireDecode(const unsigned char *input, unsigned int inputLength)
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700100 {
Jeff Thompson67e9e0a2013-08-02 19:16:19 -0700101 wireDecode(input, inputLength, *WireFormat::getDefaultWireFormat());
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700102 }
Jeff Thompson67e9e0a2013-08-02 19:16:19 -0700103 void wireDecode(const std::vector<unsigned char> &input, WireFormat &wireFormat)
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700104 {
Jeff Thompson67e9e0a2013-08-02 19:16:19 -0700105 wireDecode(&input[0], input.size(), wireFormat);
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700106 }
Jeff Thompson67e9e0a2013-08-02 19:16:19 -0700107 void wireDecode(const std::vector<unsigned char> &input)
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700108 {
Jeff Thompson67e9e0a2013-08-02 19:16:19 -0700109 wireDecode(&input[0], input.size());
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700110 }
111
112 /**
Jeff Thompson56ec9e22013-08-02 11:34:07 -0700113 * 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 Thompson5cae5e52013-07-10 19:41:20 -0700116 */
Jeff Thompson56ec9e22013-08-02 11:34:07 -0700117 void get(struct ndn_Data &dataStruct) const;
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700118
119 /**
Jeff Thompson56ec9e22013-08-02 11:34:07 -0700120 * Clear this data object, and set the values by copying from the ndn_Data struct.
121 * @param dataStruct a C ndn_Data struct
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700122 */
Jeff Thompson56ec9e22013-08-02 11:34:07 -0700123 void set(const struct ndn_Data &dataStruct);
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700124
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
133private:
134 Signature signature_;
135 Name name_;
136 SignedInfo signedInfo_;
137 std::vector<unsigned char> content_;
138};
139
140}
141
142#endif