blob: 9338846fa7b8a49ed7aa7dd66e4c2324527e9b9c [file] [log] [blame]
/**
* @author: Jeff Thompson
* See COPYING for copyright and distribution information.
*/
#ifndef NDN_DATA_H
#define NDN_DATA_H
#include "Name.h"
#include "PublisherPublicKeyDigest.h"
#include "Key.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ndn_Signature {
unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none.
* If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */
unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */
unsigned char *witness; /**< pointer to pre-allocated buffer. 0 for none. */
unsigned int witnessLength; /**< length of witness. 0 for none */
unsigned char *signature;
unsigned int signatureLength;
};
static inline void ndn_Signature_init(struct ndn_Signature *self) {
self->digestAlgorithm = 0;
self->digestAlgorithmLength = 0;
self->witness = 0;
self->witnessLength = 0;
self->signature = 0;
self->signatureLength = 0;
}
enum {
ndn_ContentType_DATA = 0,
ndn_ContentType_ENCR = 1,
ndn_ContentType_GONE = 2,
ndn_ContentType_KEY = 3,
ndn_ContentType_LINK = 4,
ndn_ContentType_NACK = 5
};
struct ndn_SignedInfo {
struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */
int type; /**< default is ndn_ContentType_DATA. -1 for none */
int freshnessSeconds; /**< -1 for none */
unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */
unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */
struct ndn_KeyLocator keyLocator;
};
/**
* Initialize the ndn_SignedInfo struct with values for none and the type to the default ndn_ContentType_DATA.
* @param self pointer to the ndn_SignedInfo struct.
*/
static inline void ndn_SignedInfo_init(struct ndn_SignedInfo *self) {
ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest);
self->type = ndn_ContentType_DATA;
self->freshnessSeconds = -1;
self->finalBlockID = 0;
self->finalBlockIDLength = 0;
ndn_KeyLocator_init(&self->keyLocator);
}
struct ndn_Data {
struct ndn_Signature signature;
struct ndn_Name name;
struct ndn_SignedInfo signedInfo;
unsigned char *content; /**< pointer to the content */
unsigned int contentLength; /**< length of content */
};
/**
* Initialize an ndn_Data struct with the pre-allocated nameComponents,
* and defaults for all the values.
* @param self pointer to the ndn_Data struct
* @param nameComponents the pre-allocated array of ndn_NameComponent
* @param maxNameComponents the number of elements in the allocated nameComponents array
*/
static inline void ndn_Data_init(struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents)
{
ndn_Signature_init(&self->signature);
ndn_Name_init(&self->name, nameComponents, maxNameComponents);
ndn_SignedInfo_init(&self->signedInfo);
self->content = 0;
self->contentLength = 0;
}
#ifdef __cplusplus
}
#endif
#endif