blob: b84e676ef9db132d9e37a080f46dc7282f874080 [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
13 * @author Jeff Thompson <jefft0@remap.ucla.edu>
14 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070015 */
16
Yingdi Yufc40d872014-02-18 12:56:04 -080017#ifndef NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
18#define NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019
Yingdi Yu4f324632014-01-15 18:10:03 -080020#include "../common.hpp"
21#include "../encoding/buffer.hpp"
22#include "../encoding/oid.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070023
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070024namespace CryptoPP {
25class BufferedTransformation;
26}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070027
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080028namespace ndn {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070029
30/**
31 * A CertificateExtension represents the Extension entry in a certificate.
32 */
33class CertificateExtension
34{
35public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070036 class Error : public std::runtime_error
37 {
38 public:
39 explicit
40 Error(const std::string& what)
41 : std::runtime_error(what)
42 {
43 }
44 };
Yingdi Yuaaf3a212014-01-10 13:01:59 -080045
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 {
48 decode(in);
49 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070050
51 /**
52 * Create a new CertificateExtension.
53 * @param oid The oid of subject description entry.
54 * @param isCritical If true, the extension must be handled.
Jeff Thompson415da1e2013-10-17 16:52:59 -070055 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070056 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080057 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070058 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070059 {
60 }
61
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070062 CertificateExtension(const OID& oid, const bool isCritical,
63 const uint8_t* value, size_t valueSize)
64 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080065 {
66 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068 /**
69 * The virtual destructor.
70 */
71 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070072 ~CertificateExtension()
73 {
74 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070075
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080076 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077 encode(CryptoPP::BufferedTransformation& out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070078
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080079 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080 decode(CryptoPP::BufferedTransformation& in);
81
82 inline const OID&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070083 getOid() const
84 {
85 return m_extensionId;
86 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070087
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070088 inline const bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070089 getIsCritical() const
90 {
91 return m_isCritical;
92 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070093
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070094 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070095 getValue() const
96 {
97 return m_extensionValue;
98 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070099
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700100protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700101 OID m_extensionId;
102 bool m_isCritical;
103 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700104};
105
Yingdi Yufc40d872014-02-18 12:56:04 -0800106} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -0700107
Yingdi Yufc40d872014-02-18 12:56:04 -0800108#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP