blob: 85c8e7231ae3fd3e7f6789f0006230a4a05477c3 [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);
44
45 inline const Name &
46 getPublicKeyName () const;
Jeff Thompson965569b2013-10-12 17:52:52 -070047
48 static bool
49 isIdentityCertificate(const Certificate& certificate);
50
Jeff Thompson74942612013-10-24 16:42:32 -070051 /**
52 * Get the public key name from the full certificate name.
53 * @param certificateName The full certificate name.
54 * @return The related public key name.
55 */
56 static Name
57 certificateNameToPublicKeyName(const Name& certificateName);
58
Jeff Thompson965569b2013-10-12 17:52:52 -070059private:
60 static bool
61 isCorrectName(const Name& name);
Jeff Thompson43a57b12013-10-22 16:25:38 -070062
63 void
64 setPublicKeyName();
65
66protected:
67 Name publicKeyName_;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070068};
69
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080070inline
71IdentityCertificate::IdentityCertificate()
72{
73}
74
75inline
76IdentityCertificate::IdentityCertificate(const Data& data)
77 : Certificate(data)
78{
79 setPublicKeyName();
80}
81
82inline
83IdentityCertificate::~IdentityCertificate()
84{
85}
86
87inline void
88IdentityCertificate::wireDecode(const Block &wire)
89{
90 Certificate::wireDecode(wire);
91 setPublicKeyName();
92}
93
94inline const Name &
95IdentityCertificate::getPublicKeyName () const
96{
97 return publicKeyName_;
98}
99
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700100}
101
102#endif