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 | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 16 | namespace CryptoPP { |
| 17 | class BufferedTransformation; |
| 18 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 20 | namespace ndn { |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * A CertificateExtension represents the Extension entry in a certificate. |
| 24 | */ |
| 25 | class CertificateExtension |
| 26 | { |
| 27 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 28 | class Error : public std::runtime_error |
| 29 | { |
| 30 | public: |
| 31 | explicit |
| 32 | Error(const std::string& what) |
| 33 | : std::runtime_error(what) |
| 34 | { |
| 35 | } |
| 36 | }; |
Yingdi Yu | aaf3a21 | 2014-01-10 13:01:59 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 38 | CertificateExtension(CryptoPP::BufferedTransformation& in) |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 39 | { |
| 40 | decode(in); |
| 41 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Create a new CertificateExtension. |
| 45 | * @param oid The oid of subject description entry. |
| 46 | * @param isCritical If true, the extension must be handled. |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 47 | * @param value The extension value. |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 48 | */ |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 49 | CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value) |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 50 | : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 54 | CertificateExtension(const OID& oid, const bool isCritical, |
| 55 | const uint8_t* value, size_t valueSize) |
| 56 | : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value, valueSize) |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 57 | { |
| 58 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 59 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 60 | /** |
| 61 | * The virtual destructor. |
| 62 | */ |
| 63 | virtual |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 64 | ~CertificateExtension() |
| 65 | { |
| 66 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 68 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 69 | encode(CryptoPP::BufferedTransformation& out) const; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 70 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 71 | void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 72 | decode(CryptoPP::BufferedTransformation& in); |
| 73 | |
| 74 | inline const OID& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 75 | getOid() const |
| 76 | { |
| 77 | return m_extensionId; |
| 78 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 80 | inline const bool |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 81 | getIsCritical() const |
| 82 | { |
| 83 | return m_isCritical; |
| 84 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 86 | inline const Buffer& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 87 | getValue() const |
| 88 | { |
| 89 | return m_extensionValue; |
| 90 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 91 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 92 | protected: |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 93 | OID m_extensionId; |
| 94 | bool m_isCritical; |
| 95 | Buffer m_extensionValue; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 98 | } // namespace ndn |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 99 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 100 | #endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |