Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #ifndef NDN_CONTENTOBJECT_H |
| 7 | #define NDN_CONTENTOBJECT_H |
| 8 | |
| 9 | #include "Name.h" |
| 10 | #include "PublisherPublicKeyDigest.h" |
| 11 | #include "Key.h" |
| 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | struct ndn_Signature { |
| 18 | unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none. |
| 19 | * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */ |
| 20 | unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */ |
| 21 | unsigned char *witness; /**< pointer to pre-allocated buffer. 0 for none. */ |
| 22 | unsigned int witnessLength; /**< length of witness. 0 for none */ |
| 23 | unsigned char *signature; |
| 24 | unsigned int signatureLength; |
| 25 | }; |
| 26 | |
| 27 | static inline void ndn_Signature_init(struct ndn_Signature *self) { |
| 28 | self->digestAlgorithm = 0; |
| 29 | self->digestAlgorithmLength = 0; |
| 30 | self->witness = 0; |
| 31 | self->witnessLength = 0; |
| 32 | self->signature = 0; |
| 33 | self->signatureLength = 0; |
| 34 | } |
| 35 | |
| 36 | enum { |
| 37 | ndn_ContentType_DATA = 0, |
| 38 | ndn_ContentType_ENCR = 1, |
| 39 | ndn_ContentType_GONE = 2, |
| 40 | ndn_ContentType_KEY = 3, |
| 41 | ndn_ContentType_LINK = 4, |
| 42 | ndn_ContentType_NACK = 5 |
| 43 | }; |
| 44 | |
| 45 | struct ndn_SignedInfo { |
| 46 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
| 47 | // TODO: Implement timestamp |
| 48 | int type; /**< default is ndn_ContentType_DATA. -1 for none */ |
| 49 | int freshnessSeconds; /**< -1 for none */ |
| 50 | unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */ |
| 51 | unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */ |
| 52 | struct ndn_KeyLocator keyLocator; |
| 53 | }; |
| 54 | |
| 55 | /** |
| 56 | * Initialize the ndn_SignedInfo struct with values for none and the type to the default ndn_ContentType_DATA. |
| 57 | * @param self pointer to the ndn_SignedInfo struct. |
| 58 | */ |
| 59 | static inline void ndn_SignedInfo_init(struct ndn_SignedInfo *self) { |
| 60 | ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest); |
| 61 | self->type = ndn_ContentType_DATA; |
| 62 | self->freshnessSeconds = -1; |
| 63 | self->finalBlockID = 0; |
| 64 | self->finalBlockIDLength = 0; |
| 65 | ndn_KeyLocator_init(&self->keyLocator); |
| 66 | } |
| 67 | |
| 68 | struct ndn_ContentObject { |
| 69 | struct ndn_Signature signature; |
| 70 | struct ndn_Name name; |
| 71 | struct ndn_SignedInfo signedInfo; |
| 72 | unsigned char *content; /**< pointer to the content */ |
| 73 | unsigned int contentLength; /**< length of content */ |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * Initialize an ndn_ContentObject struct with the pre-allocated nameComponents, |
| 78 | * and defaults for all the values. |
| 79 | * @param self pointer to the ndn_ContentObject struct |
| 80 | * @param nameComponents the pre-allocated array of ndn_NameComponent |
| 81 | * @param maxNameComponents the number of elements in the allocated nameComponents array |
| 82 | */ |
| 83 | static inline void ndn_ContentObject_init(struct ndn_ContentObject *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents) |
| 84 | { |
| 85 | ndn_Signature_init(&self->signature); |
| 86 | ndn_Name_init(&self->name, nameComponents, maxNameComponents); |
| 87 | ndn_SignedInfo_init(&self->signedInfo); |
| 88 | self->content = 0; |
| 89 | self->contentLength = 0; |
| 90 | } |
| 91 | |
| 92 | #ifdef __cplusplus |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #endif |