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 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 6 | #ifndef NDN_DATA_H |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 7 | #define NDN_DATA_H |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include "name.h" |
| 10 | #include "publisher-public-key-digest.h" |
| 11 | #include "key.h" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 12 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 13 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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). */ |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 20 | unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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; |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 47 | double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */ |
| 48 | int type; /**< default is ndn_ContentType_DATA. -1 for none */ |
| 49 | int freshnessSeconds; /**< -1 for none */ |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 50 | unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 51 | unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 68 | struct ndn_Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 | /** |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 77 | * Initialize an ndn_Data struct with the pre-allocated nameComponents, |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 78 | * and defaults for all the values. |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 79 | * @param self pointer to the ndn_Data struct |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 80 | * @param nameComponents the pre-allocated array of ndn_NameComponent |
| 81 | * @param maxNameComponents the number of elements in the allocated nameComponents array |
| 82 | */ |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 83 | static inline void ndn_Data_init(struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 92 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 93 | } |
| 94 | #endif |
| 95 | |
| 96 | #endif |