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