blob: 83653eed0b4af844f8b3015b508ee9899764c060 [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 Afanasyev2a7f7202014-04-23 14:25:29 -070016namespace CryptoPP {
17class BufferedTransformation;
18}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080020namespace ndn {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070021
22/**
23 * A CertificateExtension represents the Extension entry in a certificate.
24 */
25class CertificateExtension
26{
27public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070028 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 Yuaaf3a212014-01-10 13:01:59 -080037
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038 CertificateExtension(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080039 {
40 decode(in);
41 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070042
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 Thompson415da1e2013-10-17 16:52:59 -070047 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070048 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070050 : m_extensionId(oid), m_isCritical(isCritical), m_extensionValue(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070051 {
52 }
53
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070054 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 Afanasyev049f8f72013-12-26 19:07:15 -080057 {
58 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059
Jeff Thompson958bf9b2013-10-12 17:20:51 -070060 /**
61 * The virtual destructor.
62 */
63 virtual
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070064 ~CertificateExtension()
65 {
66 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070067
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080068 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 encode(CryptoPP::BufferedTransformation& out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070070
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080071 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072 decode(CryptoPP::BufferedTransformation& in);
73
74 inline const OID&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070075 getOid() const
76 {
77 return m_extensionId;
78 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070079
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080 inline const bool
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070081 getIsCritical() const
82 {
83 return m_isCritical;
84 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070085
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086 inline const Buffer&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070087 getValue() const
88 {
89 return m_extensionValue;
90 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091
Jeff Thompson958bf9b2013-10-12 17:20:51 -070092protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070093 OID m_extensionId;
94 bool m_isCritical;
95 Buffer m_extensionValue;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070096};
97
Yingdi Yufc40d872014-02-18 12:56:04 -080098} // namespace ndn
Jeff Thompson958bf9b2013-10-12 17:20:51 -070099
Yingdi Yufc40d872014-02-18 12:56:04 -0800100#endif //NDN_SECURITY_CERTIFICATE_EXTENSION_HPP