blob: 98a320d4109f03d0921b033d7f3697529f9db239 [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 inline
40 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070041
Jeff Thompsonc69163b2013-10-12 13:49:50 -070042 /**
43 * Create an IdentityCertificate from the content in the data packet.
44 * @param data The data packet with the content to decode.
45 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080046 inline
Jeff Thompsonc69163b2013-10-12 13:49:50 -070047 IdentityCertificate(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070048
Jeff Thompson965569b2013-10-12 17:52:52 -070049 /**
50 * The virtual destructor.
51 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052 inline virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070053 ~IdentityCertificate();
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080054
55 inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070056 wireDecode(const Block& wire);
57
58 inline void
59 setName(const Name& name);
60
61 inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070062 getPublicKeyName() const;
Jeff Thompson965569b2013-10-12 17:52:52 -070063
64 static bool
65 isIdentityCertificate(const Certificate& certificate);
66
Jeff Thompson74942612013-10-24 16:42:32 -070067 /**
68 * Get the public key name from the full certificate name.
69 * @param certificateName The full certificate name.
70 * @return The related public key name.
71 */
72 static Name
73 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074
Jeff Thompson965569b2013-10-12 17:52:52 -070075private:
76 static bool
77 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070078
Jeff Thompson43a57b12013-10-22 16:25:38 -070079 void
80 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070081
Jeff Thompson43a57b12013-10-22 16:25:38 -070082protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070083 Name m_publicKeyName;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070084};
85
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080086inline
87IdentityCertificate::IdentityCertificate()
88{
89}
90
91inline
92IdentityCertificate::IdentityCertificate(const Data& data)
93 : Certificate(data)
94{
95 setPublicKeyName();
96}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070097
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080098inline
99IdentityCertificate::~IdentityCertificate()
100{
101}
102
103inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700104IdentityCertificate::wireDecode(const Block& wire)
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800105{
106 Certificate::wireDecode(wire);
107 setPublicKeyName();
108}
109
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800110inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111IdentityCertificate::setName(const Name& name)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800112{
113 Certificate::setName(name);
114 setPublicKeyName();
115}
116
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700117inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700118IdentityCertificate::getPublicKeyName() const
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800119{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700120 return m_publicKeyName;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800121}
122
Yingdi Yufc40d872014-02-18 12:56:04 -0800123} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700124
Yingdi Yufc40d872014-02-18 12:56:04 -0800125#endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP