certificate-cache.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
24 #ifndef NDN_CERTIFICATE_CACHE_HPP
25 #define NDN_CERTIFICATE_CACHE_HPP
26 
27 #include <map>
28 #include "../certificate/identity-certificate.hpp"
29 
30 namespace ndn {
31 
37 public:
43  void
45  {
46  Name certName = certificate.getName().getPrefix(-1);
47  cache_[certName.toUri()] = certificate.wireEncode();
48  }
49 
55  void
56  deleteCertificate(const Name& certificateName)
57  {
58  std::map<std::string, Blob>::iterator entry
59  (cache_.find(certificateName.toUri()));
60  if (entry != cache_.end())
61  cache_.erase(entry);
62  }
63 
71  ptr_lib::shared_ptr<IdentityCertificate>
72  getCertificate(const Name& certificateName) const
73  {
74  std::map<std::string, Blob>::const_iterator entry
75  (cache_.find(certificateName.toUri()));
76  if (entry == cache_.end())
77  return ptr_lib::shared_ptr<IdentityCertificate>();
78 
79  ptr_lib::shared_ptr<IdentityCertificate> cert(new IdentityCertificate());
80  Blob certData = entry->second;
81  cert->wireDecode(certData);
82  return cert;
83  }
84 
88  void
90  {
91  cache_.clear();
92  }
93 
94 private:
95  // The key is the certificate name URI. The value is the wire encoding.
96  std::map<std::string, Blob> cache_;
97 };
98 
99 }
100 
101 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
std::string toUri(bool includeScheme=false) const
Encode this name as a URI.
Definition: name.cpp:305
Definition: identity-certificate.hpp:30
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
SignedBlob wireEncode(WireFormat &wireFormat=*WireFormat::getDefaultWireFormat()) const
Encode this Data for a particular wire format.
Definition: data.cpp:130
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
ptr_lib::shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName) const
Fetch a certificate from the cache.
Definition: certificate-cache.hpp:72
void insertCertificate(const IdentityCertificate &certificate)
Insert the certificate into the cache.
Definition: certificate-cache.hpp:44
void reset()
Clear all certificates from the store.
Definition: certificate-cache.hpp:89
Name getPrefix(int nComponents) const
Return a new Name with the first nComponents components of this Name.
Definition: name.hpp:758
void deleteCertificate(const Name &certificateName)
Remove a certificate from the cache.
Definition: certificate-cache.hpp:56
A CertificateCache is used to save other users' certificate during verification.
Definition: certificate-cache.hpp:36