blob: 65b07afe8dcfcbd63f890666a82a5ac3fb72597b [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
9#ifndef NDN_IDENTITY_CERTIFICATE_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -070010#define NDN_IDENTITY_CERTIFICATE_HPP
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070011
12#include "certificate.hpp"
13
14namespace ndn {
15
16class IdentityCertificate : public Certificate
17{
Jeff Thompsonc69163b2013-10-12 13:49:50 -070018public:
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080019 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
20
Jeff Thompsonc69163b2013-10-12 13:49:50 -070021 /**
22 * The default constructor.
23 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080024 inline
25 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070026
Jeff Thompson04e2cd62013-11-20 19:11:27 -080027 // Note: The copy constructor works because publicKeyName_ has a copy constructor.
28
Jeff Thompsonc69163b2013-10-12 13:49:50 -070029 /**
30 * Create an IdentityCertificate from the content in the data packet.
31 * @param data The data packet with the content to decode.
32 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080033 inline
Jeff Thompsonc69163b2013-10-12 13:49:50 -070034 IdentityCertificate(const Data& data);
Jeff Thompson965569b2013-10-12 17:52:52 -070035
36 /**
37 * The virtual destructor.
38 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080039 inline virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070040 ~IdentityCertificate();
Jeff Thompson173fd432013-10-12 18:16:41 -070041
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080042 inline void
43 wireDecode(const Block &wire);
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080044
45 inline void
46 setName(const Name &name);
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080047
48 inline const Name &
49 getPublicKeyName () const;
Jeff Thompson965569b2013-10-12 17:52:52 -070050
51 static bool
52 isIdentityCertificate(const Certificate& certificate);
53
Jeff Thompson74942612013-10-24 16:42:32 -070054 /**
55 * Get the public key name from the full certificate name.
56 * @param certificateName The full certificate name.
57 * @return The related public key name.
58 */
59 static Name
60 certificateNameToPublicKeyName(const Name& certificateName);
61
Jeff Thompson965569b2013-10-12 17:52:52 -070062private:
63 static bool
64 isCorrectName(const Name& name);
Jeff Thompson43a57b12013-10-22 16:25:38 -070065
66 void
67 setPublicKeyName();
68
69protected:
70 Name publicKeyName_;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070071};
72
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080073inline
74IdentityCertificate::IdentityCertificate()
75{
76}
77
78inline
79IdentityCertificate::IdentityCertificate(const Data& data)
80 : Certificate(data)
81{
82 setPublicKeyName();
83}
84
85inline
86IdentityCertificate::~IdentityCertificate()
87{
88}
89
90inline void
91IdentityCertificate::wireDecode(const Block &wire)
92{
93 Certificate::wireDecode(wire);
94 setPublicKeyName();
95}
96
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080097inline void
98IdentityCertificate::setName(const Name &name)
99{
100 Certificate::setName(name);
101 setPublicKeyName();
102}
103
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800104inline const Name &
105IdentityCertificate::getPublicKeyName () const
106{
107 return publicKeyName_;
108}
109
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700110}
111
112#endif