/**
 * @author: Jeff Thompson
 * See COPYING for copyright and distribution information.
 */

#ifndef NDN_DATA_H
#define NDN_DATA_H

#include "name.h"
#include "publisher-public-key-digest.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_initialize(struct ndn_Signature *self) {
  self->digestAlgorithm = 0;
  self->digestAlgorithmLength = 0;
  self->witness = 0;
  self->witnessLength = 0;
  self->signature = 0;
  self->signatureLength = 0;
}

typedef 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
} ndn_ContentType;

struct ndn_SignedInfo {
  struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest;
  double timestampMilliseconds;    /**< milliseconds since 1/1/1970. -1 for none */
  ndn_ContentType 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 A pointer to the ndn_SignedInfo struct.
 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator.
 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
 */
static inline void ndn_SignedInfo_initialize
  (struct ndn_SignedInfo *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) {
  ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest);
  self->type = ndn_ContentType_DATA;
  self->freshnessSeconds = -1;
  self->finalBlockID = 0;
  self->finalBlockIDLength = 0;
  ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents);
}

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 keyNameComponents,
 * and defaults for all the values.
 * @param self A 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.
 * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signedInfo.keyLocator.
 * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array.
 */
static inline void ndn_Data_initialize
  (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents, 
   struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) 
{
  ndn_Signature_initialize(&self->signature);
  ndn_Name_initialize(&self->name, nameComponents, maxNameComponents);
  ndn_SignedInfo_initialize(&self->signedInfo, keyNameComponents, maxKeyNameComponents);
  self->content = 0;
  self->contentLength = 0;
}

#ifdef __cplusplus
}
#endif

#endif
