blob: 270bfb014208b78970bf0e3d543a93dc99c501fa [file] [log] [blame]
Jeff Thompsone7e069b2013-09-27 15:48:48 -07001/* -*- 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 Thompson965569b2013-10-12 17:52:52 -070010#define NDN_CERTIFICATE_HPP
Jeff Thompsone7e069b2013-09-27 15:48:48 -070011
12#include "../../data.hpp"
Jeff Thompson965569b2013-10-12 17:52:52 -070013#include "../../common.hpp"
14
15#include "certificate-subject-description.hpp"
16#include "certificate-extension.hpp"
17#include "public-key.hpp"
Jeff Thompsone7e069b2013-09-27 15:48:48 -070018
19namespace ndn {
20
Jeff Thompson965569b2013-10-12 17:52:52 -070021typedef std::vector<CertificateSubjectDescription> SubjectDescriptionList;
22typedef std::vector<CertificateExtension> ExtensionList;
23
Jeff Thompsone7e069b2013-09-27 15:48:48 -070024class Certificate : public Data {
Jeff Thompsonc69163b2013-10-12 13:49:50 -070025public:
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 Thompson06f41072013-10-15 18:06:07 -070035#if 0 // TODO: Define in certificate.cpp
Jeff Thompsonc69163b2013-10-12 13:49:50 -070036 Certificate(const Data& data);
Jeff Thompson06f41072013-10-15 18:06:07 -070037#else
38 Certificate(const Data& data) {}
39#endif
Jeff Thompson965569b2013-10-12 17:52:52 -070040
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
114protected:
115 void
116 decode();
117
118protected:
119 SubjectDescriptionList subjectDescriptionList_;
120 Time notBefore_;
121 Time notAfter_;
122 PublicKey key_;
123 ExtensionList extensionList_;
Jeff Thompsone7e069b2013-09-27 15:48:48 -0700124};
125
126}
127
128#endif