blob: 01427d4b0fc92e99831467a419605b8bef1188d2 [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 Thompson04e2cd62013-11-20 19:11:27 -080036 // Note: The copy constructor works because publicKeyName_ has a copy constructor.
37
Jeff Thompsonc69163b2013-10-12 13:49:50 -070038 /**
39 * Create an IdentityCertificate from the content in the data packet.
40 * @param data The data packet with the content to decode.
41 */
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080042 inline
Jeff Thompsonc69163b2013-10-12 13:49:50 -070043 IdentityCertificate(const Data& data);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044
Jeff Thompson965569b2013-10-12 17:52:52 -070045 /**
46 * The virtual destructor.
47 */
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070048 inline virtual
Jeff Thompson965569b2013-10-12 17:52:52 -070049 ~IdentityCertificate();
Alexander Afanasyeve64788e2014-01-05 22:38:21 -080050
51 inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052 wireDecode(const Block& wire);
53
54 inline void
55 setName(const Name& name);
56
57 inline const Name&
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080058 getPublicKeyName () const;
Jeff Thompson965569b2013-10-12 17:52:52 -070059
60 static bool
61 isIdentityCertificate(const Certificate& certificate);
62
Jeff Thompson74942612013-10-24 16:42:32 -070063 /**
64 * Get the public key name from the full certificate name.
65 * @param certificateName The full certificate name.
66 * @return The related public key name.
67 */
68 static Name
69 certificateNameToPublicKeyName(const Name& certificateName);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070070
Jeff Thompson965569b2013-10-12 17:52:52 -070071private:
72 static bool
73 isCorrectName(const Name& name);
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074
Jeff Thompson43a57b12013-10-22 16:25:38 -070075 void
76 setPublicKeyName();
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070077
Jeff Thompson43a57b12013-10-22 16:25:38 -070078protected:
79 Name publicKeyName_;
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -070080};
81
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080082inline
83IdentityCertificate::IdentityCertificate()
84{
85}
86
87inline
88IdentityCertificate::IdentityCertificate(const Data& data)
89 : Certificate(data)
90{
91 setPublicKeyName();
92}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070093
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -080094inline
95IdentityCertificate::~IdentityCertificate()
96{
97}
98
99inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700100IdentityCertificate::wireDecode(const Block& wire)
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800101{
102 Certificate::wireDecode(wire);
103 setPublicKeyName();
104}
105
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800106inline void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700107IdentityCertificate::setName(const Name& name)
Alexander Afanasyeve64788e2014-01-05 22:38:21 -0800108{
109 Certificate::setName(name);
110 setPublicKeyName();
111}
112
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -0700113inline const Name&
Alexander Afanasyevbf1a67a2014-01-05 23:36:13 -0800114IdentityCertificate::getPublicKeyName () const
115{
116 return publicKeyName_;
117}
118
Yingdi Yufc40d872014-02-18 12:56:04 -0800119} // namespace ndn
Jeff Thompsoncf0fdd92013-10-12 11:54:35 -0700120
Yingdi Yufc40d872014-02-18 12:56:04 -0800121#endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP