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