blob: fa319664cc58861a3ec9a4d2c735b07d6a4b4405 [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
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 Afanasyevbf1a67a2014-01-05 23:36:13 -080020 struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
21
Jeff Thompsonc69163b2013-10-12 13:49:50 -070022 /**
23 * The default constructor.
24 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080025 inline
26 IdentityCertificate();
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070027
Jeff Thompson04e2cd62013-11-20 19:11:27 -080028 // Note: The copy constructor works because publicKeyName_ has a copy constructor.
29
Jeff Thompsonc69163b2013-10-12 13:49:50 -070030 /**
31 * Create an IdentityCertificate from the content in the data packet.
32 * @param data The data packet with the content to decode.
33 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080034 inline
Jeff Thompsonc69163b2013-10-12 13:49:50 -070035 IdentityCertificate(const Data& data);
Jeff Thompson965569b2013-10-12 17:52:52 -070036
37 /**
38 * The virtual destructor.
39 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080040 inline virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070041 ~IdentityCertificate();
Jeff Thompson173fd432013-10-12 18:16:41 -070042
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080043 inline void
44 wireDecode(const Block &wire);
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080045
46 inline void
47 setName(const Name &name);
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080048
49 inline const Name &
50 getPublicKeyName () const;
Jeff Thompson965569b2013-10-12 17:52:52 -070051
52 static bool
53 isIdentityCertificate(const Certificate& certificate);
54
Jeff Thompson74942612013-10-24 16:42:32 -070055 /**
56 * Get the public key name from the full certificate name.
57 * @param certificateName The full certificate name.
58 * @return The related public key name.
59 */
60 static Name
61 certificateNameToPublicKeyName(const Name& certificateName);
62
Jeff Thompson965569b2013-10-12 17:52:52 -070063private:
64 static bool
65 isCorrectName(const Name& name);
Jeff Thompson43a57b12013-10-22 16:25:38 -070066
67 void
68 setPublicKeyName();
69
70protected:
71 Name publicKeyName_;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070072};
73
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080074inline
75IdentityCertificate::IdentityCertificate()
76{
77}
78
79inline
80IdentityCertificate::IdentityCertificate(const Data& data)
81 : Certificate(data)
82{
83 setPublicKeyName();
84}
85
86inline
87IdentityCertificate::~IdentityCertificate()
88{
89}
90
91inline void
92IdentityCertificate::wireDecode(const Block &wire)
93{
94 Certificate::wireDecode(wire);
95 setPublicKeyName();
96}
97
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080098inline void
99IdentityCertificate::setName(const Name &name)
100{
101 Certificate::setName(name);
102 setPublicKeyName();
103}
104
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800105inline const Name &
106IdentityCertificate::getPublicKeyName () const
107{
108 return publicKeyName_;
109}
110
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700111}
112
113#endif