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 | |
| 6 | #ifndef NDN_KEY_H |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_KEY_H |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 9 | #include "name.h" |
| 10 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 11 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | typedef enum { |
| 16 | ndn_KeyLocatorType_KEY = 1, |
| 17 | ndn_KeyLocatorType_CERTIFICATE = 2, |
| 18 | ndn_KeyLocatorType_KEYNAME = 3 |
| 19 | } ndn_KeyLocatorType; |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 20 | |
| 21 | typedef enum { |
| 22 | ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST = 1, |
| 23 | ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST = 2, |
| 24 | ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST = 3, |
| 25 | ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST = 4 |
| 26 | } ndn_KeyNameType; |
| 27 | |
| 28 | /** |
| 29 | * An ndn_KeyLocator holds the type of key locator and related data. |
| 30 | */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 31 | struct ndn_KeyLocator { |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 32 | ndn_KeyLocatorType type; /**< -1 for none */ |
| 33 | unsigned char *keyData; /**< A pointer to a pre-allocated buffer for the key data as follows: |
| 34 | * If type is ndn_KeyLocatorType_KEY, the key data. |
| 35 | * If type is ndn_KeyLocatorType_CERTIFICATE, the certificate data. |
| 36 | * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest. |
| 37 | * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest. |
| 38 | * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest. |
| 39 | * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest. |
| 40 | */ |
| 41 | unsigned int keyDataLength; /**< The length of keyData. */ |
| 42 | struct ndn_Name keyName; /**< The key name (only used if type is ndn_KeyLocatorType_KEYNAME.) */ |
| 43 | ndn_KeyNameType keyNameType; /**< The type of data for keyName (only used if type is ndn_KeyLocatorType_KEYNAME.) */ |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 46 | /** |
| 47 | * Initialize an ndn_KeyLocator struct with the pre-allocated nameComponents, and defaults for all the values. |
| 48 | * @param self A pointer to the ndn_KeyLocator struct. |
| 49 | * @param keyNameComponents The pre-allocated array of ndn_NameComponent. |
| 50 | * @param maxKeyNameComponents The number of elements in the allocated keyNameComponents array. |
| 51 | */ |
| 52 | static inline void ndn_KeyLocator_init |
| 53 | (struct ndn_KeyLocator *self, struct ndn_NameComponent *keyNameComponents, unsigned int maxKeyNameComponents) { |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 54 | self->type = (ndn_KeyLocatorType)-1; |
Jeff Thompson | 63d0269 | 2013-08-16 12:09:07 -0700 | [diff] [blame] | 55 | self->keyData = 0; |
| 56 | self->keyDataLength = 0; |
Jeff Thompson | 7329a13 | 2013-08-16 15:57:37 -0700 | [diff] [blame^] | 57 | ndn_Name_init(&self->keyName, keyNameComponents, maxKeyNameComponents); |
| 58 | self->keyNameType = (ndn_KeyNameType)-1; |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 61 | #ifdef __cplusplus |
Jeff Thompson | 5cae5e5 | 2013-07-10 19:41:20 -0700 | [diff] [blame] | 62 | } |
| 63 | #endif |
| 64 | |
| 65 | #endif |