blob: a933489260be9a398dea65fd116fe247b1fcc694 [file] [log] [blame]
Jeff Thompson5cae5e52013-07-10 19:41:20 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson5cae5e52013-07-10 19:41:20 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_KEY_H
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_KEY_H
Jeff Thompson5cae5e52013-07-10 19:41:20 -07009
Jeff Thompson7329a132013-08-16 15:57:37 -070010#include "name.h"
11
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070012#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070013extern "C" {
14#endif
15
16typedef enum {
17 ndn_KeyLocatorType_KEY = 1,
18 ndn_KeyLocatorType_CERTIFICATE = 2,
19 ndn_KeyLocatorType_KEYNAME = 3
20} ndn_KeyLocatorType;
Jeff Thompson7329a132013-08-16 15:57:37 -070021
22typedef enum {
23 ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST = 1,
24 ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST = 2,
25 ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST = 3,
26 ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST = 4
27} ndn_KeyNameType;
28
29/**
30 * An ndn_KeyLocator holds the type of key locator and related data.
31 */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070032struct ndn_KeyLocator {
Jeff Thompson7329a132013-08-16 15:57:37 -070033 ndn_KeyLocatorType type; /**< -1 for none */
Jeff Thompson93034532013-10-08 11:52:43 -070034 struct ndn_Blob keyData; /**< A Blob whose value is a pointer to a pre-allocated buffer for the key data as follows:
Jeff Thompson7329a132013-08-16 15:57:37 -070035 * If type is ndn_KeyLocatorType_KEY, the key data.
36 * If type is ndn_KeyLocatorType_CERTIFICATE, the certificate data.
37 * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest.
38 * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest.
39 * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest.
40 * If type is ndn_KeyLocatorType_KEYNAME and keyNameType is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest.
41 */
Jeff Thompson7329a132013-08-16 15:57:37 -070042 struct ndn_Name keyName; /**< The key name (only used if type is ndn_KeyLocatorType_KEYNAME.) */
Jeff Thompson1cf72e92013-08-23 20:38:39 -070043 ndn_KeyNameType keyNameType; /**< The type of data for keyName, -1 for none. (only used if type is ndn_KeyLocatorType_KEYNAME.) */
Jeff Thompson5cae5e52013-07-10 19:41:20 -070044};
45
Jeff Thompson7329a132013-08-16 15:57:37 -070046/**
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 */
Jeff Thompsond1427fb2013-08-29 17:20:32 -070052static inline void ndn_KeyLocator_initialize
Jeff Thompson97223af2013-09-24 17:01:27 -070053 (struct ndn_KeyLocator *self, struct ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents) {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070054 self->type = (ndn_KeyLocatorType)-1;
Jeff Thompson93034532013-10-08 11:52:43 -070055 ndn_Blob_initialize(&self->keyData, 0, 0);
Jeff Thompsond1427fb2013-08-29 17:20:32 -070056 ndn_Name_initialize(&self->keyName, keyNameComponents, maxKeyNameComponents);
Jeff Thompson7329a132013-08-16 15:57:37 -070057 self->keyNameType = (ndn_KeyNameType)-1;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070058}
59
Jeff Thompson2d27e2f2013-08-09 12:55:00 -070060#ifdef __cplusplus
Jeff Thompson5cae5e52013-07-10 19:41:20 -070061}
62#endif
63
64#endif