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: |
Yingdi Yu | aaf3a21 | 2014-01-10 13:01:59 -0800 | [diff] [blame] | 26 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 27 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 28 | CertificateExtension(CryptoPP::BufferedTransformation &in) |
| 29 | { |
| 30 | decode(in); |
| 31 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Create a new CertificateExtension. |
| 35 | * @param oid The oid of subject description entry. |
| 36 | * @param isCritical If true, the extension must be handled. |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame] | 37 | * @param value The extension value. |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 39 | CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value) |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 40 | : extensionId_(oid), isCritical_(isCritical), extensionValue_(value) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 41 | { |
| 42 | } |
| 43 | |
Alexander Afanasyev | 049f8f7 | 2013-12-26 19:07:15 -0800 | [diff] [blame] | 44 | CertificateExtension(const OID& oid, const bool isCritical, const uint8_t* value, size_t valueSize) |
| 45 | : extensionId_(oid), isCritical_(isCritical), extensionValue_(value, valueSize) |
| 46 | { |
| 47 | } |
| 48 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 49 | /** |
| 50 | * The virtual destructor. |
| 51 | */ |
| 52 | virtual |
| 53 | ~CertificateExtension() {} |
| 54 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 55 | void |
| 56 | encode(CryptoPP::BufferedTransformation &out) const; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 58 | void |
| 59 | decode(CryptoPP::BufferedTransformation &in); |
| 60 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 61 | inline const OID& |
| 62 | getOid() const { return extensionId_; } |
| 63 | |
| 64 | inline const bool |
| 65 | getIsCritical() const { return isCritical_; } |
| 66 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 67 | inline const Buffer& |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 68 | getValue() const { return extensionValue_; } |
| 69 | |
| 70 | protected: |
| 71 | OID extensionId_; |
| 72 | bool isCritical_; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 73 | Buffer extensionValue_; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 76 | } // namespace ndn |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 77 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 78 | #endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP |