blob: a95131991c0971491b79259712e5cb1df29a2224 [file] [log] [blame]
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070013 */
14
Yingdi Yufc40d872014-02-18 12:56:04 -080015#ifndef NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
16#define NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070017
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080018#include "../common.hpp"
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070019#include "certificate.hpp"
20
21namespace ndn {
22
23class IdentityCertificate : public Certificate
24{
Jeff Thompsonc69163b2013-10-12 13:49:50 -070025public:
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 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080035
Jeff Thompsonc69163b2013-10-12 13:49:50 -070036 /**
37 * The default constructor.
38 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080039 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070040
Jeff Thompsonc69163b2013-10-12 13:49:50 -070041 /**
42 * Create an IdentityCertificate from the content in the data packet.
43 * @param data The data packet with the content to decode.
44 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070045 explicit
Jeff Thompsonc69163b2013-10-12 13:49:50 -070046 IdentityCertificate(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047
Jeff Thompson965569b2013-10-12 17:52:52 -070048 /**
49 * The virtual destructor.
50 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070051 virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070052 ~IdentityCertificate();
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080053
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070054 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070055 wireDecode(const Block& wire);
56
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070057 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058 setName(const Name& name);
59
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070060 const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070061 getPublicKeyName() const;
Jeff Thompson965569b2013-10-12 17:52:52 -070062
63 static bool
64 isIdentityCertificate(const Certificate& certificate);
65
Jeff Thompson74942612013-10-24 16:42:32 -070066 /**
67 * Get the public key name from the full certificate name.
68 * @param certificateName The full certificate name.
69 * @return The related public key name.
70 */
71 static Name
72 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070073
Jeff Thompson965569b2013-10-12 17:52:52 -070074private:
75 static bool
76 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077
Jeff Thompson43a57b12013-10-22 16:25:38 -070078 void
79 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070080
Jeff Thompson43a57b12013-10-22 16:25:38 -070081protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070082 Name m_publicKeyName;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070083};
84
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080085inline
86IdentityCertificate::IdentityCertificate()
87{
88}
89
90inline
91IdentityCertificate::IdentityCertificate(const Data& data)
92 : Certificate(data)
93{
94 setPublicKeyName();
95}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070096
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080097inline
98IdentityCertificate::~IdentityCertificate()
99{
100}
101
102inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700103IdentityCertificate::wireDecode(const Block& wire)
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800104{
105 Certificate::wireDecode(wire);
106 setPublicKeyName();
107}
108
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800109inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700110IdentityCertificate::setName(const Name& name)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800111{
112 Certificate::setName(name);
113 setPublicKeyName();
114}
115
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700116inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700117IdentityCertificate::getPublicKeyName() const
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800118{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700119 return m_publicKeyName;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800120}
121
Yingdi Yufc40d872014-02-18 12:56:04 -0800122} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700123
Yingdi Yufc40d872014-02-18 12:56:04 -0800124#endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP