blob: 61dd7509fc63cdba573dab5d22b6cf9ec4466544 [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 Thompson145e2252013-09-12 12:51:35 -070065 struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070066};
67
68/**
Jeff Thompsonfec716d2013-09-11 13:54:36 -070069 * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
70 * @param self A pointer to the ndn_MetaInfo struct.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070071 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070072static inline void ndn_MetaInfo_initialize
Jeff Thompsonf4585af2013-09-11 14:56:59 -070073 (struct ndn_MetaInfo *self) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070074 self->type = ndn_ContentType_DATA;
75 self->freshnessSeconds = -1;
Jeff Thompson145e2252013-09-12 12:51:35 -070076 ndn_NameComponent_initialize(&self->finalBlockID, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070077}
78
Jeff Thompson56ec9e22013-08-02 11:34:07 -070079struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070080 struct ndn_Signature signature;
81 struct ndn_Name name;
Jeff Thompsonfec716d2013-09-11 13:54:36 -070082 struct ndn_MetaInfo metaInfo;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070083 unsigned char *content; /**< pointer to the content */
84 unsigned int contentLength; /**< length of content */
85};
86
87/**
Jeff Thompson7329a132013-08-16 15:57:37 -070088 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070089 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070090 * @param self A pointer to the ndn_Data struct.
91 * @param nameComponents The pre-allocated array of ndn_NameComponent.
92 * @param maxNameComponents The number of elements in the allocated nameComponents array.
Jeff Thompsonf4585af2013-09-11 14:56:59 -070093 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
Jeff Thompson7329a132013-08-16 15:57:37 -070094 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070095 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070096static inline void ndn_Data_initialize
Jeff Thompson7329a132013-08-16 15:57:37 -070097 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
98 struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070099{
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700100 ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700101 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700102 ndn_MetaInfo_initialize(&self->metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700103 self->content = 0;
104 self->contentLength = 0;
105}
106
Jeff Thompsona0d18c92013-08-06 13:55:32 -0700107#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700108}
109#endif
110
111#endif