Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 3 | * 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 17 | #ifndef NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |
| 18 | #define NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 19 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 20 | #include "../common.hpp" |
| 21 | #include "../encoding/buffer.hpp" |
| 22 | #include "../encoding/oid.hpp" |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 24 | namespace CryptoPP { |
| 25 | class BufferedTransformation; |
| 26 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 27 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 28 | namespace ndn { |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * A CertificateExtension represents the Extension entry in a certificate. |
| 32 | */ |
| 33 | class CertificateExtension |
| 34 | { |
| 35 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 36 | 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 Yu | aaf3a21 | 2014-01-10 13:01:59 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 46 | CertificateExtension(CryptoPP::BufferedTransformation& in) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 47 | { |
| 48 | decode(in); |
| 49 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 50 | |
| 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 Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 55 | * @param value The extension value. |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 56 | */ |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 57 | CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 58 | : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 59 | { |
| 60 | } |
| 61 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 62 | 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 Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 65 | { |
| 66 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 67 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 68 | /** |
| 69 | * The virtual destructor. |
| 70 | */ |
| 71 | virtual |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 72 | ~CertificateExtension() |
| 73 | { |
| 74 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 76 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 77 | encode(CryptoPP::BufferedTransformation& out) const; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 79 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 80 | decode(CryptoPP::BufferedTransformation& in); |
| 81 | |
| 82 | inline const OID& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 83 | getOid() const |
| 84 | { |
| 85 | return m_extensionId; |
| 86 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 88 | inline const bool |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 89 | getIsCritical() const |
| 90 | { |
| 91 | return m_isCritical; |
| 92 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 94 | inline const Buffer& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 95 | getValue() const |
| 96 | { |
| 97 | return m_extensionValue; |
| 98 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 99 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 100 | protected: |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 101 | OID m_extensionId; |
| 102 | bool m_isCritical; |
| 103 | Buffer m_extensionValue; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 106 | } // namespace ndn |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 107 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 108 | #endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |