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 |
| 41 | ~Certificate() {} |
| 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); } |
| 55 | |
| 56 | /** |
| 57 | * Add a certificate extension. |
| 58 | * @param extension the extension to be added |
| 59 | */ |
| 60 | void |
| 61 | addExtension(const CertificateExtension& extension) { extensionList_.push_back(extension); } |
| 62 | |
| 63 | void |
| 64 | setNotBefore(const Time& notBefore) { notBefore_ = notBefore; } |
| 65 | |
| 66 | Time& |
| 67 | getNotBefore() { return notBefore_; } |
| 68 | |
| 69 | const Time& |
| 70 | getNotBefore() const { return notBefore_; } |
| 71 | |
| 72 | void |
| 73 | setNotAfter(const Time& notAfter) { notAfter_ = notAfter; } |
| 74 | |
| 75 | Time& |
| 76 | getNotAfter() { return notAfter_; } |
| 77 | |
| 78 | const Time& |
| 79 | getNotAfter() const { return notAfter_; } |
| 80 | |
| 81 | void |
| 82 | setPublicKeyInfo(const PublicKey& key) { key_ = key; } |
| 83 | |
| 84 | PublicKey& |
| 85 | getPublicKeyInfo() { return key_; } |
| 86 | |
| 87 | const PublicKey& |
| 88 | getPublicKeyInfo() const { return key_; } |
| 89 | |
| 90 | virtual Name |
| 91 | getPublicKeyName() const = 0; |
| 92 | |
| 93 | /** |
| 94 | * Check if the certificate is valid. |
| 95 | * @return True if the current time is earlier than notBefore. |
| 96 | */ |
| 97 | bool |
| 98 | isTooEarly(); |
| 99 | |
| 100 | /** |
| 101 | * Check if the certificate is valid. |
| 102 | * @return True if the current time is later than notAfter. |
| 103 | */ |
| 104 | bool |
| 105 | isTooLate(); |
| 106 | |
| 107 | void |
| 108 | printCertificate(); |
| 109 | |
| 110 | protected: |
| 111 | void |
| 112 | decode(); |
| 113 | |
| 114 | protected: |
| 115 | SubjectDescriptionList subjectDescriptionList_; |
| 116 | Time notBefore_; |
| 117 | Time notAfter_; |
| 118 | PublicKey key_; |
| 119 | ExtensionList extensionList_; |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | } |
| 123 | |
| 124 | #endif |