All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sec-public-info-memory.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
8 #ifndef NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
9 #define NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
10 
11 #include "../common.hpp"
12 #include "sec-public-info.hpp"
13 
14 namespace ndn {
15 
21 {
22 public:
23  class Error : public SecPublicInfo::Error
24  {
25  public:
26  explicit
27  Error(const std::string& what)
28  : SecPublicInfo::Error(what)
29  {
30  }
31  };
32 
33  virtual
35 
36  virtual bool
37  doesIdentityExist(const Name& identityName);
38 
39  virtual void
40  addIdentity(const Name& identityName);
41 
42  virtual bool
44 
45  virtual bool
46  doesPublicKeyExist(const Name& keyName);
47 
48  virtual void
49  addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKeyDer);
50 
51  virtual shared_ptr<PublicKey>
52  getPublicKey(const Name& keyName);
53 
54  virtual bool
55  doesCertificateExist(const Name& certificateName);
56 
57  virtual void
58  addCertificate(const IdentityCertificate& certificate);
59 
60  virtual shared_ptr<IdentityCertificate>
61  getCertificate(const Name& certificateName);
62 
63  virtual Name
65 
66  virtual Name
67  getDefaultKeyNameForIdentity(const Name& identityName);
68 
69  virtual Name
70  getDefaultCertificateNameForKey(const Name& keyName);
71 
72  virtual void
73  getAllIdentities(std::vector<Name>& nameList, bool isDefault);
74 
75  virtual void
76  getAllKeyNames(std::vector<Name>& nameList, bool isDefault);
77 
78  virtual void
79  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault);
80 
81  virtual void
82  getAllCertificateNames(std::vector<Name>& nameList, bool isDefault);
83 
84  virtual void
85  getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, bool isDefault);
86 
87 protected:
88  virtual void
89  setDefaultIdentityInternal(const Name& identityName);
90 
91  virtual void
93 
94  virtual void
95  setDefaultCertificateNameForKeyInternal(const Name& certificateName);
96 
97  virtual void
98  deleteCertificateInfo(const Name& certificateName);
99 
100  virtual void
101  deletePublicKeyInfo(const Name& keyName);
102 
103  virtual void
104  deleteIdentityInfo(const Name& identity);
105 
106 
107 private:
108  class KeyRecord
109  {
110  public:
111  KeyRecord(KeyType keyType, const PublicKey& key)
112  : m_keyType(keyType), m_key(key)
113  {
114  }
115 
116  const KeyType
117  getKeyType() const
118  {
119  return m_keyType;
120  }
121 
122  const PublicKey&
123  getKey()
124  {
125  return m_key;
126  }
127 
128  private:
129  KeyType m_keyType;
130  PublicKey m_key;
131  };
132 
133  std::vector<std::string> m_identityStore; // A list of name URI.
134  std::string m_defaultIdentity; // The default identity in m_identityStore, or "" if not defined.
135  Name m_defaultKeyName;
136  Name m_defaultCert;
137 
138  // The map key is the keyName.toUri()
139  typedef std::map<std::string, shared_ptr<KeyRecord> > KeyStore;
140 
141  // The map key is the certificateName.toUri()
142  typedef std::map<std::string, shared_ptr<IdentityCertificate> > CertificateStore;
143 
144  KeyStore m_keyStore;
145  CertificateStore m_certificateStore;
146 };
147 
148 } // namespace ndn
149 
150 #endif //NDN_SECURITY_SEC_PUBLIC_INFO_MEMORY_HPP
virtual bool doesPublicKeyExist(const Name &keyName)
Check if the specified key already exists.
virtual bool doesIdentityExist(const Name &identityName)
Check if the specified identity already exists.
virtual void getAllIdentities(std::vector< Name > &nameList, bool isDefault)
Get all the identities in public info.
virtual bool doesCertificateExist(const Name &certificateName)
Check if the specified certificate already exists.
virtual void setDefaultCertificateNameForKeyInternal(const Name &certificateName)
Set the default certificate name for the corresponding key.
SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity, public key and certificate objects in memory.
virtual void getAllKeyNamesOfIdentity(const Name &identity, std::vector< Name > &nameList, bool isDefault)
Get all the key name of a particular identity.
virtual void deleteIdentityInfo(const Name &identity)
Delete an identity and related public keys and certificates.
virtual Name getDefaultKeyNameForIdentity(const Name &identityName)
Get the default key name for the specified identity.
virtual void setDefaultKeyNameForIdentityInternal(const Name &keyName)
Set the default key name for the corresponding identity.
virtual void getAllKeyNames(std::vector< Name > &nameList, bool isDefault)
Get all the key name in public info.
virtual shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a certificate from the identity storage.
virtual bool revokeIdentity()
Revoke the identity.
virtual void getAllCertificateNamesOfKey(const Name &keyName, std::vector< Name > &nameList, bool isDefault)
Get all the certificate name of a particular key.
virtual void getAllCertificateNames(std::vector< Name > &nameList, bool isDefault)
Get all the certificate name in public info.
virtual void deletePublicKeyInfo(const Name &keyName)
Delete a public key and related certificates.
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:26
virtual void setDefaultIdentityInternal(const Name &identityName)
Set the default identity.
virtual Name getDefaultIdentity()
Get the default identity.
virtual shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get the public key DER blob from the identity storage.
virtual void deleteCertificateInfo(const Name &certificateName)
Delete a certificate.
virtual void addPublicKey(const Name &keyName, KeyType keyType, const PublicKey &publicKeyDer)
Add a public key to the identity storage.
virtual Name getDefaultCertificateNameForKey(const Name &keyName)
Get the default certificate name for the specified key.
SecPublicInfo is a base class for the storage of public information.
virtual void addIdentity(const Name &identityName)
Add a new identity.
virtual void addCertificate(const IdentityCertificate &certificate)
Add a certificate to the identity storage.