Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 7 | #ifndef NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |
| 8 | #define NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 9 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 10 | #include "../data.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 11 | #include "../encoding/tlv.hpp" |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
| 16 | * Representing of SHA256-with-RSA signature in a data packet. |
| 17 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame^] | 18 | class SignatureSha256WithRsa : public Signature |
| 19 | { |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 20 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame^] | 21 | class Error : public Signature::Error |
| 22 | { |
| 23 | public: |
| 24 | explicit |
| 25 | Error(const std::string& what) |
| 26 | : Signature::Error(what) |
| 27 | { |
| 28 | } |
| 29 | }; |
| 30 | |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 31 | SignatureSha256WithRsa() |
| 32 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 33 | m_info = Block(Tlv::SignatureInfo); |
| 34 | |
| 35 | m_type = Signature::Sha256WithRsa; |
| 36 | m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa)); |
| 37 | m_info.push_back(m_keyLocator.wireEncode()); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 38 | } |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 39 | |
| 40 | SignatureSha256WithRsa(const Signature& signature) |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 41 | : Signature(signature) |
| 42 | { |
| 43 | if (getType() != Signature::Sha256WithRsa) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame^] | 44 | throw Error("Incorrect signature type"); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 46 | m_info.parse(); |
| 47 | Block::element_const_iterator i = m_info.find(Tlv::KeyLocator); |
| 48 | if (i != m_info.elements_end()) |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 49 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 50 | m_keyLocator.wireDecode(*i); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 51 | } |
| 52 | } |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 53 | |
| 54 | const KeyLocator& |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 55 | getKeyLocator() const |
| 56 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 57 | return m_keyLocator; |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 60 | void |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 61 | setKeyLocator(const KeyLocator& keyLocator) |
| 62 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 63 | m_keyLocator = keyLocator; |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 65 | m_info.remove(ndn::Tlv::KeyLocator); |
| 66 | m_info.push_back(m_keyLocator.wireEncode()); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private: |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 70 | KeyLocator m_keyLocator; |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace ndn |
| 74 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 75 | #endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |