blob: 7c3915b0a2c449a005561c622c48b7e5c0317aed [file] [log] [blame]
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompsonc69163b2013-10-12 13:49:50 -07004 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -07005 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Yingdi Yufc40d872014-02-18 12:56:04 -08009#ifndef NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
10#define NDN_SECURITY_IDENTITY_CERTIFICATE_HPP
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070011
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080012#include "../common.hpp"
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070013#include "certificate.hpp"
14
15namespace ndn {
16
17class IdentityCertificate : public Certificate
18{
Jeff Thompsonc69163b2013-10-12 13:49:50 -070019public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070020 class Error : public std::runtime_error
21 {
22 public:
23 explicit
24 Error(const std::string& what)
25 : std::runtime_error(what)
26 {
27 }
28 };
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080029
Jeff Thompsonc69163b2013-10-12 13:49:50 -070030 /**
31 * The default constructor.
32 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080033 inline
34 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070035
Jeff Thompsonc69163b2013-10-12 13:49:50 -070036 /**
37 * Create an IdentityCertificate from the content in the data packet.
38 * @param data The data packet with the content to decode.
39 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080040 inline
Jeff Thompsonc69163b2013-10-12 13:49:50 -070041 IdentityCertificate(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070042
Jeff Thompson965569b2013-10-12 17:52:52 -070043 /**
44 * The virtual destructor.
45 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 inline virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070047 ~IdentityCertificate();
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080048
49 inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050 wireDecode(const Block& wire);
51
52 inline void
53 setName(const Name& name);
54
55 inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070056 getPublicKeyName() const;
Jeff Thompson965569b2013-10-12 17:52:52 -070057
58 static bool
59 isIdentityCertificate(const Certificate& certificate);
60
Jeff Thompson74942612013-10-24 16:42:32 -070061 /**
62 * Get the public key name from the full certificate name.
63 * @param certificateName The full certificate name.
64 * @return The related public key name.
65 */
66 static Name
67 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068
Jeff Thompson965569b2013-10-12 17:52:52 -070069private:
70 static bool
71 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070072
Jeff Thompson43a57b12013-10-22 16:25:38 -070073 void
74 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070075
Jeff Thompson43a57b12013-10-22 16:25:38 -070076protected:
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070077 Name m_publicKeyName;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070078};
79
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080080inline
81IdentityCertificate::IdentityCertificate()
82{
83}
84
85inline
86IdentityCertificate::IdentityCertificate(const Data& data)
87 : Certificate(data)
88{
89 setPublicKeyName();
90}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070091
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080092inline
93IdentityCertificate::~IdentityCertificate()
94{
95}
96
97inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070098IdentityCertificate::wireDecode(const Block& wire)
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080099{
100 Certificate::wireDecode(wire);
101 setPublicKeyName();
102}
103
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800104inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700105IdentityCertificate::setName(const Name& name)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800106{
107 Certificate::setName(name);
108 setPublicKeyName();
109}
110
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700111inline const Name&
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700112IdentityCertificate::getPublicKeyName() const
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800113{
Yingdi Yu4b8c6a22014-04-15 23:00:54 -0700114 return m_publicKeyName;
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800115}
116
Yingdi Yufc40d872014-02-18 12:56:04 -0800117} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700118
Yingdi Yufc40d872014-02-18 12:56:04 -0800119#endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP