Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 7 | #ifndef NDN_DATA_H |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 8 | #define NDN_DATA_H |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 10 | #include "name.h" |
| 11 | #include "publisher-public-key-digest.h" |
| 12 | #include "key.h" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 14 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 18 | /** |
| 19 | * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet. |
| 20 | */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 21 | struct ndn_Signature { |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 22 | uint8_t *digestAlgorithm; /**< pointer to pre-allocated buffer. 0 for none. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 23 | * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 24 | size_t digestAlgorithmLength; /**< length of digestAlgorithm. 0 for none */ |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 25 | uint8_t *witness; /**< pointer to pre-allocated buffer. 0 for none. */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 26 | size_t witnessLength; /**< length of witness. 0 for none */ |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 27 | uint8_t *signature; |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 28 | size_t signatureLength; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 29 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
| 30 | struct ndn_KeyLocator keyLocator; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm. |
| 35 | * @param self A pointer to the ndn_MetaInfo struct. |
| 36 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator. |
| 37 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
| 38 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 39 | static inline void ndn_Signature_initialize(struct ndn_Signature *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 40 | self->digestAlgorithm = 0; |
| 41 | self->digestAlgorithmLength = 0; |
| 42 | self->witness = 0; |
| 43 | self->witnessLength = 0; |
| 44 | self->signature = 0; |
| 45 | self->signatureLength = 0; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 46 | ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest); |
| 47 | ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 50 | typedef enum { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 51 | ndn_ContentType_DATA = 0, |
| 52 | ndn_ContentType_ENCR = 1, |
| 53 | ndn_ContentType_GONE = 2, |
| 54 | ndn_ContentType_KEY = 3, |
| 55 | ndn_ContentType_LINK = 4, |
| 56 | ndn_ContentType_NACK = 5 |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 57 | } ndn_ContentType; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 58 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 59 | /** |
| 60 | * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet. |
| 61 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 62 | struct ndn_MetaInfo { |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 63 | double timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */ |
Jeff Thompson | d877635 | 2013-08-16 18:09:30 -0700 | [diff] [blame] | 64 | ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */ |
Jeff Thompson | 210b92f | 2013-07-11 15:16:03 -0700 | [diff] [blame] | 65 | int freshnessSeconds; /**< -1 for none */ |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 66 | struct ndn_NameComponent finalBlockID; /**< has a pointer to a pre-allocated buffer. 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; |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 77 | ndn_NameComponent_initialize(&self->finalBlockID, 0, 0); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 80 | struct ndn_Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | struct ndn_Signature signature; |
| 82 | struct ndn_Name name; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 83 | struct ndn_MetaInfo metaInfo; |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 84 | uint8_t *content; /**< pointer to the content */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 85 | size_t contentLength; /**< length of content */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | /** |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 89 | * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents, |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 90 | * and defaults for all the values. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 91 | * @param self A pointer to the ndn_Data struct. |
| 92 | * @param nameComponents The pre-allocated array of ndn_NameComponent. |
| 93 | * @param maxNameComponents The number of elements in the allocated nameComponents array. |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 94 | * @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] | 95 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 96 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 97 | static inline void ndn_Data_initialize |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 98 | (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents, |
| 99 | struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 100 | { |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 101 | ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 102 | ndn_Name_initialize(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 103 | ndn_MetaInfo_initialize(&self->metaInfo); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 104 | self->content = 0; |
| 105 | self->contentLength = 0; |
| 106 | } |
| 107 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 108 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 109 | } |
| 110 | #endif |
| 111 | |
| 112 | #endif |