blob: 81489f5c9b1124ac533e4ec231a7bdd6cb958b4c [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 Thompson10ad12a2013-09-24 16:19:11 -070022 uint8_t *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070023 * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
Jeff Thompsona0d18c92013-08-06 13:55:32 -070024 unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070025 uint8_t *witness; /**< pointer to pre-allocated buffer. 0 for none. */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070026 unsigned int witnessLength; /**< length of witness. 0 for none */
Jeff Thompson10ad12a2013-09-24 16:19:11 -070027 uint8_t *signature;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070028 unsigned int signatureLength;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070029 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
30 struct ndn_KeyLocator keyLocator;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070031};
32
Jeff Thompsonf4585af2013-09-11 14:56:59 -070033/**
34 * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
35 * @param self A pointer to the ndn_MetaInfo struct.
36 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
37 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
38 */
39static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070040 self->digestAlgorithm = 0;
41 self->digestAlgorithmLength = 0;
42 self->witness = 0;
43 self->witnessLength = 0;
44 self->signature = 0;
45 self->signatureLength = 0;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070046 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
47 ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070048}
49
Jeff Thompsond8776352013-08-16 18:09:30 -070050typedef enum {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070051 ndn_ContentType_DATA = 0,
52 ndn_ContentType_ENCR = 1,
53 ndn_ContentType_GONE = 2,
54 ndn_ContentType_KEY = 3,
55 ndn_ContentType_LINK = 4,
56 ndn_ContentType_NACK = 5
Jeff Thompsond8776352013-08-16 18:09:30 -070057} ndn_ContentType;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070058
Jeff Thompsonf4585af2013-09-11 14:56:59 -070059/**
60 * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
61 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070062struct ndn_MetaInfo {
Jeff Thompson210b92f2013-07-11 15:16:03 -070063 double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
Jeff Thompsond8776352013-08-16 18:09:30 -070064 ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
Jeff Thompson210b92f2013-07-11 15:16:03 -070065 int freshnessSeconds; /**< -1 for none */
Jeff Thompson145e2252013-09-12 12:51:35 -070066 struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 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;
Jeff Thompson145e2252013-09-12 12:51:35 -070077 ndn_NameComponent_initialize(&self->finalBlockID, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070078}
79
Jeff Thompson56ec9e22013-08-02 11:34:07 -070080struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081 struct ndn_Signature signature;
82 struct ndn_Name name;
Jeff Thompsonfec716d2013-09-11 13:54:36 -070083 struct ndn_MetaInfo metaInfo;
Jeff Thompson10ad12a2013-09-24 16:19:11 -070084 uint8_t *content; /**< pointer to the content */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070085 unsigned int contentLength; /**< length of content */
86};
87
88/**
Jeff Thompson7329a132013-08-16 15:57:37 -070089 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070090 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070091 * @param self A pointer to the ndn_Data struct.
92 * @param nameComponents The pre-allocated array of ndn_NameComponent.
93 * @param maxNameComponents The number of elements in the allocated nameComponents array.
Jeff Thompsonf4585af2013-09-11 14:56:59 -070094 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
Jeff Thompson7329a132013-08-16 15:57:37 -070095 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070096 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070097static inline void ndn_Data_initialize
Jeff Thompson7329a132013-08-16 15:57:37 -070098 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents,
99 struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700100{
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700101 ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
Jeff Thompsond1427fb2013-08-29 17:20:32 -0700102 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompsonf4585af2013-09-11 14:56:59 -0700103 ndn_MetaInfo_initialize(&self->metaInfo);
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700104 self->content = 0;
105 self->contentLength = 0;
106}
107
Jeff Thompsona0d18c92013-08-06 13:55:32 -0700108#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -0700109}
110#endif
111
112#endif