blob: 4a42eac92b0ec492a33dc228e64fbc84f0c174b5 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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
Yingdi Yufc40d872014-02-18 12:56:04 -080026#ifndef NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
27#define NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
Jeff Thompson958bf9b2013-10-12 17:20:51 -070028
Yingdi Yu4f324632014-01-15 18:10:03 -080029#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;
35}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070036
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037namespace ndn {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070038
39/**
40 * A CertificateExtension represents the Extension entry in a certificate.
41 */
42class CertificateExtension
43{
44public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070045 class Error : public std::runtime_error
46 {
47 public:
48 explicit
49 Error(const std::string& what)
50 : std::runtime_error(what)
51 {
52 }
53 };
Yingdi Yuaaf3a212014-01-10 13:01:59 -080054
Alexander Afanasyeva4297a62014-06-19 13:29:34 -070055 explicit
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080057 {
58 decode(in);
59 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070060
61 /**
62 * Create a new CertificateExtension.
63 * @param oid The oid of subject description entry.
64 * @param isCritical If true, the extension must be handled.
Jeff Thompson415da1e2013-10-17 16:52:59 -070065 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070066 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080067 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070068 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070069 {
70 }
71
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070072 CertificateExtension(const OID& oid, const bool isCritical,
73 const uint8_t* value, size_t valueSize)
74 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080075 {
76 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077
Jeff Thompson958bf9b2013-10-12 17:20:51 -070078 /**
79 * The virtual destructor.
80 */
81 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070082 ~CertificateExtension()
83 {
84 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070085
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080086 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070087 encode(CryptoPP::BufferedTransformation& out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070088
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080089 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070090 decode(CryptoPP::BufferedTransformation& in);
91
92 inline const OID&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070093 getOid() const
94 {
95 return m_extensionId;
96 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070097
Alexander Afanasyev24b75c82014-05-31 15:59:31 +030098 inline bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070099 getIsCritical() const
100 {
101 return m_isCritical;
102 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700103
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700105 getValue() const
106 {
107 return m_extensionValue;
108 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700109
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700110protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700111 OID m_extensionId;
112 bool m_isCritical;
113 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700114};
115
Yingdi Yufc40d872014-02-18 12:56:04 -0800116} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700117
Yingdi Yufc40d872014-02-18 12:56:04 -0800118#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP