blob: cad811f2402acd708c3ec190c01af0a9d3cc2c33 [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 Afanasyevfdbfc6d2014-04-14 15:12:11 -070055 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080056 {
57 decode(in);
58 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070059
60 /**
61 * Create a new CertificateExtension.
62 * @param oid The oid of subject description entry.
63 * @param isCritical If true, the extension must be handled.
Jeff Thompson415da1e2013-10-17 16:52:59 -070064 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070065 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080066 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070067 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068 {
69 }
70
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070071 CertificateExtension(const OID& oid, const bool isCritical,
72 const uint8_t* value, size_t valueSize)
73 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080074 {
75 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070076
Jeff Thompson958bf9b2013-10-12 17:20:51 -070077 /**
78 * The virtual destructor.
79 */
80 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070081 ~CertificateExtension()
82 {
83 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070084
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080085 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086 encode(CryptoPP::BufferedTransformation& out) const;
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 decode(CryptoPP::BufferedTransformation& in);
90
91 inline const OID&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070092 getOid() const
93 {
94 return m_extensionId;
95 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070096
Alexander Afanasyev24b75c82014-05-31 15:59:31 +030097 inline bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070098 getIsCritical() const
99 {
100 return m_isCritical;
101 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700102
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700104 getValue() const
105 {
106 return m_extensionValue;
107 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700108
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700109protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700110 OID m_extensionId;
111 bool m_isCritical;
112 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700113};
114
Yingdi Yufc40d872014-02-18 12:56:04 -0800115} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700116
Yingdi Yufc40d872014-02-18 12:56:04 -0800117#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP