blob: e085f79381c807c1a59a8356792d8b53a40cd197 [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson5cae5e52013-07-10 19:41:20 -07004 * See COPYING for copyright and distribution information.
5 */
6
Jeff Thompson56ec9e22013-08-02 11:34:07 -07007#ifndef NDN_DATA_H
Jeff Thompsona0d18c92013-08-06 13:55:32 -07008#define NDN_DATA_H
Jeff Thompson5cae5e52013-07-10 19:41:20 -07009
Jeff Thompson53412192013-08-06 13:35:50 -070010#include "name.h"
11#include "publisher-public-key-digest.h"
12#include "key.h"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070013
Jeff Thompsona0d18c92013-08-06 13:55:32 -070014#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070015extern "C" {
16#endif
17
Jeff Thompsonf4585af2013-09-11 14:56:59 -070018/**
19 * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
20 */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070021struct ndn_Signature {
Jeff Thompson93034532013-10-08 11:52:43 -070022 struct ndn_Blob digestAlgorithm; /**< A Blob whose value is a pointer to a pre-allocated buffer. 0 for none.
23 * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
24 struct ndn_Blob witness; /**< A Blob whose value is a pointer to pre-allocated buffer. 0 for none. */
25 struct ndn_Blob signature;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070026 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
27 struct ndn_KeyLocator keyLocator;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070028};
29
Jeff Thompsonf4585af2013-09-11 14:56:59 -070030/**
31 * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
32 * @param self A pointer to the ndn_MetaInfo struct.
33 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
34 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
35 */
Jeff Thompson97223af2013-09-24 17:01:27 -070036static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) {
Jeff Thompson93034532013-10-08 11:52:43 -070037 ndn_Blob_initialize(&self->digestAlgorithm, 0, 0);
38 ndn_Blob_initialize(&self->witness, 0, 0);
39 ndn_Blob_initialize(&self->signature, 0, 0);
Jeff Thompsonf4585af2013-09-11 14:56:59 -070040 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
41 ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070042}
43
Jeff Thompsond8776352013-08-16 18:09:30 -070044typedef enum {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070045 ndn_ContentType_DATA = 0,
46 ndn_ContentType_ENCR = 1,
47 ndn_ContentType_GONE = 2,
48 ndn_ContentType_KEY = 3,
49 ndn_ContentType_LINK = 4,
50 ndn_ContentType_NACK = 5
Jeff Thompsond8776352013-08-16 18:09:30 -070051} ndn_ContentType;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070052
Jeff Thompsonf4585af2013-09-11 14:56:59 -070053/**
54 * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
55 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070056struct ndn_MetaInfo {
Jeff Thompson210b92f2013-07-11 15:16:03 -070057 double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
Jeff Thompsond8776352013-08-16 18:09:30 -070058 ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
Jeff Thompson210b92f2013-07-11 15:16:03 -070059 int freshnessSeconds; /**< -1 for none */
Jeff Thompson145e2252013-09-12 12:51:35 -070060 struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070061};
62
63/**
Jeff Thompsonfec716d2013-09-11 13:54:36 -070064 * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
65 * @param self A pointer to the ndn_MetaInfo struct.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070066 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070067static inline void ndn_MetaInfo_initialize
Jeff Thompsonf4585af2013-09-11 14:56:59 -070068 (struct ndn_MetaInfo *self) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070069 self->type = ndn_ContentType_DATA;
70 self->freshnessSeconds = -1;
Jeff Thompson145e2252013-09-12 12:51:35 -070071 ndn_NameComponent_initialize(&self->finalBlockID, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070072}
73
Jeff Thompson56ec9e22013-08-02 11:34:07 -070074struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070075 struct ndn_Signature signature;
76 struct ndn_Name name;
Jeff Thompsonfec716d2013-09-11 13:54:36 -070077 struct ndn_MetaInfo metaInfo;
Jeff Thompson93034532013-10-08 11:52:43 -070078 struct ndn_Blob content; /**< A Blob with a pointer to the content. */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070079};
80
81/**
Jeff Thompson7329a132013-08-16 15:57:37 -070082 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070083 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070084 * @param self A pointer to the ndn_Data struct.
85 * @param nameComponents The pre-allocated array of ndn_NameComponent.
86 * @param maxNameComponents The number of elements in the allocated nameComponents array.
Jeff Thompsonf4585af2013-09-11 14:56:59 -070087 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
Jeff Thompson7329a132013-08-16 15:57:37 -070088 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070089 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070090static inline void ndn_Data_initialize
Jeff Thompson97223af2013-09-24 17:01:27 -070091 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
92 struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070093{
Jeff Thompsonf4585af2013-09-11 14:56:59 -070094 ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
Jeff Thompsond1427fb2013-08-29 17:20:32 -070095 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompsonf4585af2013-09-11 14:56:59 -070096 ndn_MetaInfo_initialize(&self->metaInfo);
Jeff Thompson93034532013-10-08 11:52:43 -070097 ndn_Blob_initialize(&self->content, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070098}
99
Jeff Thompsona0d18c92013-08-06 13:55:32 -0700100#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700101}
102#endif
103
104#endif