blob: c8988356b4170b1cca8e1bf8bc2cb143b83321f9 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson958bf9b2013-10-12 17:20:51 -07002/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
22 * @author Jeff Thompson <jefft0@remap.ucla.edu>
23 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070024 */
25
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070026#ifndef NDN_SECURITY_V1_CERTIFICATE_EXTENSION_HPP
27#define NDN_SECURITY_V1_CERTIFICATE_EXTENSION_HPP
Jeff Thompson958bf9b2013-10-12 17:20:51 -070028
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070029#include "../../common.hpp"
30#include "../../encoding/buffer.hpp"
31#include "../../encoding/oid.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070033namespace CryptoPP {
34class BufferedTransformation;
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070035} // namespace CryptoPP
Jeff Thompson958bf9b2013-10-12 17:20:51 -070036
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070038namespace security {
39namespace v1 {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070040
41/**
42 * A CertificateExtension represents the Extension entry in a certificate.
43 */
44class CertificateExtension
45{
46public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 class Error : public std::runtime_error
48 {
49 public:
50 explicit
51 Error(const std::string& what)
52 : std::runtime_error(what)
53 {
54 }
55 };
Yingdi Yuaaf3a212014-01-10 13:01:59 -080056
Alexander Afanasyeva4297a62014-06-19 13:29:34 -070057 explicit
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080059 {
60 decode(in);
61 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070062
63 /**
64 * Create a new CertificateExtension.
65 * @param oid The oid of subject description entry.
66 * @param isCritical If true, the extension must be handled.
Jeff Thompson415da1e2013-10-17 16:52:59 -070067 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068 */
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070069 CertificateExtension(const Oid& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070070 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070071 {
72 }
73
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070074 CertificateExtension(const Oid& oid, const bool isCritical,
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070075 const uint8_t* value, size_t valueSize)
76 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080077 {
78 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070079
Jeff Thompson958bf9b2013-10-12 17:20:51 -070080 /**
81 * The virtual destructor.
82 */
83 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070084 ~CertificateExtension()
85 {
86 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070087
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080088 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089 encode(CryptoPP::BufferedTransformation& out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070090
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080091 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070092 decode(CryptoPP::BufferedTransformation& in);
93
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070094 inline const Oid&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070095 getOid() const
96 {
97 return m_extensionId;
98 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070099
Alexander Afanasyev24b75c82014-05-31 15:59:31 +0300100 inline bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700101 getIsCritical() const
102 {
103 return m_isCritical;
104 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700105
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700106 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700107 getValue() const
108 {
109 return m_extensionValue;
110 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700112protected:
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700113 Oid m_extensionId;
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700114 bool m_isCritical;
115 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700116};
117
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700118} // namespace v1
119} // namespace security
120
121#ifdef NDN_CXX_KEEP_SECURITY_V1_ALIASES
122/// @deprecated When needed, use explicit namespace
123using security::v1::CertificateExtension;
124#endif // NDN_CXX_KEEP_SECURITY_V1_ALIASES
125
Yingdi Yufc40d872014-02-18 12:56:04 -0800126} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700127
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700128#endif // NDN_SECURITY_V1_CERTIFICATE_EXTENSION_HPP