blob: 98a1d7698936a3c8dadf05a4798071b7e1b1a49e [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.
Jeff Thompson7329a132013-08-16 15:57:37 -070057 * @param self A pointer to the ndn_SignedInfo struct.
58 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
59 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070060 */
Jeff Thompson7329a132013-08-16 15:57:37 -070061static inline void ndn_SignedInfo_init
62 (struct ndn_SignedInfo *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070063 ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest);
64 self->type = ndn_ContentType_DATA;
65 self->freshnessSeconds = -1;
66 self->finalBlockID = 0;
67 self->finalBlockIDLength = 0;
Jeff Thompson7329a132013-08-16 15:57:37 -070068 ndn_KeyLocator_init(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070069}
70
Jeff Thompson56ec9e22013-08-02 11:34:07 -070071struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070072 struct ndn_Signature signature;
73 struct ndn_Name name;
74 struct ndn_SignedInfo signedInfo;
75 unsigned char *content; /**< pointer to the content */
76 unsigned int contentLength; /**< length of content */
77};
78
79/**
Jeff Thompson7329a132013-08-16 15:57:37 -070080 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070082 * @param self A pointer to the ndn_Data struct.
83 * @param nameComponents The pre-allocated array of ndn_NameComponent.
84 * @param maxNameComponents The number of elements in the allocated nameComponents array.
85 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signedInfo.keyLocator.
86 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070087 */
Jeff Thompson7329a132013-08-16 15:57:37 -070088static inline void ndn_Data_init
89 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
90 struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070091{
92 ndn_Signature_init(&self->signature);
93 ndn_Name_init(&self->name, nameComponents, maxNameComponents);
Jeff Thompson7329a132013-08-16 15:57:37 -070094 ndn_SignedInfo_init(&self->signedInfo, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070095 self->content = 0;
96 self->contentLength = 0;
97}
98
Jeff Thompsona0d18c92013-08-06 13:55:32 -070099#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700100}
101#endif
102
103#endif