Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 15 | #ifndef NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |
| 16 | #define NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 17 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 18 | #include "../common.hpp" |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 19 | #include "certificate.hpp" |
| 20 | |
| 21 | namespace ndn { |
| 22 | |
| 23 | class IdentityCertificate : public Certificate |
| 24 | { |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 25 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 26 | class Error : public std::runtime_error |
| 27 | { |
| 28 | public: |
| 29 | explicit |
| 30 | Error(const std::string& what) |
| 31 | : std::runtime_error(what) |
| 32 | { |
| 33 | } |
| 34 | }; |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 35 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 36 | /** |
| 37 | * The default constructor. |
| 38 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 39 | inline |
| 40 | IdentityCertificate(); |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Create an IdentityCertificate from the content in the data packet. |
| 44 | * @param data The data packet with the content to decode. |
| 45 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 46 | inline |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 47 | IdentityCertificate(const Data& data); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 49 | /** |
| 50 | * The virtual destructor. |
| 51 | */ |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 52 | inline virtual |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 53 | ~IdentityCertificate(); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 54 | |
| 55 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 56 | wireDecode(const Block& wire); |
| 57 | |
| 58 | inline void |
| 59 | setName(const Name& name); |
| 60 | |
| 61 | inline const Name& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 62 | getPublicKeyName() const; |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 63 | |
| 64 | static bool |
| 65 | isIdentityCertificate(const Certificate& certificate); |
| 66 | |
Jeff Thompson | 7494261 | 2013-10-24 16:42:32 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Get the public key name from the full certificate name. |
| 69 | * @param certificateName The full certificate name. |
| 70 | * @return The related public key name. |
| 71 | */ |
| 72 | static Name |
| 73 | certificateNameToPublicKeyName(const Name& certificateName); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 74 | |
Jeff Thompson | 965569b | 2013-10-12 17:52:52 -0700 | [diff] [blame] | 75 | private: |
| 76 | static bool |
| 77 | isCorrectName(const Name& name); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 78 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 79 | void |
| 80 | setPublicKeyName(); |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 81 | |
Jeff Thompson | 43a57b1 | 2013-10-22 16:25:38 -0700 | [diff] [blame] | 82 | protected: |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 83 | Name m_publicKeyName; |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 86 | inline |
| 87 | IdentityCertificate::IdentityCertificate() |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | inline |
| 92 | IdentityCertificate::IdentityCertificate(const Data& data) |
| 93 | : Certificate(data) |
| 94 | { |
| 95 | setPublicKeyName(); |
| 96 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 97 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 98 | inline |
| 99 | IdentityCertificate::~IdentityCertificate() |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 104 | IdentityCertificate::wireDecode(const Block& wire) |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 105 | { |
| 106 | Certificate::wireDecode(wire); |
| 107 | setPublicKeyName(); |
| 108 | } |
| 109 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 110 | inline void |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 111 | IdentityCertificate::setName(const Name& name) |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 112 | { |
| 113 | Certificate::setName(name); |
| 114 | setPublicKeyName(); |
| 115 | } |
| 116 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 117 | inline const Name& |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 118 | IdentityCertificate::getPublicKeyName() const |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 119 | { |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 120 | return m_publicKeyName; |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 123 | } // namespace ndn |
Jeff Thompson | cf0fdd9 | 2013-10-12 11:54:35 -0700 | [diff] [blame] | 124 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 125 | #endif //NDN_SECURITY_IDENTITY_CERTIFICATE_HPP |