blob: c8d97fc52efa57bce8d53bcf578ab4388473b301 [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_H
Jeff Thompsona0d18c92013-08-06 13:55:32 -07007#define NDN_DATA_H
Jeff Thompson5cae5e52013-07-10 19:41:20 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "name.h"
10#include "publisher-public-key-digest.h"
11#include "key.h"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070012
Jeff Thompsona0d18c92013-08-06 13:55:32 -070013#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070014extern "C" {
15#endif
16
17struct ndn_Signature {
18 unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
19 * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
Jeff Thompsona0d18c92013-08-06 13:55:32 -070020 unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070021 unsigned char *witness; /**< pointer to pre-allocated buffer. 0 for none. */
22 unsigned int witnessLength; /**< length of witness. 0 for none */
23 unsigned char *signature;
24 unsigned int signatureLength;
25};
26
27static inline void ndn_Signature_init(struct ndn_Signature *self) {
28 self->digestAlgorithm = 0;
29 self->digestAlgorithmLength = 0;
30 self->witness = 0;
31 self->witnessLength = 0;
32 self->signature = 0;
33 self->signatureLength = 0;
34}
35
36enum {
37 ndn_ContentType_DATA = 0,
38 ndn_ContentType_ENCR = 1,
39 ndn_ContentType_GONE = 2,
40 ndn_ContentType_KEY = 3,
41 ndn_ContentType_LINK = 4,
42 ndn_ContentType_NACK = 5
43};
44
45struct ndn_SignedInfo {
46 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
Jeff Thompson210b92f2013-07-11 15:16:03 -070047 double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
48 int type; /**< default is ndn_ContentType_DATA. -1 for none */
49 int freshnessSeconds; /**< -1 for none */
Jeff Thompsona0d18c92013-08-06 13:55:32 -070050 unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */
Jeff Thompson210b92f2013-07-11 15:16:03 -070051 unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070052 struct ndn_KeyLocator keyLocator;
53};
54
55/**
56 * Initialize the ndn_SignedInfo struct with values for none and the type to the default ndn_ContentType_DATA.
57 * @param self pointer to the ndn_SignedInfo struct.
58 */
59static inline void ndn_SignedInfo_init(struct ndn_SignedInfo *self) {
60 ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest);
61 self->type = ndn_ContentType_DATA;
62 self->freshnessSeconds = -1;
63 self->finalBlockID = 0;
64 self->finalBlockIDLength = 0;
65 ndn_KeyLocator_init(&self->keyLocator);
66}
67
Jeff Thompson56ec9e22013-08-02 11:34:07 -070068struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070069 struct ndn_Signature signature;
70 struct ndn_Name name;
71 struct ndn_SignedInfo signedInfo;
72 unsigned char *content; /**< pointer to the content */
73 unsigned int contentLength; /**< length of content */
74};
75
76/**
Jeff Thompson56ec9e22013-08-02 11:34:07 -070077 * Initialize an ndn_Data struct with the pre-allocated nameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070078 * and defaults for all the values.
Jeff Thompson56ec9e22013-08-02 11:34:07 -070079 * @param self pointer to the ndn_Data struct
Jeff Thompson5cae5e52013-07-10 19:41:20 -070080 * @param nameComponents the pre-allocated array of ndn_NameComponent
81 * @param maxNameComponents the number of elements in the allocated nameComponents array
82 */
Jeff Thompson56ec9e22013-08-02 11:34:07 -070083static inline void ndn_Data_init(struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070084{
85 ndn_Signature_init(&self->signature);
86 ndn_Name_init(&self->name, nameComponents, maxNameComponents);
87 ndn_SignedInfo_init(&self->signedInfo);
88 self->content = 0;
89 self->contentLength = 0;
90}
91
Jeff Thompsona0d18c92013-08-06 13:55:32 -070092#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070093}
94#endif
95
96#endif