Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -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: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #ifndef NDN_CERTIFICATE_HPP |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 10 | #define NDN_CERTIFICATE_HPP |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 11 | |
| 12 | #include "../../data.hpp" |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 13 | #include "../../common.hpp" |
| 14 | |
| 15 | #include "certificate-subject-description.hpp" |
| 16 | #include "certificate-extension.hpp" |
| 17 | #include "public-key.hpp" |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 18 | |
| 19 | namespace ndn { |
| 20 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 21 | typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList; |
| 22 | typedef std::vector<CertificateExtension> ExtensionList; |
| 23 | |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 24 | class Certificate : public Data { |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 25 | public: |
| 26 | /** |
| 27 | * The default constructor. |
| 28 | */ |
| 29 | Certificate(); |
| 30 | |
| 31 | /** |
| 32 | * Create a Certificate from the content in the data packet. |
| 33 | * @param data The data packet with the content to decode. |
| 34 | */ |
| 35 | Certificate(const Data& data); |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * The virtual destructor. |
| 39 | */ |
| 40 | virtual |
Jeff Thompson | a5dc351 | 2013-10-17 10:26:19 -0700 | [diff] [blame] | 41 | ~Certificate(); |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * encode certificate info into content |
| 45 | */ |
| 46 | void |
| 47 | encode(); |
| 48 | |
| 49 | /** |
| 50 | * Add a subject description. |
| 51 | * @param description The description to be added. |
| 52 | */ |
| 53 | void |
| 54 | addSubjectDescription(const CertificateSubjectDescription& description) { subjectDescriptionList_.push_back(description); } |
Jeff Thompson | 6ef69b2 | 2013-12-18 16:24:45 -0800 | [diff] [blame] | 55 | |
| 56 | const SubjectDescriptionList& |
| 57 | getSubjectDescriptionList() const { return subjectDescriptionList_; } |
| 58 | |
| 59 | SubjectDescriptionList& |
| 60 | getSubjectDescriptionList() { return subjectDescriptionList_; } |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Add a certificate extension. |
| 64 | * @param extension the extension to be added |
| 65 | */ |
| 66 | void |
| 67 | addExtension(const CertificateExtension& extension) { extensionList_.push_back(extension); } |
| 68 | |
Jeff Thompson | 6ef69b2 | 2013-12-18 16:24:45 -0800 | [diff] [blame] | 69 | const ExtensionList& |
| 70 | getExtensionList() const { return extensionList_; } |
| 71 | |
| 72 | ExtensionList& |
| 73 | getExtensionList() { return extensionList_; } |
| 74 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 75 | void |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 76 | setNotBefore(const MillisecondsSince1970& notBefore) { notBefore_ = notBefore; } |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 77 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 78 | MillisecondsSince1970& |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 79 | getNotBefore() { return notBefore_; } |
| 80 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 81 | const MillisecondsSince1970& |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 82 | getNotBefore() const { return notBefore_; } |
| 83 | |
| 84 | void |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 85 | setNotAfter(const MillisecondsSince1970& notAfter) { notAfter_ = notAfter; } |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 86 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 87 | MillisecondsSince1970& |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 88 | getNotAfter() { return notAfter_; } |
| 89 | |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 90 | const MillisecondsSince1970& |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 91 | getNotAfter() const { return notAfter_; } |
| 92 | |
| 93 | void |
| 94 | setPublicKeyInfo(const PublicKey& key) { key_ = key; } |
| 95 | |
| 96 | PublicKey& |
| 97 | getPublicKeyInfo() { return key_; } |
| 98 | |
| 99 | const PublicKey& |
| 100 | getPublicKeyInfo() const { return key_; } |
| 101 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame^] | 102 | // virtual Name |
| 103 | // getPublicKeyName() const = 0; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Check if the certificate is valid. |
| 107 | * @return True if the current time is earlier than notBefore. |
| 108 | */ |
| 109 | bool |
| 110 | isTooEarly(); |
| 111 | |
| 112 | /** |
| 113 | * Check if the certificate is valid. |
| 114 | * @return True if the current time is later than notAfter. |
| 115 | */ |
| 116 | bool |
| 117 | isTooLate(); |
| 118 | |
| 119 | void |
| 120 | printCertificate(); |
| 121 | |
| 122 | protected: |
| 123 | void |
| 124 | decode(); |
| 125 | |
| 126 | protected: |
| 127 | SubjectDescriptionList subjectDescriptionList_; |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 128 | MillisecondsSince1970 notBefore_; |
| 129 | MillisecondsSince1970 notAfter_; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 130 | PublicKey key_; |
| 131 | ExtensionList extensionList_; |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } |
| 135 | |
| 136 | #endif |