blob: ffaa83c5af1164a611c4cfd1488dbb25f78134c0 [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
Yingdi Yu61ec2722014-01-20 14:22:32 -080010#include <ndn-cpp-dev/c/data-types.h>
Jeff Thompson53412192013-08-06 13:35:50 -070011#include "name.h"
12#include "publisher-public-key-digest.h"
Jeff Thompson98ec85a2013-12-17 11:57:56 -080013#include "key-locator.h"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070014
Jeff Thompsona0d18c92013-08-06 13:55:32 -070015#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070016extern "C" {
17#endif
18
Jeff Thompsonf4585af2013-09-11 14:56:59 -070019/**
20 * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet.
21 */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070022struct ndn_Signature {
Jeff Thompson93034532013-10-08 11:52:43 -070023 struct ndn_Blob digestAlgorithm; /**< A Blob whose value is a pointer to a pre-allocated buffer. 0 for none.
24 * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
25 struct ndn_Blob witness; /**< A Blob whose value is a pointer to pre-allocated buffer. 0 for none. */
26 struct ndn_Blob signature;
Jeff Thompsonf4585af2013-09-11 14:56:59 -070027 struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
28 struct ndn_KeyLocator keyLocator;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070029};
30
Jeff Thompsonf4585af2013-09-11 14:56:59 -070031/**
32 * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm.
33 * @param self A pointer to the ndn_MetaInfo struct.
34 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
35 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
36 */
Jeff Thompson97223af2013-09-24 17:01:27 -070037static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) {
Jeff Thompson93034532013-10-08 11:52:43 -070038 ndn_Blob_initialize(&self->digestAlgorithm, 0, 0);
39 ndn_Blob_initialize(&self->witness, 0, 0);
40 ndn_Blob_initialize(&self->signature, 0, 0);
Jeff Thompsonf4585af2013-09-11 14:56:59 -070041 ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
42 ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070043}
44
Jeff Thompsonf4585af2013-09-11 14:56:59 -070045/**
46 * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet.
47 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070048struct ndn_MetaInfo {
Jeff Thompson9a8e82f2013-10-17 14:13:43 -070049 ndn_MillisecondsSince1970 timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
50 ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */
51 int freshnessSeconds; /**< -1 for none */
52 struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 0 for none */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070053};
54
55/**
Jeff Thompsonfec716d2013-09-11 13:54:36 -070056 * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA.
57 * @param self A pointer to the ndn_MetaInfo struct.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070058 */
Jeff Thompsonfec716d2013-09-11 13:54:36 -070059static inline void ndn_MetaInfo_initialize
Jeff Thompsonf4585af2013-09-11 14:56:59 -070060 (struct ndn_MetaInfo *self) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070061 self->type = ndn_ContentType_DATA;
62 self->freshnessSeconds = -1;
Jeff Thompson145e2252013-09-12 12:51:35 -070063 ndn_NameComponent_initialize(&self->finalBlockID, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070064}
65
Jeff Thompson56ec9e22013-08-02 11:34:07 -070066struct ndn_Data {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070067 struct ndn_Signature signature;
68 struct ndn_Name name;
Jeff Thompsonfec716d2013-09-11 13:54:36 -070069 struct ndn_MetaInfo metaInfo;
Jeff Thompson93034532013-10-08 11:52:43 -070070 struct ndn_Blob content; /**< A Blob with a pointer to the content. */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070071};
72
73/**
Jeff Thompson7329a132013-08-16 15:57:37 -070074 * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents,
Jeff Thompson5cae5e52013-07-10 19:41:20 -070075 * and defaults for all the values.
Jeff Thompson7329a132013-08-16 15:57:37 -070076 * @param self A pointer to the ndn_Data struct.
77 * @param nameComponents The pre-allocated array of ndn_NameComponent.
78 * @param maxNameComponents The number of elements in the allocated nameComponents array.
Jeff Thompsonf4585af2013-09-11 14:56:59 -070079 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator.
Jeff Thompson7329a132013-08-16 15:57:37 -070080 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
Jeff Thompson5cae5e52013-07-10 19:41:20 -070081 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070082static inline void ndn_Data_initialize
Jeff Thompson97223af2013-09-24 17:01:27 -070083 (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents,
84 struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070085{
Jeff Thompsonf4585af2013-09-11 14:56:59 -070086 ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents);
Jeff Thompsond1427fb2013-08-29 17:20:32 -070087 ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
Jeff Thompsonf4585af2013-09-11 14:56:59 -070088 ndn_MetaInfo_initialize(&self->metaInfo);
Jeff Thompson93034532013-10-08 11:52:43 -070089 ndn_Blob_initialize(&self->content, 0, 0);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070090}
91
Jeff Thompsona0d18c92013-08-06 13:55:32 -070092#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070093}
94#endif
95
96#endif