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 | 04e2cd6 | 2013-11-20 19:11:27 -0800 | [diff] [blame] | 36 | // Note: The copy constructor works because publicKeyName_ has a copy constructor. |
| 37 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Create an IdentityCertificate from the content in the data packet. |
| 40 | * @param data The data packet with the content to decode. |
| 41 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 42 | inline |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 43 | IdentityCertificate(const Data& data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 44 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 45 | /** |
| 46 | * The virtual destructor. |
| 47 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 48 | inline virtual |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 49 | ~IdentityCertificate(); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 50 | |
| 51 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 52 | wireDecode(const Block& wire); |
| 53 | |
| 54 | inline void |
| 55 | setName(const Name& name); |
| 56 | |
| 57 | inline const Name& |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 58 | getPublicKeyName () const; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 59 | |
| 60 | static bool |
| 61 | isIdentityCertificate(const Certificate& certificate); |
| 62 | |
Jeff Thompson | 7494261 | 2013-10-24 16:42:32 -0700 | [diff] [blame] | 63 | /** |
| 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 Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 70 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 71 | private: |
| 72 | static bool |
| 73 | isCorrectName(const Name& name); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 74 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 75 | void |
| 76 | setPublicKeyName(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 77 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 78 | protected: |
| 79 | Name publicKeyName_; |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 82 | inline |
| 83 | IdentityCertificate::IdentityCertificate() |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | inline |
| 88 | IdentityCertificate::IdentityCertificate(const Data& data) |
| 89 | : Certificate(data) |
| 90 | { |
| 91 | setPublicKeyName(); |
| 92 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 94 | inline |
| 95 | IdentityCertificate::~IdentityCertificate() |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 100 | IdentityCertificate::wireDecode(const Block& wire) |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 101 | { |
| 102 | Certificate::wireDecode(wire); |
| 103 | setPublicKeyName(); |
| 104 | } |
| 105 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 106 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 107 | IdentityCertificate::setName(const Name& name) |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 108 | { |
| 109 | Certificate::setName(name); |
| 110 | setPublicKeyName(); |
| 111 | } |
| 112 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 113 | inline const Name& |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 114 | IdentityCertificate::getPublicKeyName () const |
| 115 | { |
| 116 | return publicKeyName_; |
| 117 | } |
| 118 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 119 | } // namespace ndn |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 120 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 121 | #endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |