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 | */ |
| 18 | class SignatureSha256WithRsa : public Signature { |
| 19 | public: |
| 20 | SignatureSha256WithRsa() |
| 21 | { |
| 22 | info_ = Block(Tlv::SignatureInfo); |
| 23 | |
| 24 | type_ = Signature::Sha256WithRsa; |
| 25 | info_.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa)); |
Alexander Afanasyev | e9a66e5 | 2014-01-17 16:07:17 -0800 | [diff] [blame] | 26 | info_.push_back(keyLocator_.wireEncode()); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | SignatureSha256WithRsa(const Signature &signature) |
| 30 | : Signature(signature) |
| 31 | { |
| 32 | if (getType() != Signature::Sha256WithRsa) |
| 33 | throw Signature::Error("Incorrect signature type"); |
| 34 | |
| 35 | info_.parse(); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 36 | Block::element_const_iterator i = info_.find(Tlv::KeyLocator); |
| 37 | if (i != info_.elements_end()) |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 38 | { |
| 39 | keyLocator_.wireDecode(*i); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | const KeyLocator& |
| 44 | getKeyLocator() const |
| 45 | { |
| 46 | return keyLocator_; |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | setKeyLocator(const KeyLocator& keyLocator) |
| 51 | { |
| 52 | keyLocator_ = keyLocator; |
| 53 | |
Alexander Afanasyev | e9a66e5 | 2014-01-17 16:07:17 -0800 | [diff] [blame] | 54 | info_.remove(ndn::Tlv::KeyLocator); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 55 | info_.push_back(keyLocator_.wireEncode()); |
| 56 | } |
| 57 | |
| 58 | private: |
| 59 | KeyLocator keyLocator_; |
| 60 | }; |
| 61 | |
| 62 | } // namespace ndn |
| 63 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 64 | #endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |