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 | |
| 9 | #ifndef NDN_IDENTITY_CERTIFICATE_HPP |
Jeff Thompson | e589c3f | 2013-10-12 17:30:50 -0700 | [diff] [blame] | 10 | #define NDN_IDENTITY_CERTIFICATE_HPP |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 11 | |
| 12 | #include "certificate.hpp" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | class IdentityCertificate : public Certificate |
| 17 | { |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 18 | public: |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 19 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 20 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 21 | /** |
| 22 | * The default constructor. |
| 23 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 24 | inline |
| 25 | IdentityCertificate(); |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 26 | |
Jeff Thompson | 04e2cd6 | 2013-11-20 19:11:27 -0800 | [diff] [blame] | 27 | // Note: The copy constructor works because publicKeyName_ has a copy constructor. |
| 28 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Create an IdentityCertificate from the content in the data packet. |
| 31 | * @param data The data packet with the content to decode. |
| 32 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 33 | inline |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 34 | IdentityCertificate(const Data& data); |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * The virtual destructor. |
| 38 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 39 | inline virtual |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 40 | ~IdentityCertificate(); |
Jeff Thompson | 173fd43 | 2013-10-12 18:16:41 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 42 | inline void |
| 43 | wireDecode(const Block &wire); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 44 | |
| 45 | inline void |
| 46 | setName(const Name &name); |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 47 | |
| 48 | inline const Name & |
| 49 | getPublicKeyName () const; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 50 | |
| 51 | static bool |
| 52 | isIdentityCertificate(const Certificate& certificate); |
| 53 | |
Jeff Thompson | 7494261 | 2013-10-24 16:42:32 -0700 | [diff] [blame] | 54 | /** |
| 55 | * Get the public key name from the full certificate name. |
| 56 | * @param certificateName The full certificate name. |
| 57 | * @return The related public key name. |
| 58 | */ |
| 59 | static Name |
| 60 | certificateNameToPublicKeyName(const Name& certificateName); |
| 61 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 62 | private: |
| 63 | static bool |
| 64 | isCorrectName(const Name& name); |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 65 | |
| 66 | void |
| 67 | setPublicKeyName(); |
| 68 | |
| 69 | protected: |
| 70 | Name publicKeyName_; |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 73 | inline |
| 74 | IdentityCertificate::IdentityCertificate() |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | inline |
| 79 | IdentityCertificate::IdentityCertificate(const Data& data) |
| 80 | : Certificate(data) |
| 81 | { |
| 82 | setPublicKeyName(); |
| 83 | } |
| 84 | |
| 85 | inline |
| 86 | IdentityCertificate::~IdentityCertificate() |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | inline void |
| 91 | IdentityCertificate::wireDecode(const Block &wire) |
| 92 | { |
| 93 | Certificate::wireDecode(wire); |
| 94 | setPublicKeyName(); |
| 95 | } |
| 96 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 97 | inline void |
| 98 | IdentityCertificate::setName(const Name &name) |
| 99 | { |
| 100 | Certificate::setName(name); |
| 101 | setPublicKeyName(); |
| 102 | } |
| 103 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 104 | inline const Name & |
| 105 | IdentityCertificate::getPublicKeyName () const |
| 106 | { |
| 107 | return publicKeyName_; |
| 108 | } |
| 109 | |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | #endif |