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 | */ |
Jeff Thompson | 06f4107 | 2013-10-15 18:06:07 -0700 | [diff] [blame] | 35 | #if 0 // TODO: Define in certificate.cpp |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 36 | Certificate(const Data& data); |
Jeff Thompson | 06f4107 | 2013-10-15 18:06:07 -0700 | [diff] [blame] | 37 | #else |
| 38 | Certificate(const Data& data) {} |
| 39 | #endif |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * The virtual destructor. |
| 43 | */ |
| 44 | virtual |
| 45 | ~Certificate() {} |
| 46 | |
| 47 | /** |
| 48 | * encode certificate info into content |
| 49 | */ |
| 50 | void |
| 51 | encode(); |
| 52 | |
| 53 | /** |
| 54 | * Add a subject description. |
| 55 | * @param description The description to be added. |
| 56 | */ |
| 57 | void |
| 58 | addSubjectDescription(const CertificateSubjectDescription& description) { subjectDescriptionList_.push_back(description); } |
| 59 | |
| 60 | /** |
| 61 | * Add a certificate extension. |
| 62 | * @param extension the extension to be added |
| 63 | */ |
| 64 | void |
| 65 | addExtension(const CertificateExtension& extension) { extensionList_.push_back(extension); } |
| 66 | |
| 67 | void |
| 68 | setNotBefore(const Time& notBefore) { notBefore_ = notBefore; } |
| 69 | |
| 70 | Time& |
| 71 | getNotBefore() { return notBefore_; } |
| 72 | |
| 73 | const Time& |
| 74 | getNotBefore() const { return notBefore_; } |
| 75 | |
| 76 | void |
| 77 | setNotAfter(const Time& notAfter) { notAfter_ = notAfter; } |
| 78 | |
| 79 | Time& |
| 80 | getNotAfter() { return notAfter_; } |
| 81 | |
| 82 | const Time& |
| 83 | getNotAfter() const { return notAfter_; } |
| 84 | |
| 85 | void |
| 86 | setPublicKeyInfo(const PublicKey& key) { key_ = key; } |
| 87 | |
| 88 | PublicKey& |
| 89 | getPublicKeyInfo() { return key_; } |
| 90 | |
| 91 | const PublicKey& |
| 92 | getPublicKeyInfo() const { return key_; } |
| 93 | |
| 94 | virtual Name |
| 95 | getPublicKeyName() const = 0; |
| 96 | |
| 97 | /** |
| 98 | * Check if the certificate is valid. |
| 99 | * @return True if the current time is earlier than notBefore. |
| 100 | */ |
| 101 | bool |
| 102 | isTooEarly(); |
| 103 | |
| 104 | /** |
| 105 | * Check if the certificate is valid. |
| 106 | * @return True if the current time is later than notAfter. |
| 107 | */ |
| 108 | bool |
| 109 | isTooLate(); |
| 110 | |
| 111 | void |
| 112 | printCertificate(); |
| 113 | |
| 114 | protected: |
| 115 | void |
| 116 | decode(); |
| 117 | |
| 118 | protected: |
| 119 | SubjectDescriptionList subjectDescriptionList_; |
| 120 | Time notBefore_; |
| 121 | Time notAfter_; |
| 122 | PublicKey key_; |
| 123 | ExtensionList extensionList_; |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } |
| 127 | |
| 128 | #endif |