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. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 57 | * @param self A pointer to the ndn_SignedInfo struct. |
| 58 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator. |
| 59 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 60 | */ |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 61 | static inline void ndn_SignedInfo_init |
| 62 | (struct ndn_SignedInfo *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 63 | ndn_PublisherPublicKeyDigest_init(&self->publisherPublicKeyDigest); |
| 64 | self->type = ndn_ContentType_DATA; |
| 65 | self->freshnessSeconds = -1; |
| 66 | self->finalBlockID = 0; |
| 67 | self->finalBlockIDLength = 0; |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 68 | ndn_KeyLocator_init(&self->keyLocator, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 71 | struct ndn_Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 72 | struct ndn_Signature signature; |
| 73 | struct ndn_Name name; |
| 74 | struct ndn_SignedInfo signedInfo; |
| 75 | unsigned char *content; /**< pointer to the content */ |
| 76 | unsigned int contentLength; /**< length of content */ |
| 77 | }; |
| 78 | |
| 79 | /** |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 80 | * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents, |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | * and defaults for all the values. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 82 | * @param self A pointer to the ndn_Data struct. |
| 83 | * @param nameComponents The pre-allocated array of ndn_NameComponent. |
| 84 | * @param maxNameComponents The number of elements in the allocated nameComponents array. |
| 85 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the signedInfo.keyLocator. |
| 86 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 87 | */ |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 88 | static inline void ndn_Data_init |
| 89 | (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, unsigned int maxNameComponents, |
| 90 | struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 91 | { |
| 92 | ndn_Signature_init(&self->signature); |
| 93 | ndn_Name_init(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 94 | ndn_SignedInfo_init(&self->signedInfo, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 95 | self->content = 0; |
| 96 | self->contentLength = 0; |
| 97 | } |
| 98 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 99 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 100 | } |
| 101 | #endif |
| 102 | |
| 103 | #endif |