All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
certificate.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_CERTIFICATE_HPP
24 #define NDN_CERTIFICATE_HPP
25 
26 #include "../../data.hpp"
27 #include "../../common.hpp"
28 #include "../../sha256-with-rsa-signature.hpp"
29 
30 #include "certificate-subject-description.hpp"
31 #include "certificate-extension.hpp"
32 #include "public-key.hpp"
33 
34 namespace ndn {
35 
36 typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
37 typedef std::vector<CertificateExtension> ExtensionList;
38 
39 class Certificate : public Data {
40 public:
44  Certificate();
45 
50  Certificate(const Data& data);
51 
55  virtual
56  ~Certificate();
57 
62  void
63  encode();
64 
72  virtual void
74  (const Blob& input,
76 
81  void
82  addSubjectDescription(const CertificateSubjectDescription& description) { subjectDescriptionList_.push_back(description); }
83 
84  const SubjectDescriptionList&
85  getSubjectDescriptionList() const { return subjectDescriptionList_; }
86 
87  SubjectDescriptionList&
88  getSubjectDescriptionList() { return subjectDescriptionList_; }
89 
94  void
95  addExtension(const CertificateExtension& extension) { extensionList_.push_back(extension); }
96 
97  const ExtensionList&
98  getExtensionList() const { return extensionList_; }
99 
100  ExtensionList&
101  getExtensionList() { return extensionList_; }
102 
103  void
104  setNotBefore(const MillisecondsSince1970& notBefore) { notBefore_ = notBefore; }
105 
107  getNotBefore() { return notBefore_; }
108 
109  const MillisecondsSince1970&
110  getNotBefore() const { return notBefore_; }
111 
112  void
113  setNotAfter(const MillisecondsSince1970& notAfter) { notAfter_ = notAfter; }
114 
116  getNotAfter() { return notAfter_; }
117 
118  const MillisecondsSince1970&
119  getNotAfter() const { return notAfter_; }
120 
121  void
122  setPublicKeyInfo(const PublicKey& key) { key_ = key; }
123 
124  PublicKey&
125  getPublicKeyInfo() { return key_; }
126 
127  const PublicKey&
128  getPublicKeyInfo() const { return key_; }
129 
135  const Blob&
136  getPublicKeyDer() const;
137 
142  bool
143  isTooEarly() const;
144 
149  bool
150  isTooLate() const;
151 
152  bool
153  isInValidityPeriod(MillisecondsSince1970 time) const
154  {
155  // Debug: Generalize this from Sha256WithRsaSignature.
156  return dynamic_cast<const Sha256WithRsaSignature *>
157  (getSignature())->getValidityPeriod().isValid(time);
158  }
159 
160  void
161  printCertificate(std::ostream& os) const;
162 
163  void
164  printCertificate() const;
165 
166 protected:
167  void
168  decode();
169 
170  SubjectDescriptionList subjectDescriptionList_;
171  MillisecondsSince1970 notBefore_;
172  MillisecondsSince1970 notAfter_;
173  PublicKey key_;
174  ExtensionList extensionList_;
175 
176 private:
177  ptr_lib::shared_ptr<DerNode>
178  toDer();
179 };
180 
181 }
182 
183 #endif
Certificate()
The default constructor.
Definition: certificate.cpp:38
bool isTooEarly() const
Check if the certificate is valid.
Definition: certificate.cpp:65
void addSubjectDescription(const CertificateSubjectDescription &description)
Add a subject description.
Definition: certificate.hpp:82
A CertificateSubjectDescription represents the SubjectDescription entry in a Certificate.
Definition: certificate-subject-description.hpp:36
Definition: data.hpp:37
bool isTooLate() const
Check if the certificate is valid.
Definition: certificate.cpp:75
void encode()
Encode the contents of the certificate in DER format and set the Content and MetaInfo fields...
Definition: certificate.cpp:85
A CertificateExtension represents the Extension entry in a certificate.
Definition: certificate-extension.hpp:37
const Blob & getPublicKeyDer() const
Get the public key DER encoding.
Definition: certificate.cpp:56
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:119
void addExtension(const CertificateExtension &extension)
Add a certificate extension.
Definition: certificate.hpp:95
virtual void wireDecode(const Blob &input, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Override to call the base class wireDecode then populate the certificate fields.
Definition: certificate.cpp:93
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
virtual ~Certificate()
The virtual destructor.
Definition: certificate.cpp:50
Definition: wire-format.hpp:39
Definition: certificate.hpp:39