Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
| 11 | #include "identity-storage.hpp" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
| 16 | * MemoryIdentityStorage extends IdentityStorage and implements its methods to store identity, public key and certificate objects in memory. |
| 17 | * The application must get the objects through its own means and add the objects to the MemoryIdentityStorage object. |
| 18 | * To use permanent file-based storage, see BasicIdentityStorage. |
| 19 | */ |
| 20 | class MemoryIdentityStorage : public IdentityStorage { |
| 21 | public: |
| 22 | /** |
| 23 | * The virtual Destructor. |
| 24 | */ |
| 25 | virtual |
| 26 | ~MemoryIdentityStorage(); |
| 27 | |
| 28 | /** |
| 29 | * Check if the specified identity already exists. |
| 30 | * @param identityName The identity name. |
| 31 | * @return true if the identity exists, otherwise false. |
| 32 | */ |
| 33 | virtual bool |
| 34 | doesIdentityExist(const Name& identityName); |
| 35 | |
| 36 | /** |
| 37 | * Add a new identity. An exception will be thrown if the identity already exists. |
| 38 | * @param identityName The identity name to be added. |
| 39 | */ |
| 40 | virtual void |
| 41 | addIdentity(const Name& identityName); |
| 42 | |
| 43 | /** |
| 44 | * Revoke the identity. |
| 45 | * @return true if the identity was revoked, false if not. |
| 46 | */ |
| 47 | virtual bool |
| 48 | revokeIdentity(); |
| 49 | |
| 50 | /** |
| 51 | * Generate a name for a new key belonging to the identity. |
| 52 | * @param identityName The identity name. |
| 53 | * @param useKsk If true, generate a KSK name, otherwise a DSK name. |
| 54 | * @return The generated key name. |
| 55 | */ |
| 56 | virtual Name |
| 57 | getNewKeyName(const Name& identityName, bool useKsk); |
| 58 | |
| 59 | /** |
| 60 | * Check if the specified key already exists. |
| 61 | * @param keyName The name of the key. |
| 62 | * @return true if the key exists, otherwise false. |
| 63 | */ |
| 64 | virtual bool |
| 65 | doesKeyExist(const Name& keyName); |
| 66 | |
| 67 | /** |
| 68 | * Extract the key name from the certificate name. |
| 69 | * @param certificateName The certificate name to be processed. |
| 70 | */ |
| 71 | virtual Name |
| 72 | getKeyNameForCertificate(const Name& certificateName); |
| 73 | |
| 74 | /** |
| 75 | * Add a public key to the identity storage. |
| 76 | * @param keyName The name of the public key to be added. |
| 77 | * @param keyType Type of the public key to be added. |
| 78 | * @param publicKeyDer A blob of the public key DER to be added. |
| 79 | */ |
| 80 | virtual void |
| 81 | addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer); |
| 82 | |
| 83 | /** |
| 84 | * Get the public key DER blob from the identity storage. |
| 85 | * @param keyName The name of the requested public key. |
| 86 | */ |
| 87 | virtual Blob |
| 88 | getKey(const Name& keyName); |
| 89 | |
| 90 | /** |
| 91 | * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing. |
| 92 | * @param keyName name of the key |
| 93 | */ |
| 94 | virtual void |
| 95 | activateKey(const Name& keyName); |
| 96 | |
| 97 | /** |
| 98 | * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing. |
| 99 | * @param keyName name of the key |
| 100 | */ |
| 101 | virtual void |
| 102 | deactivateKey(const Name& keyName); |
| 103 | |
| 104 | /** |
| 105 | * Check if the specified certificate already exists. |
| 106 | * @param certificateName The name of the certificate. |
| 107 | * @return true if the certificate exists, otherwise false. |
| 108 | */ |
| 109 | virtual bool |
| 110 | doesCertificateExist(const Name& certificateName); |
| 111 | |
| 112 | /** |
| 113 | * Add a certificate to the identity storage. |
| 114 | * @param certificate The certificate to be added. |
| 115 | */ |
| 116 | virtual void |
| 117 | addCertificate(const Certificate& certificate); |
| 118 | |
| 119 | /** |
| 120 | * Get a certificate from the identity storage. |
| 121 | * @param certificateName The name of the requested certificate. |
| 122 | * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded. |
| 123 | * @return The requested certificate. |
| 124 | */ |
| 125 | virtual ptr_lib::shared_ptr<Data> |
| 126 | getCertificate(const Name &certificateName, bool allowAny = false); |
| 127 | |
| 128 | |
| 129 | /***************************************** |
| 130 | * Get/Set Default * |
| 131 | *****************************************/ |
| 132 | |
| 133 | /** |
| 134 | * Get the default identity. |
| 135 | * @param return The name of default identity. |
| 136 | */ |
| 137 | virtual Name |
| 138 | getDefaultIdentity(); |
| 139 | |
| 140 | /** |
| 141 | * Get the default key name for the specified identity. |
| 142 | * @param identityName The identity name. |
| 143 | * @return The default key name. |
| 144 | */ |
| 145 | virtual Name |
| 146 | getDefaultKeyNameForIdentity(const Name& identityName); |
| 147 | |
| 148 | /** |
| 149 | * Get the default certificate name for the specified key. |
| 150 | * @param keyName The key name. |
| 151 | * @return The default certificate name. |
| 152 | */ |
| 153 | virtual Name |
| 154 | getDefaultCertificateNameForKey(const Name& keyName); |
| 155 | |
| 156 | /** |
| 157 | * Set the default identity. |
| 158 | * @param identityName The default identity name. |
| 159 | */ |
| 160 | virtual void |
| 161 | setDefaultIdentity(const Name& identityName); |
| 162 | |
| 163 | /** |
| 164 | * Set the default key name for the specified identity. |
| 165 | * @param keyName The key name. |
| 166 | * @param identityName (optional) The identity name to check the keyName. |
| 167 | */ |
| 168 | virtual void |
| 169 | setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName = Name()); |
| 170 | |
| 171 | /** |
| 172 | * Set the default key name for the specified identity. |
| 173 | * @param keyName The key name. |
| 174 | * @param certificateName The certificate name. |
| 175 | */ |
| 176 | virtual void |
| 177 | setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName); |
| 178 | }; |
| 179 | |
| 180 | } |
| 181 | |
| 182 | #endif |