Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -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 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_SECURITY_SIGNATURE_SHA256_HPP |
| 8 | #define NDN_SECURITY_SIGNATURE_SHA256_HPP |
| 9 | |
| 10 | #include "../data.hpp" |
| 11 | #include "../encoding/tlv.hpp" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
| 16 | * Representing of SHA256 signature in a data packet. |
| 17 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame^] | 18 | class SignatureSha256 : public Signature |
| 19 | { |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -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 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 31 | SignatureSha256() |
| 32 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 33 | m_info = Block(Tlv::SignatureInfo); |
| 34 | |
| 35 | m_type = Signature::Sha256; |
| 36 | m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::DigestSha256)); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 37 | } |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 39 | SignatureSha256(const Signature& signature) |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 40 | : Signature(signature) |
| 41 | { |
| 42 | if (getType() != Signature::Sha256) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame^] | 43 | throw Error("Incorrect signature type"); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 44 | } |
| 45 | }; |
| 46 | |
| 47 | } // namespace ndn |
| 48 | |
| 49 | #endif //NDN_SECURITY_SIGNATURE_SHA256_HPP |