blob: 61f7dd29099db92ae60e3c670df5a501430ca7cd [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
9#ifndef NDN_CERTIFICATE_EXTENSION_HPP
10#define NDN_CERTIFICATE_EXTENSION_HPP
11
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:
Yingdi Yuaaf3a212014-01-10 13:01:59 -080026 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
27
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080028 CertificateExtension(CryptoPP::BufferedTransformation &in)
29 {
30 decode(in);
31 }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032
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 Thompson415da1e2013-10-17 16:52:59 -070037 * @param value The extension value.
Jeff Thompson958bf9b2013-10-12 17:20:51 -070038 */
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080039 CertificateExtension(const OID& oid, const bool isCritical, const Buffer& value)
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080040 : extensionId_(oid), isCritical_(isCritical), extensionValue_(value)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070041 {
42 }
43
Alexander Afanasyev049f8f72013-12-26 19:07:15 -080044 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 Thompson958bf9b2013-10-12 17:20:51 -070049 /**
50 * The virtual destructor.
51 */
52 virtual
53 ~CertificateExtension() {}
54
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080055 void
56 encode(CryptoPP::BufferedTransformation &out) const;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070057
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080058 void
59 decode(CryptoPP::BufferedTransformation &in);
60
Jeff Thompson958bf9b2013-10-12 17:20:51 -070061 inline const OID&
62 getOid() const { return extensionId_; }
63
64 inline const bool
65 getIsCritical() const { return isCritical_; }
66
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080067 inline const Buffer&
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068 getValue() const { return extensionValue_; }
69
70protected:
71 OID extensionId_;
72 bool isCritical_;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080073 Buffer extensionValue_;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070074};
75
76}
77
78#endif