blob: b416080ce5126b3924b6405fa86e43782c6d48c1 [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:
Yingdi Yu80979ba2014-11-25 14:38:36 -080035 class Error : public Certificate::Error
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070036 {
37 public:
38 explicit
39 Error(const std::string& what)
Yingdi Yu80979ba2014-11-25 14:38:36 -080040 : Certificate::Error(what)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 {
42 }
43 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080044
Jeff Thompsonc69163b2013-10-12 13:49:50 -070045 /**
Yingdi Yu80979ba2014-11-25 14:38:36 -080046 * @brief The default constructor.
Jeff Thompsonc69163b2013-10-12 13:49:50 -070047 */
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 /**
Yingdi Yu80979ba2014-11-25 14:38:36 -080051 * @brief Create an IdentityCertificate from the content in the data packet.
Jeff Thompsonc69163b2013-10-12 13:49:50 -070052 * @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 /**
Yingdi Yu80979ba2014-11-25 14:38:36 -080058 * @brief Create an IdentityCertificate from a block.
59 * @param block The raw block of the certificate.
Jeff Thompson965569b2013-10-12 17:52:52 -070060 */
Yingdi Yu80979ba2014-11-25 14:38:36 -080061 explicit
62 IdentityCertificate(const Block& block);
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080063
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070064 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070065 wireDecode(const Block& wire);
66
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070067 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 setName(const Name& name);
69
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070070 const Name&
Yingdi Yu80979ba2014-11-25 14:38:36 -080071 getPublicKeyName() const
72 {
73 return m_publicKeyName;
74 }
Jeff Thompson965569b2013-10-12 17:52:52 -070075
76 static bool
77 isIdentityCertificate(const Certificate& certificate);
78
Jeff Thompson74942612013-10-24 16:42:32 -070079 /**
Yingdi Yu80979ba2014-11-25 14:38:36 -080080 * @brief Get the public key name from the full certificate name.
Jeff Thompson74942612013-10-24 16:42:32 -070081 * @param certificateName The full certificate name.
82 * @return The related public key name.
83 */
84 static Name
85 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070086
Jeff Thompson965569b2013-10-12 17:52:52 -070087private:
88 static bool
89 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070090
Jeff Thompson43a57b12013-10-22 16:25:38 -070091 void
92 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093
Jeff Thompson43a57b12013-10-22 16:25:38 -070094protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070095 Name m_publicKeyName;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070096};
97
Yingdi Yufc40d872014-02-18 12:56:04 -080098} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070099
Yingdi Yu80979ba2014-11-25 14:38:36 -0800100#endif // NDN_SECURITY_IDENTITY_CERTIFICATE_HPP