blob: b86b7d959f61f78977cfb2e2f0209542aed73319 [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
Jeff Thompsone589c3f2013-10-12 17:30:50 -07009#define NDN_MEMORY_IDENTITY_STORAGE_HPP
Jeff Thompson6c314bc2013-09-23 18:09:38 -070010
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 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070052 * Check if the specified key already exists.
53 * @param keyName The name of the key.
54 * @return true if the key exists, otherwise false.
55 */
56 virtual bool
57 doesKeyExist(const Name& keyName);
58
59 /**
Jeff Thompson6c314bc2013-09-23 18:09:38 -070060 * Add a public key to the identity storage.
61 * @param keyName The name of the public key to be added.
62 * @param keyType Type of the public key to be added.
63 * @param publicKeyDer A blob of the public key DER to be added.
64 */
65 virtual void
Jeff Thompsonbd04b072013-09-27 15:14:09 -070066 addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070067
68 /**
69 * Get the public key DER blob from the identity storage.
70 * @param keyName The name of the requested public key.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -070071 * @return The DER Blob. If not found, return a Blob with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -070072 */
73 virtual Blob
74 getKey(const Name& keyName);
75
76 /**
77 * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing.
78 * @param keyName name of the key
79 */
80 virtual void
81 activateKey(const Name& keyName);
82
83 /**
84 * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing.
85 * @param keyName name of the key
86 */
87 virtual void
88 deactivateKey(const Name& keyName);
89
90 /**
91 * Check if the specified certificate already exists.
92 * @param certificateName The name of the certificate.
93 * @return true if the certificate exists, otherwise false.
94 */
95 virtual bool
96 doesCertificateExist(const Name& certificateName);
97
98 /**
99 * Add a certificate to the identity storage.
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700100 * @param certificate The certificate to be added. This makes a copy of the certificate.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700101 */
102 virtual void
Jeff Thompsonc69163b2013-10-12 13:49:50 -0700103 addCertificate(const IdentityCertificate& certificate);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700104
105 /**
106 * Get a certificate from the identity storage.
107 * @param certificateName The name of the requested certificate.
108 * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700109 * @return The requested certificate. If not found, return a shared_ptr with a null pointer.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700110 */
Jeff Thompson3bd90bc2013-10-19 16:40:14 -0700111 virtual ptr_lib::shared_ptr<Data>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700112 getCertificate(const Name &certificateName, bool allowAny = false);
113
114
115 /*****************************************
116 * Get/Set Default *
117 *****************************************/
118
119 /**
120 * Get the default identity.
Jeff Thompson81842272013-09-25 16:12:33 -0700121 * @param return The name of default identity, or an empty name if there is no default.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700122 */
123 virtual Name
124 getDefaultIdentity();
125
126 /**
127 * Get the default key name for the specified identity.
128 * @param identityName The identity name.
129 * @return The default key name.
130 */
131 virtual Name
132 getDefaultKeyNameForIdentity(const Name& identityName);
133
134 /**
135 * Get the default certificate name for the specified key.
136 * @param keyName The key name.
137 * @return The default certificate name.
138 */
139 virtual Name
140 getDefaultCertificateNameForKey(const Name& keyName);
141
142 /**
Jeff Thompson81842272013-09-25 16:12:33 -0700143 * Set the default identity. If the identityName does not exist, then clear the default identity
144 * so that getDefaultIdentity() returns an empty name.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700145 * @param identityName The default identity name.
146 */
147 virtual void
148 setDefaultIdentity(const Name& identityName);
149
150 /**
151 * Set the default key name for the specified identity.
152 * @param keyName The key name.
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700153 * @param identityNameCheck (optional) The identity name to check the keyName.
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700154 */
155 virtual void
Jeff Thompsonabcea7d2013-10-02 15:03:21 -0700156 setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name());
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700157
158 /**
159 * Set the default key name for the specified identity.
160 * @param keyName The key name.
161 * @param certificateName The certificate name.
162 */
163 virtual void
164 setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName);
Jeff Thompson81842272013-09-25 16:12:33 -0700165
166private:
167 std::vector<std::string> identityStore_; /**< A list of name URI. */
168 std::string defaultIdentity_; /**< The default identity in identityStore_, or "" if not defined. */
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700169};
170
171}
172
173#endif