certificate.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2021 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  *
21  * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
22  * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
23  */
24 
25 #ifndef NDN_CXX_SECURITY_CERTIFICATE_HPP
26 #define NDN_CXX_SECURITY_CERTIFICATE_HPP
27 
28 #include "ndn-cxx/data.hpp"
29 
30 namespace ndn {
31 namespace security {
32 inline namespace v2 {
33 
60 class Certificate : public Data
61 {
62 public:
63  Certificate();
64 
69  explicit
70  Certificate(Data&& data);
71 
76  explicit
77  Certificate(const Data& data);
78 
83  explicit
84  Certificate(const Block& block);
85 
89  Name
90  getKeyName() const;
91 
95  Name
96  getIdentity() const;
97 
102  getKeyId() const;
103 
108  getIssuerId() const;
109 
114  Buffer
115  getPublicKey() const;
116 
121  getValidityPeriod() const;
122 
126  bool
128 
133  Block
134  getExtension(uint32_t type) const;
135 
136  // @TODO Implement extension enumeration (Issue #3907)
137 public:
141  static bool
142  isValidName(const Name& certName);
143 
144 public:
145  static const ssize_t VERSION_OFFSET;
146  static const ssize_t ISSUER_ID_OFFSET;
147  static const ssize_t KEY_COMPONENT_OFFSET;
148  static const ssize_t KEY_ID_OFFSET;
149  static const size_t MIN_CERT_NAME_LENGTH;
150  static const size_t MIN_KEY_NAME_LENGTH;
152 };
153 
154 std::ostream&
155 operator<<(std::ostream& os, const Certificate& cert);
156 
160 Name
161 extractIdentityFromCertName(const Name& certName);
162 
166 Name
167 extractKeyNameFromCertName(const Name& certName);
168 
169 } // inline namespace v2
170 } // namespace security
171 } // namespace ndn
172 
173 #endif // NDN_CXX_SECURITY_CERTIFICATE_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
General-purpose automatically managed/resized buffer.
Definition: buffer.hpp:42
Represents a Data packet.
Definition: data.hpp:38
Represents an absolute name.
Definition: name.hpp:46
Represents a name component.
Represents a ValidityPeriod TLV element.
Represents an NDN certificate following the version 2.0 format.
Definition: certificate.hpp:61
Buffer getPublicKey() const
Get public key bits (in PKCS#8 format)
bool isValid(const time::system_clock::TimePoint &ts=time::system_clock::now()) const
Check if the certificate is valid at ts.
name::Component getIssuerId() const
Get issuer ID.
Definition: certificate.cpp:99
static const name::Component KEY_COMPONENT
Name getKeyName() const
Get key name.
Definition: certificate.cpp:81
Name getIdentity() const
Get identity name.
Definition: certificate.cpp:87
ValidityPeriod getValidityPeriod() const
Get validity period of the certificate.
static const ssize_t KEY_COMPONENT_OFFSET
static const size_t MIN_KEY_NAME_LENGTH
static bool isValidName(const Name &certName)
Check if the specified name follows the naming convention for the certificate.
name::Component getKeyId() const
Get key ID.
Definition: certificate.cpp:93
static const size_t MIN_CERT_NAME_LENGTH
static const ssize_t ISSUER_ID_OFFSET
static const ssize_t VERSION_OFFSET
static const ssize_t KEY_ID_OFFSET
Block getExtension(uint32_t type) const
Get extension with TLV type.
static time_point now() noexcept
Definition: time.cpp:46
time_point TimePoint
Definition: time.hpp:203
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &desc)
Name extractKeyNameFromCertName(const Name &certName)
Extract key name from the certificate name certName.
Name extractIdentityFromCertName(const Name &certName)
Extract identity namespace from the certificate name certName.
Definition: data.cpp:25