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