All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
certificate.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
9 #ifndef NDN_SECURITY_CERTIFICATE_HPP
10 #define NDN_SECURITY_CERTIFICATE_HPP
11 
12 #include "../common.hpp"
13 #include "../data.hpp"
16 #include "public-key.hpp"
17 
18 namespace ndn {
19 
20 class Certificate : public Data
21 {
22 public:
23  class Error : public std::runtime_error
24  {
25  public:
26  explicit
27  Error(const std::string& what)
28  : std::runtime_error(what)
29  {
30  }
31  };
32 
33  typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
34  typedef std::vector<CertificateExtension> ExtensionList;
35 
39  Certificate();
40 
45  Certificate(const Data& data);
46 
50  virtual
51  ~Certificate();
52 
53  inline void
54  wireDecode(const Block& wire);
55 
59  void
60  encode();
61 
66  void
68  {
69  m_subjectDescriptionList.push_back(description);
70  }
71 
74  {
76  }
77 
80  {
82  }
83 
88  void
90  {
91  m_extensionList.push_back(extension);
92  }
93 
94  const ExtensionList&
96  {
97  return m_extensionList;
98  }
99 
102  {
103  return m_extensionList;
104  }
105 
106  void
108  {
109  m_notBefore = notBefore;
110  }
111 
114  {
115  return m_notBefore;
116  }
117 
119  getNotBefore() const
120  {
121  return m_notBefore;
122  }
123 
124  void
126  {
127  m_notAfter = notAfter;
128  }
129 
132  {
133  return m_notAfter;
134  }
135 
137  getNotAfter() const
138  {
139  return m_notAfter;
140  }
141 
142  void
144  {
145  m_key = key;
146  }
147 
148  PublicKey&
150  {
151  return m_key;
152  }
153 
154  const PublicKey&
156  {
157  return m_key;
158  }
159 
160  // virtual Name
161  // getPublicKeyName() const = 0;
162 
167  bool
168  isTooEarly();
169 
174  bool
175  isTooLate();
176 
177  void
178  printCertificate(std::ostream& os) const;
179 
180 protected:
181  void
182  decode();
183 
184 protected:
190 };
191 
192 inline void
194 {
195  Data::wireDecode(wire);
196  decode();
197 }
198 
199 
200 inline std::ostream&
201 operator<<(std::ostream& os, const Certificate& cert)
202 {
203  cert.printCertificate(os);
204  return os;
205 }
206 
207 } // namespace ndn
208 
209 #endif //NDN_SECURITY_CERTIFICATE_HPP
time::system_clock::TimePoint & getNotBefore()
Error(const std::string &what)
Definition: certificate.hpp:27
ExtensionList m_extensionList
time::system_clock::TimePoint & getNotAfter()
void addSubjectDescription(const CertificateSubjectDescription &description)
Add a subject description.
Definition: certificate.hpp:67
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: data.hpp:306
void addExtension(const CertificateExtension &extension)
Add a certificate extension.
Definition: certificate.hpp:89
std::vector< CertificateExtension > ExtensionList
Definition: certificate.hpp:34
A CertificateSubjectDescription represents the SubjectDescription entry in a Certificate.
const SubjectDescriptionList & getSubjectDescriptionList() const
Definition: certificate.hpp:73
void wireDecode(const Block &wire)
Class representing wire element of the NDN packet.
Definition: block.hpp:26
Certificate()
The default constructor.
Definition: certificate.cpp:20
const time::system_clock::TimePoint & getNotAfter() const
PublicKey & getPublicKeyInfo()
const ExtensionList & getExtensionList() const
Definition: certificate.hpp:95
time::system_clock::TimePoint m_notAfter
void setNotBefore(const time::system_clock::TimePoint &notBefore)
bool isTooLate()
Check if the certificate is valid.
Definition: certificate.cpp:48
void encode()
encode certificate info into content
Definition: certificate.cpp:57
const PublicKey & getPublicKeyInfo() const
time::system_clock::TimePoint m_notBefore
bool isTooEarly()
Check if the certificate is valid.
Definition: certificate.cpp:39
time_point TimePoint
Definition: time.hpp:55
SubjectDescriptionList m_subjectDescriptionList
SubjectDescriptionList & getSubjectDescriptionList()
Definition: certificate.hpp:79
std::vector< CertificateSubjectDescription > SubjectDescriptionList
Definition: certificate.hpp:33
virtual ~Certificate()
The virtual destructor.
Definition: certificate.cpp:33
ExtensionList & getExtensionList()
const time::system_clock::TimePoint & getNotBefore() const
A CertificateExtension represents the Extension entry in a certificate.
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.hpp:523
void printCertificate(std::ostream &os) const
void setNotAfter(const time::system_clock::TimePoint &notAfter)
void setPublicKeyInfo(const PublicKey &key)