blob: 6350a32fc29a048301d1a71cc701c9bd1aa9e9c4 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson5cae5e52013-07-10 19:41:20 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson5cae5e52013-07-10 19:41:20 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_KEY_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07009#define NDN_KEY_HPP
Jeff Thompson5cae5e52013-07-10 19:41:20 -070010
11#include <vector>
Jeff Thompson25b4e612013-10-10 16:03:24 -070012#include "c/key-types.h"
Jeff Thompson2e6269c2013-08-22 10:36:00 -070013#include "name.hpp"
Jeff Thompson5cae5e52013-07-10 19:41:20 -070014
Jeff Thompson25b4e612013-10-10 16:03:24 -070015struct ndn_KeyLocator;
16
Jeff Thompson5cae5e52013-07-10 19:41:20 -070017namespace ndn {
18
19class KeyLocator {
20public:
21 KeyLocator()
Jeff Thompson7329a132013-08-16 15:57:37 -070022 : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1)
Jeff Thompson5cae5e52013-07-10 19:41:20 -070023 {
Jeff Thompson5cae5e52013-07-10 19:41:20 -070024 }
25
26 /**
Jeff Thompsonf4585af2013-09-11 14:56:59 -070027 * Clear the keyData and set the type to none.
28 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070029 void
30 clear()
Jeff Thompsonf4585af2013-09-11 14:56:59 -070031 {
32 type_ = (ndn_KeyLocatorType)-1;
33 keyNameType_ = (ndn_KeyNameType)-1;
Jeff Thompson03616c92013-09-12 14:30:01 -070034 keyData_.reset();
Jeff Thompsonf4585af2013-09-11 14:56:59 -070035 }
36
37 /**
Jeff Thompson5cae5e52013-07-10 19:41:20 -070038 * Set the keyLocatorStruct to point to the values in this key locator, without copying any memory.
39 * WARNING: The resulting pointers in keyLocatorStruct are invalid after a further use of this object which could reallocate memory.
40 * @param keyLocatorStruct a C ndn_KeyLocator struct where the name components array is already allocated.
41 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070042 void
43 get(struct ndn_KeyLocator& keyLocatorStruct) const;
Jeff Thompson5cae5e52013-07-10 19:41:20 -070044
45 /**
46 * Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
47 * @param keyLocatorStruct a C ndn_KeyLocator struct
48 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070049 void
50 set(const struct ndn_KeyLocator& keyLocatorStruct);
Jeff Thompson5cae5e52013-07-10 19:41:20 -070051
Jeff Thompson0050abe2013-09-17 12:50:25 -070052 ndn_KeyLocatorType
53 getType() const { return type_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070054
Jeff Thompson0050abe2013-09-17 12:50:25 -070055 const Blob&
56 getKeyData() const { return keyData_; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070057
Jeff Thompson0050abe2013-09-17 12:50:25 -070058 const Name&
59 getKeyName() const { return keyName_; }
Jeff Thompson46bd45f2013-08-08 16:46:41 -070060
Jeff Thompson0050abe2013-09-17 12:50:25 -070061 Name&
62 getKeyName() { return keyName_; }
63
64 ndn_KeyNameType
65 getKeyNameType() const { return keyNameType_; }
66
67 void
68 setType(ndn_KeyLocatorType type) { type_ = type; }
Jeff Thompson2c8dff52013-11-18 18:17:12 -080069
Jeff Thompson0050abe2013-09-17 12:50:25 -070070 void
Jeff Thompson2c8dff52013-11-18 18:17:12 -080071 setKeyData(const Blob& keyData) { keyData_ = keyData; }
Jeff Thompson63d02692013-08-16 12:09:07 -070072
Jeff Thompson35a2bc12013-09-17 14:23:13 -070073 void setKeyName(const Name &keyName) { keyName_ = keyName; }
74
Jeff Thompson0050abe2013-09-17 12:50:25 -070075 void
76 setKeyNameType(ndn_KeyNameType keyNameType) { keyNameType_ = keyNameType; }
Jeff Thompson5cae5e52013-07-10 19:41:20 -070077
78private:
Jeff Thompson7329a132013-08-16 15:57:37 -070079 ndn_KeyLocatorType type_; /**< -1 for none */
Jeff Thompson4c9c0452013-09-12 14:10:11 -070080 Blob keyData_; /**< An array for the key data as follows:
Jeff Thompson7329a132013-08-16 15:57:37 -070081 * If type_ is ndn_KeyLocatorType_KEY, the key data.
82 * If type_ is ndn_KeyLocatorType_CERTIFICATE, the certificate data.
83 * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_PUBLIC_KEY_DIGEST, the publisher public key digest.
84 * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST, the publisher certificate digest.
85 * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_KEY_DIGEST, the publisher issuer key digest.
86 * If type_ is ndn_KeyLocatorType_KEYNAME and keyNameType_ is ndn_KeyNameType_PUBLISHER_ISSUER_CERTIFICATE_DIGEST, the publisher issuer certificate digest.
87 */
88 Name keyName_; /**< The key name (only used if type_ is ndn_KeyLocatorType_KEYNAME.) */
Jeff Thompson1cf72e92013-08-23 20:38:39 -070089 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 -070090};
91
92}
93
94#endif