blob: 0990d86ee47ea0855262cd8b639aa038c63df615 [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
Jeff Thompsonf4585af2013-09-11 14:56:59 -070017/**
18 * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
19 */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070020struct ndn_Signature {
21 unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
22 * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
Jeff Thompsona0d18c92013-08-06 13:55:32 -070023 unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070024 unsigned char *witness; /**< pointer to pre-allocated buffer. 0 for none. */
25 unsigned int witnessLength; /**< length of witness. 0 for none */
26 unsigned char *signature;
27 unsigned int signatureLength;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070028 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
29 struct ndn_KeyLocator keyLocator;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070030};
31
Jeff Thompsonf4585af2013-09-11 14:56:59 -070032/**
33 * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
34 * @param self A pointer to the ndn_MetaInfo struct.
35 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
36 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
37 */
38static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070039 self->digestAlgorithm = 0;
40 self->digestAlgorithmLength = 0;
41 self->witness = 0;
42 self->witnessLength = 0;
43 self->signature = 0;
44 self->signatureLength = 0;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070045 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
46 ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070047}
48
Jeff Thompsond8776352013-08-16 18:09:30 -070049typedef enum {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070050 ndn_ContentType_DATA = 0,
51 ndn_ContentType_ENCR = 1,
52 ndn_ContentType_GONE = 2,
53 ndn_ContentType_KEY = 3,
54 ndn_ContentType_LINK = 4,
55 ndn_ContentType_NACK = 5
Jeff Thompsond8776352013-08-16 18:09:30 -070056} ndn_ContentType;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070057
Jeff Thompsonf4585af2013-09-11 14:56:59 -070058/**
59 * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
60 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070061struct ndn_MetaInfo {
Jeff Thompson210b92f2013-07-11 15:16:03 -070062 double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
Jeff Thompsond8776352013-08-16 18:09:30 -070063 ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
Jeff Thompson210b92f2013-07-11 15:16:03 -070064 int freshnessSeconds; /**< -1 for none */
Jeff Thompsona0d18c92013-08-06 13:55:32 -070065 unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */
Jeff Thompson210b92f2013-07-11 15:16:03 -070066 unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070067};
68
69/**
Jeff Thompsonfec716d2013-09-11 13:54:36 -070070 * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
71 * @param self A pointer to the ndn_MetaInfo struct.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070072 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070073static inline void ndn_MetaInfo_initialize
Jeff Thompsonf4585af2013-09-11 14:56:59 -070074 (struct ndn_MetaInfo *self) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070075 self->type = ndn_ContentType_DATA;
76 self->freshnessSeconds = -1;
77 self->finalBlockID = 0;
78 self->finalBlockIDLength = 0;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070079}
80
Jeff Thompson56ec9e22013-08-02 11:34:07 -070081struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070082 struct ndn_Signature signature;
83 struct ndn_Name name;
Jeff Thompsonfec716d2013-09-11 13:54:36 -070084 struct ndn_MetaInfo metaInfo;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070085 unsigned char *content; /**< pointer to the content */
86 unsigned int contentLength; /**< length of content */
87};
88
89/**
Jeff Thompson7329a132013-08-16 15:57:37 -070090 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070091 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070092 * @param self A pointer to the ndn_Data struct.
93 * @param nameComponents The pre-allocated array of ndn_NameComponent.
94 * @param maxNameComponents The number of elements in the allocated nameComponents array.
Jeff Thompsonf4585af2013-09-11 14:56:59 -070095 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
Jeff Thompson7329a132013-08-16 15:57:37 -070096 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070097 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070098static inline void ndn_Data_initialize
Jeff Thompson7329a132013-08-16 15:57:37 -070099 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
100 struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700101{
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700102 ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700103 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700104 ndn_MetaInfo_initialize(&self->metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700105 self->content = 0;
106 self->contentLength = 0;
107}
108
Jeff Thompsona0d18c92013-08-06 13:55:32 -0700109#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700110}
111#endif
112
113#endif