blob: dc8509da72c93b6bbbe0a631108807582fb8bf84 [file] [log] [blame]
Jeff Thompson6c314bc2013-09-23 18:09:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_MEMORY_IDENTITY_STORAGE_HPP
9#define NDN_MEMORY_IDENTITY_STORAGE_HPP
10
Jeff Thompson81842272013-09-25 16:12:33 -070011#include <vector>
Jeff Thompson6c314bc2013-09-23 18:09:38 -070012#include "identity-storage.hpp"
13
14namespace ndn {
15
16/**
17 * MemoryIdentityStorage extends IdentityStorage and implements its methods to store identity, public key and certificate objects in memory.
18 * The application must get the objects through its own means and add the objects to the MemoryIdentityStorage object.
19 * To use permanent file-based storage, see BasicIdentityStorage.
20 */
21class MemoryIdentityStorage : public IdentityStorage {
22public:
23 /**
24 * The virtual Destructor.
25 */
26 virtual
27 ~MemoryIdentityStorage();
28
29 /**
30 * Check if the specified identity already exists.
31 * @param identityName The identity name.
32 * @return true if the identity exists, otherwise false.
33 */
34 virtual bool
35 doesIdentityExist(const Name& identityName);
36
37 /**
38 * Add a new identity. An exception will be thrown if the identity already exists.
39 * @param identityName The identity name to be added.
40 */
41 virtual void
42 addIdentity(const Name& identityName);
43
44 /**
45 * Revoke the identity.
46 * @return true if the identity was revoked, false if not.
47 */
48 virtual bool
49 revokeIdentity();
50
51 /**
52 * Generate a name for a new key belonging to the identity.
53 * @param identityName The identity name.
54 * @param useKsk If true, generate a KSK name, otherwise a DSK name.
55 * @return The generated key name.
56 */
57 virtual Name
58 getNewKeyName(const Name& identityName, bool useKsk);
59
60 /**
61 * Check if the specified key already exists.
62 * @param keyName The name of the key.
63 * @return true if the key exists, otherwise false.
64 */
65 virtual bool
66 doesKeyExist(const Name& keyName);
67
68 /**
69 * Extract the key name from the certificate name.
70 * @param certificateName The certificate name to be processed.
71 */
72 virtual Name
73 getKeyNameForCertificate(const Name& certificateName);
74
75 /**
76 * Add a public key to the identity storage.
77 * @param keyName The name of the public key to be added.
78 * @param keyType Type of the public key to be added.
79 * @param publicKeyDer A blob of the public key DER to be added.
80 */
81 virtual void
82 addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer);
83
84 /**
85 * Get the public key DER blob from the identity storage.
86 * @param keyName The name of the requested public key.
87 */
88 virtual Blob
89 getKey(const Name& keyName);
90
91 /**
92 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
93 * @param keyName name of the key
94 */
95 virtual void
96 activateKey(const Name& keyName);
97
98 /**
99 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
100 * @param keyName name of the key
101 */
102 virtual void
103 deactivateKey(const Name& keyName);
104
105 /**
106 * Check if the specified certificate already exists.
107 * @param certificateName The name of the certificate.
108 * @return true if the certificate exists, otherwise false.
109 */
110 virtual bool
111 doesCertificateExist(const Name& certificateName);
112
113 /**
114 * Add a certificate to the identity storage.
115 * @param certificate The certificate to be added.
116 */
117 virtual void
118 addCertificate(const Certificate& certificate);
119
120 /**
121 * Get a certificate from the identity storage.
122 * @param certificateName The name of the requested certificate.
123 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
124 * @return The requested certificate.
125 */
Jeff Thompsona6fd6382013-09-24 15:23:37 -0700126 virtual ptr_lib::shared_ptr<Certificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700127 getCertificate(const Name &certificateName, bool allowAny = false);
128
129
130 /*****************************************
131 * Get/Set Default *
132 *****************************************/
133
134 /**
135 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700136 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700137 */
138 virtual Name
139 getDefaultIdentity();
140
141 /**
142 * Get the default key name for the specified identity.
143 * @param identityName The identity name.
144 * @return The default key name.
145 */
146 virtual Name
147 getDefaultKeyNameForIdentity(const Name& identityName);
148
149 /**
150 * Get the default certificate name for the specified key.
151 * @param keyName The key name.
152 * @return The default certificate name.
153 */
154 virtual Name
155 getDefaultCertificateNameForKey(const Name& keyName);
156
157 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700158 * Set the default identity. If the identityName does not exist, then clear the default identity
159 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700160 * @param identityName The default identity name.
161 */
162 virtual void
163 setDefaultIdentity(const Name& identityName);
164
165 /**
166 * Set the default key name for the specified identity.
167 * @param keyName The key name.
168 * @param identityName (optional) The identity name to check the keyName.
169 */
170 virtual void
171 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName = Name());
172
173 /**
174 * Set the default key name for the specified identity.
175 * @param keyName The key name.
176 * @param certificateName The certificate name.
177 */
178 virtual void
179 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
Jeff Thompson81842272013-09-25 16:12:33 -0700180
181private:
182 std::vector<std::string> identityStore_; /**< A list of name URI. */
183 std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700184};
185
186}
187
188#endif