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 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 17 | /** |
| 18 | * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet. |
| 19 | */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 20 | struct ndn_Signature { |
| 21 | unsigned char *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none. |
| 22 | * 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] | 23 | unsigned int digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 24 | unsigned char *witness; /**< pointer to pre-allocated buffer. 0 for none. */ |
| 25 | unsigned int witnessLength; /**< length of witness. 0 for none */ |
| 26 | unsigned char *signature; |
| 27 | unsigned int signatureLength; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 28 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
| 29 | struct ndn_KeyLocator keyLocator; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm. |
| 34 | * @param self A pointer to the ndn_MetaInfo struct. |
| 35 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator. |
| 36 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
| 37 | */ |
| 38 | static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 39 | self->digestAlgorithm = 0; |
| 40 | self->digestAlgorithmLength = 0; |
| 41 | self->witness = 0; |
| 42 | self->witnessLength = 0; |
| 43 | self->signature = 0; |
| 44 | self->signatureLength = 0; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 45 | ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest); |
| 46 | ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 49 | typedef enum { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 50 | ndn_ContentType_DATA = 0, |
| 51 | ndn_ContentType_ENCR = 1, |
| 52 | ndn_ContentType_GONE = 2, |
| 53 | ndn_ContentType_KEY = 3, |
| 54 | ndn_ContentType_LINK = 4, |
| 55 | ndn_ContentType_NACK = 5 |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 56 | } ndn_ContentType; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 57 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 58 | /** |
| 59 | * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet. |
| 60 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 61 | struct ndn_MetaInfo { |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 62 | double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */ |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 63 | ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 64 | int freshnessSeconds; /**< -1 for none */ |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 65 | unsigned char *finalBlockID; /**< pointer to pre-allocated buffer. 0 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 66 | unsigned int finalBlockIDLength; /**< length of finalBlockID. 0 for none */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /** |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 70 | * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA. |
| 71 | * @param self A pointer to the ndn_MetaInfo struct. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 72 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 73 | static inline void ndn_MetaInfo_initialize |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 74 | (struct ndn_MetaInfo *self) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 75 | self->type = ndn_ContentType_DATA; |
| 76 | self->freshnessSeconds = -1; |
| 77 | self->finalBlockID = 0; |
| 78 | self->finalBlockIDLength = 0; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 81 | struct ndn_Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 82 | struct ndn_Signature signature; |
| 83 | struct ndn_Name name; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 84 | struct ndn_MetaInfo metaInfo; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 85 | unsigned char *content; /**< pointer to the content */ |
| 86 | unsigned int contentLength; /**< length of content */ |
| 87 | }; |
| 88 | |
| 89 | /** |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 90 | * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents, |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 91 | * and defaults for all the values. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 92 | * @param self A pointer to the ndn_Data struct. |
| 93 | * @param nameComponents The pre-allocated array of ndn_NameComponent. |
| 94 | * @param maxNameComponents The number of elements in the allocated nameComponents array. |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 95 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signature.keyLocator. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 96 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 97 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 98 | static inline void ndn_Data_initialize |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 99 | (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents, |
| 100 | struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 101 | { |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 102 | ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 103 | ndn_Name_initialize(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 104 | ndn_MetaInfo_initialize(&self->metaInfo); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 105 | self->content = 0; |
| 106 | self->contentLength = 0; |
| 107 | } |
| 108 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 109 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 110 | } |
| 111 | #endif |
| 112 | |
| 113 | #endif |