Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 9 | #ifndef NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |
| 10 | #define NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 12 | #include "../common.hpp" |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 13 | #include "certificate.hpp" |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | class IdentityCertificate : public Certificate |
| 18 | { |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 19 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 20 | 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 Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 29 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 30 | /** |
| 31 | * The default constructor. |
| 32 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 33 | inline |
| 34 | IdentityCertificate(); |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 35 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Create an IdentityCertificate from the content in the data packet. |
| 38 | * @param data The data packet with the content to decode. |
| 39 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 40 | inline |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 41 | IdentityCertificate(const Data& data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 42 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 43 | /** |
| 44 | * The virtual destructor. |
| 45 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 46 | inline virtual |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 47 | ~IdentityCertificate(); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 48 | |
| 49 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 50 | wireDecode(const Block& wire); |
| 51 | |
| 52 | inline void |
| 53 | setName(const Name& name); |
| 54 | |
| 55 | inline const Name& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 56 | getPublicKeyName() const; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 57 | |
| 58 | static bool |
| 59 | isIdentityCertificate(const Certificate& certificate); |
| 60 | |
Jeff Thompson | 7494261 | 2013-10-24 16:42:32 -0700 | [diff] [blame] | 61 | /** |
| 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 Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 68 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 69 | private: |
| 70 | static bool |
| 71 | isCorrectName(const Name& name); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 72 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 73 | void |
| 74 | setPublicKeyName(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 75 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 76 | protected: |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 77 | Name m_publicKeyName; |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 80 | inline |
| 81 | IdentityCertificate::IdentityCertificate() |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | inline |
| 86 | IdentityCertificate::IdentityCertificate(const Data& data) |
| 87 | : Certificate(data) |
| 88 | { |
| 89 | setPublicKeyName(); |
| 90 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 92 | inline |
| 93 | IdentityCertificate::~IdentityCertificate() |
| 94 | { |
| 95 | } |
| 96 | |
| 97 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 98 | IdentityCertificate::wireDecode(const Block& wire) |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 99 | { |
| 100 | Certificate::wireDecode(wire); |
| 101 | setPublicKeyName(); |
| 102 | } |
| 103 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 104 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 105 | IdentityCertificate::setName(const Name& name) |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 106 | { |
| 107 | Certificate::setName(name); |
| 108 | setPublicKeyName(); |
| 109 | } |
| 110 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 111 | inline const Name& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 112 | IdentityCertificate::getPublicKeyName() const |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 113 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 114 | return m_publicKeyName; |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 117 | } // namespace ndn |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 118 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 119 | #endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |