blob: 1388107c491b0362ae3972884eec2e84df4a6113 [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)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080048 : extensionId_(oid), isCritical_(isCritical), extensionValue_(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070049 {
50 }
51
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080052 CertificateExtension(const OID& oid, const bool isCritical, const uint8_t* value, size_t valueSize)
53 : extensionId_(oid), isCritical_(isCritical), extensionValue_(value, valueSize)
54 {
55 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056
Jeff Thompson958bf9b2013-10-12 17:20:51 -070057 /**
58 * The virtual destructor.
59 */
60 virtual
61 ~CertificateExtension() {}
62
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080063 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064 encode(CryptoPP::BufferedTransformation& out) const;
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 decode(CryptoPP::BufferedTransformation& in);
68
69 inline const OID&
Jeff Thompson958bf9b2013-10-12 17:20:51 -070070 getOid() const { return extensionId_; }
71
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072 inline const bool
Jeff Thompson958bf9b2013-10-12 17:20:51 -070073 getIsCritical() const { return isCritical_; }
74
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075 inline const Buffer&
Jeff Thompson958bf9b2013-10-12 17:20:51 -070076 getValue() const { return extensionValue_; }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077
Jeff Thompson958bf9b2013-10-12 17:20:51 -070078protected:
79 OID extensionId_;
80 bool isCritical_;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080081 Buffer extensionValue_;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070082};
83
Yingdi Yufc40d872014-02-18 12:56:04 -080084} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -070085
Yingdi Yufc40d872014-02-18 12:56:04 -080086#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP