Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | 173fd43 | 2013-10-12 18:16:41 -0700 | [diff] [blame] | 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 9 | #ifndef NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |
| 10 | #define NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 11 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 12 | #include "../common.hpp" |
| 13 | #include "../encoding/buffer.hpp" |
| 14 | #include "../encoding/oid.hpp" |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 16 | namespace CryptoPP { class BufferedTransformation; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 17 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 18 | namespace ndn { |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * A CertificateExtension represents the Extension entry in a certificate. |
| 22 | */ |
| 23 | class CertificateExtension |
| 24 | { |
| 25 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 26 | class Error : public std::runtime_error |
| 27 | { |
| 28 | public: |
| 29 | explicit |
| 30 | Error(const std::string& what) |
| 31 | : std::runtime_error(what) |
| 32 | { |
| 33 | } |
| 34 | }; |
Yingdi Yu | aaf3a21 | 2014-01-10 13:01:59 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 36 | CertificateExtension(CryptoPP::BufferedTransformation& in) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 37 | { |
| 38 | decode(in); |
| 39 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Create a new CertificateExtension. |
| 43 | * @param oid The oid of subject description entry. |
| 44 | * @param isCritical If true, the extension must be handled. |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 45 | * @param value The extension value. |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 46 | */ |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 47 | CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 48 | : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 52 | CertificateExtension(const OID& oid, const bool isCritical, |
| 53 | const uint8_t* value, size_t valueSize) |
| 54 | : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize) |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 55 | { |
| 56 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 57 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 58 | /** |
| 59 | * The virtual destructor. |
| 60 | */ |
| 61 | virtual |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 62 | ~CertificateExtension() |
| 63 | { |
| 64 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 66 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 67 | encode(CryptoPP::BufferedTransformation& out) const; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 69 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 70 | decode(CryptoPP::BufferedTransformation& in); |
| 71 | |
| 72 | inline const OID& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 73 | getOid() const |
| 74 | { |
| 75 | return m_extensionId; |
| 76 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 78 | inline const bool |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 79 | getIsCritical() const |
| 80 | { |
| 81 | return m_isCritical; |
| 82 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 84 | inline const Buffer& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 85 | getValue() const |
| 86 | { |
| 87 | return m_extensionValue; |
| 88 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 89 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 90 | protected: |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame^] | 91 | OID m_extensionId; |
| 92 | bool m_isCritical; |
| 93 | Buffer m_extensionValue; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 96 | } // namespace ndn |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 97 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 98 | #endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |