blob: 90ad3c5c58d2467c9a76c1b784788459947bd6fd [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070022 */
23
Yingdi Yufc40d872014-02-18 12:56:04 -080024#ifndef NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
25#define NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070026
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080027#include "../common.hpp"
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070028#include "certificate.hpp"
29
30namespace ndn {
31
32class IdentityCertificate : public Certificate
33{
Jeff Thompsonc69163b2013-10-12 13:49:50 -070034public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070035 class Error : public std::runtime_error
36 {
37 public:
38 explicit
39 Error(const std::string& what)
40 : std::runtime_error(what)
41 {
42 }
43 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080044
Jeff Thompsonc69163b2013-10-12 13:49:50 -070045 /**
46 * The default constructor.
47 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080048 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070049
Jeff Thompsonc69163b2013-10-12 13:49:50 -070050 /**
51 * Create an IdentityCertificate from the content in the data packet.
52 * @param data The data packet with the content to decode.
53 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070054 explicit
Jeff Thompsonc69163b2013-10-12 13:49:50 -070055 IdentityCertificate(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056
Jeff Thompson965569b2013-10-12 17:52:52 -070057 /**
58 * The virtual destructor.
59 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070060 virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070061 ~IdentityCertificate();
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080062
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070063 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064 wireDecode(const Block& wire);
65
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070066 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 setName(const Name& name);
68
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070069 const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070070 getPublicKeyName() const;
Jeff Thompson965569b2013-10-12 17:52:52 -070071
72 static bool
73 isIdentityCertificate(const Certificate& certificate);
74
Jeff Thompson74942612013-10-24 16:42:32 -070075 /**
76 * Get the public key name from the full certificate name.
77 * @param certificateName The full certificate name.
78 * @return The related public key name.
79 */
80 static Name
81 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070082
Jeff Thompson965569b2013-10-12 17:52:52 -070083private:
84 static bool
85 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086
Jeff Thompson43a57b12013-10-22 16:25:38 -070087 void
88 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070089
Jeff Thompson43a57b12013-10-22 16:25:38 -070090protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070091 Name m_publicKeyName;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070092};
93
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080094inline
95IdentityCertificate::IdentityCertificate()
96{
97}
98
99inline
100IdentityCertificate::IdentityCertificate(const Data& data)
101 : Certificate(data)
102{
103 setPublicKeyName();
104}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800106inline
107IdentityCertificate::~IdentityCertificate()
108{
109}
110
111inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700112IdentityCertificate::wireDecode(const Block& wire)
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800113{
114 Certificate::wireDecode(wire);
115 setPublicKeyName();
116}
117
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800118inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700119IdentityCertificate::setName(const Name& name)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800120{
121 Certificate::setName(name);
122 setPublicKeyName();
123}
124
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700125inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700126IdentityCertificate::getPublicKeyName() const
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800127{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700128 return m_publicKeyName;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800129}
130
Yingdi Yufc40d872014-02-18 12:56:04 -0800131} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700132
Yingdi Yufc40d872014-02-18 12:56:04 -0800133#endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP