blob: 6bd5a8020627c17223e5ee90581f31cfde9ba93c [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
6#ifndef NDN_CONTENTOBJECT_HPP
7#define NDN_CONTENTOBJECT_HPP
8
9#include "Name.hpp"
10#include "PublisherPublicKeyDigest.hpp"
11#include "Key.hpp"
12#include "c/ContentObject.h"
13
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
85class ContentObject {
86public:
87 void encode(std::vector<unsigned char> &output, WireFormat &wireFormat) const
88 {
89 wireFormat.encodeContentObject(*this, output);
90 }
91 void encode(std::vector<unsigned char> &output) const
92 {
93 encode(output, BinaryXMLWireFormat::instance());
94 }
95 void decode(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat)
96 {
97 wireFormat.decodeContentObject(*this, input, inputLength);
98 }
99 void decode(const unsigned char *input, unsigned int inputLength)
100 {
101 decode(input, inputLength, BinaryXMLWireFormat::instance());
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 /**
113 * Set the contentObjectStruct to point to the values in this interest, without copying any memory.
114 * WARNING: The resulting pointers in contentObjectStruct are invalid after a further use of this object which could reallocate memory.
115 * @param contentObjectStruct a C ndn_ContentObject struct where the name components array is already allocated.
116 */
117 void get(struct ndn_ContentObject &contentObjectStruct) const;
118
119 /**
120 * Clear this content object, and set the values by copying from the ndn_ContentObject struct.
121 * @param contentObjectStruct a C ndn_ContentObject struct
122 */
123 void set(const struct ndn_ContentObject &contentObjectStruct);
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
133private:
134 Signature signature_;
135 Name name_;
136 SignedInfo signedInfo_;
137 std::vector<unsigned char> content_;
138};
139
140}
141
142#endif