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. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 8 | #ifndef NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |
| 9 | #define NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 10 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 11 | #include "../data.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 12 | #include "../encoding/tlv.hpp" |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | /** |
| 17 | * Representing of SHA256-with-RSA signature in a data packet. |
| 18 | */ |
| 19 | class SignatureSha256WithRsa : public Signature { |
| 20 | public: |
| 21 | SignatureSha256WithRsa() |
| 22 | { |
| 23 | info_ = Block(Tlv::SignatureInfo); |
| 24 | |
| 25 | type_ = Signature::Sha256WithRsa; |
| 26 | info_.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa)); |
Alexander Afanasyev | e9a66e5 | 2014-01-17 16:07:17 -0800 | [diff] [blame] | 27 | info_.push_back(keyLocator_.wireEncode()); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | SignatureSha256WithRsa(const Signature &signature) |
| 31 | : Signature(signature) |
| 32 | { |
| 33 | if (getType() != Signature::Sha256WithRsa) |
| 34 | throw Signature::Error("Incorrect signature type"); |
| 35 | |
| 36 | info_.parse(); |
Alexander Afanasyev | 29e5c3d | 2014-02-11 00:01:10 -0800 | [diff] [blame] | 37 | Block::element_const_iterator i = info_.find(Tlv::KeyLocator); |
| 38 | if (i != info_.elements_end()) |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 39 | { |
| 40 | keyLocator_.wireDecode(*i); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | const KeyLocator& |
| 45 | getKeyLocator() const |
| 46 | { |
| 47 | return keyLocator_; |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | setKeyLocator(const KeyLocator& keyLocator) |
| 52 | { |
| 53 | keyLocator_ = keyLocator; |
| 54 | |
Alexander Afanasyev | e9a66e5 | 2014-01-17 16:07:17 -0800 | [diff] [blame] | 55 | info_.remove(ndn::Tlv::KeyLocator); |
Alexander Afanasyev | fa13f8e | 2014-01-03 15:19:07 -0800 | [diff] [blame] | 56 | info_.push_back(keyLocator_.wireEncode()); |
| 57 | } |
| 58 | |
| 59 | private: |
| 60 | KeyLocator keyLocator_; |
| 61 | }; |
| 62 | |
| 63 | } // namespace ndn |
| 64 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 65 | #endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP |