Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [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. |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef NDN_SECURITY_SIGNATURE_SHA256_HPP |
| 14 | #define NDN_SECURITY_SIGNATURE_SHA256_HPP |
| 15 | |
| 16 | #include "../data.hpp" |
| 17 | #include "../encoding/tlv.hpp" |
| 18 | |
| 19 | namespace ndn { |
| 20 | |
| 21 | /** |
| 22 | * Representing of SHA256 signature in a data packet. |
| 23 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 24 | class SignatureSha256 : public Signature |
| 25 | { |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 26 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 27 | class Error : public Signature::Error |
| 28 | { |
| 29 | public: |
| 30 | explicit |
| 31 | Error(const std::string& what) |
| 32 | : Signature::Error(what) |
| 33 | { |
| 34 | } |
| 35 | }; |
| 36 | |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 37 | SignatureSha256() |
| 38 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 39 | m_info = Block(Tlv::SignatureInfo); |
| 40 | |
| 41 | m_type = Signature::Sha256; |
| 42 | m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::DigestSha256)); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 43 | } |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 45 | SignatureSha256(const Signature& signature) |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 46 | : Signature(signature) |
| 47 | { |
| 48 | if (getType() != Signature::Sha256) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 49 | throw Error("Incorrect signature type"); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 50 | } |
| 51 | }; |
| 52 | |
| 53 | } // namespace ndn |
| 54 | |
| 55 | #endif //NDN_SECURITY_SIGNATURE_SHA256_HPP |