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-2022 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 
59 class Certificate : public Data
60 {
61 public:
62  class Error : public Data::Error
63  {
64  public:
65  using Data::Error::Error;
66  };
67 
68  Certificate();
69 
74  explicit
75  Certificate(Data&& data);
76 
81  explicit
82  Certificate(const Data& data);
83 
88  explicit
89  Certificate(const Block& block);
90 
94  Name
95  getIdentity() const;
96 
100  Name
101  getKeyName() const;
102 
107  getKeyId() const;
108 
113  getIssuerId() const;
114 
119  span<const uint8_t>
120  getPublicKey() const noexcept
121  {
122  return getContent().value_bytes();
123  }
124 
129  getValidityPeriod() const;
130 
134  bool
136 
141  Block
142  getExtension(uint32_t type) const;
143 
144  // @TODO Implement extension enumeration (Issue #3907)
145 public:
149  static bool
150  isValidName(const Name& certName);
151 
152 public:
153  static const ssize_t VERSION_OFFSET;
154  static const ssize_t ISSUER_ID_OFFSET;
155  static const ssize_t KEY_COMPONENT_OFFSET;
156  static const ssize_t KEY_ID_OFFSET;
157  static const size_t MIN_CERT_NAME_LENGTH;
158  static const size_t MIN_KEY_NAME_LENGTH;
161 };
162 
163 std::ostream&
164 operator<<(std::ostream& os, const Certificate& cert);
165 
169 Name
170 extractIdentityFromCertName(const Name& certName);
171 
175 Name
176 extractKeyNameFromCertName(const Name& certName);
177 
178 } // inline namespace v2
179 } // namespace security
180 } // namespace ndn
181 
182 #endif // NDN_CXX_SECURITY_CERTIFICATE_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
span< const uint8_t > value_bytes() const noexcept
Return a read-only view of TLV-VALUE as a contiguous range of bytes.
Definition: block.hpp:330
Represents a Data packet.
Definition: data.hpp:39
const Block & getContent() const noexcept
Get the Content element.
Definition: data.hpp:180
Represents an absolute name.
Definition: name.hpp:44
Represents a name component.
Represents a ValidityPeriod TLV element.
Represents an NDN certificate.
Definition: certificate.hpp:60
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:98
static const name::Component KEY_COMPONENT
Name getKeyName() const
Get key name.
Definition: certificate.cpp:86
static const name::Component DEFAULT_ISSUER_ID
Name getIdentity() const
Get identity name.
Definition: certificate.cpp:80
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:92
static const size_t MIN_CERT_NAME_LENGTH
static const ssize_t ISSUER_ID_OFFSET
span< const uint8_t > getPublicKey() const noexcept
Return the public key as a DER-encoded SubjectPublicKeyInfo structure, i.e., exactly as it appears in...
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
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
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