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 | |
Yingdi Yu | 61ec272 | 2014-01-20 14:22:32 -0800 | [diff] [blame] | 10 | #include <ndn-cpp-dev/c/data-types.h> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 11 | #include "name.h" |
| 12 | #include "publisher-public-key-digest.h" |
Jeff Thompson | 98ec85a | 2013-12-17 11:57:56 -0800 | [diff] [blame] | 13 | #include "key-locator.h" |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 14 | |
Jeff Thompson | a0d18c9 | 2013-08-06 13:55:32 -0700 | [diff] [blame] | 15 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 16 | extern "C" { |
| 17 | #endif |
| 18 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 19 | /** |
| 20 | * An ndn_Signature struct holds the signature bits and other info representing the signature in a data packet. |
| 21 | */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 22 | struct ndn_Signature { |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 23 | struct ndn_Blob digestAlgorithm; /**< A Blob whose value is a pointer to a pre-allocated buffer. 0 for none. |
| 24 | * If none, default is 2.16.840.1.101.3.4.2.1 (sha-256). */ |
| 25 | struct ndn_Blob witness; /**< A Blob whose value is a pointer to pre-allocated buffer. 0 for none. */ |
| 26 | struct ndn_Blob signature; |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 27 | struct ndn_PublisherPublicKeyDigest publisherPublicKeyDigest; |
| 28 | struct ndn_KeyLocator keyLocator; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Initialize the ndn_Signature struct with values for none and the default digestAlgorithm. |
| 33 | * @param self A pointer to the ndn_MetaInfo struct. |
| 34 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent for the keyLocator. |
| 35 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
| 36 | */ |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 37 | 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] | 38 | ndn_Blob_initialize(&self->digestAlgorithm, 0, 0); |
| 39 | ndn_Blob_initialize(&self->witness, 0, 0); |
| 40 | ndn_Blob_initialize(&self->signature, 0, 0); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 41 | ndn_PublisherPublicKeyDigest_initialize(&self->publisherPublicKeyDigest); |
| 42 | ndn_KeyLocator_initialize(&self->keyLocator, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 45 | /** |
| 46 | * An ndn_MetaInfo struct holds the meta info which is signed inside the data packet. |
| 47 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 48 | struct ndn_MetaInfo { |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 49 | ndn_MillisecondsSince1970 timestampMilliseconds; /**< milliseconds since 1/1/1970. -1 for none */ |
| 50 | ndn_ContentType type; /**< default is ndn_ContentType_DATA. -1 for none */ |
| 51 | int freshnessSeconds; /**< -1 for none */ |
| 52 | 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] | 53 | }; |
| 54 | |
| 55 | /** |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 56 | * Initialize the ndn_MetaInfo struct with values for none and the type to the default ndn_ContentType_DATA. |
| 57 | * @param self A pointer to the ndn_MetaInfo struct. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 58 | */ |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 59 | static inline void ndn_MetaInfo_initialize |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 60 | (struct ndn_MetaInfo *self) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 61 | self->type = ndn_ContentType_DATA; |
| 62 | self->freshnessSeconds = -1; |
Jeff Thompson | 145e225 | 2013-09-12 12:51:35 -0700 | [diff] [blame] | 63 | ndn_NameComponent_initialize(&self->finalBlockID, 0, 0); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 66 | struct ndn_Data { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 67 | struct ndn_Signature signature; |
| 68 | struct ndn_Name name; |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 69 | struct ndn_MetaInfo metaInfo; |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 70 | struct ndn_Blob content; /**< A Blob with a pointer to the content. */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /** |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 74 | * Initialize an ndn_Data struct with the pre-allocated nameComponents and keyNameComponents, |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 75 | * and defaults for all the values. |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame] | 76 | * @param self A pointer to the ndn_Data struct. |
| 77 | * @param nameComponents The pre-allocated array of ndn_NameComponent. |
| 78 | * @param maxNameComponents The number of elements in the allocated nameComponents array. |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 79 | * @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] | 80 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 81 | */ |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 82 | static inline void ndn_Data_initialize |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 83 | (struct ndn_Data *self, struct ndn_NameComponent *nameComponents, size_t maxNameComponents, |
| 84 | struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 85 | { |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 86 | ndn_Signature_initialize(&self->signature, keyNameComponents, maxKeyNameComponents); |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 87 | ndn_Name_initialize(&self->name, nameComponents, maxNameComponents); |
Jeff Thompson | f4585af | 2013-09-11 14:56:59 -0700 | [diff] [blame] | 88 | ndn_MetaInfo_initialize(&self->metaInfo); |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 89 | ndn_Blob_initialize(&self->content, 0, 0); |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 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 |