blob: a1aa5b656c8a541f41312b2f90197632fafef770 [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson173fd432013-10-12 18:16:41 -07004 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson958bf9b2013-10-12 17:20:51 -07005 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yufc40d872014-02-18 12:56:04 -08009#ifndef NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
10#define NDN_SECURITY_CERTIFICATE_EXTENSION_HPP
Jeff Thompson958bf9b2013-10-12 17:20:51 -070011
Yingdi Yu4f324632014-01-15 18:10:03 -080012#include "../common.hpp"
13#include "../encoding/buffer.hpp"
14#include "../encoding/oid.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070015
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080016namespace CryptoPP { class BufferedTransformation; }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070017
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080018namespace ndn {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019
20/**
21 * A CertificateExtension represents the Extension entry in a certificate.
22 */
23class CertificateExtension
24{
25public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070026 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 Yuaaf3a212014-01-10 13:01:59 -080035
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070036 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037 {
38 decode(in);
39 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070040
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 Thompson415da1e2013-10-17 16:52:59 -070045 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070046 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070048 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070049 {
50 }
51
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070052 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 Afanasyev049f8f72013-12-26 19:07:15 -080055 {
56 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057
Jeff Thompson958bf9b2013-10-12 17:20:51 -070058 /**
59 * The virtual destructor.
60 */
61 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070062 ~CertificateExtension()
63 {
64 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070065
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080066 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 encode(CryptoPP::BufferedTransformation& out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080069 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070070 decode(CryptoPP::BufferedTransformation& in);
71
72 inline const OID&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070073 getOid() const
74 {
75 return m_extensionId;
76 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070077
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078 inline const bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070079 getIsCritical() const
80 {
81 return m_isCritical;
82 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070083
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070084 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070085 getValue() const
86 {
87 return m_extensionValue;
88 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089
Jeff Thompson958bf9b2013-10-12 17:20:51 -070090protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070091 OID m_extensionId;
92 bool m_isCritical;
93 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070094};
95
Yingdi Yufc40d872014-02-18 12:56:04 -080096} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -070097
Yingdi Yufc40d872014-02-18 12:56:04 -080098#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP