blob: 3935c2ec17a95124be9b293051eafc0664b7ace1 [file] [log] [blame]
Yingdi Yu21157162014-02-28 13:02:34 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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 Yu21157162014-02-28 13:02:34 -080011 */
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
19namespace ndn {
20
21/**
22 * Representing of SHA256 signature in a data packet.
23 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070024class SignatureSha256 : public Signature
25{
Yingdi Yu21157162014-02-28 13:02:34 -080026public:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070027 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 Yu21157162014-02-28 13:02:34 -080037 SignatureSha256()
38 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070039 m_info = Block(Tlv::SignatureInfo);
40
41 m_type = Signature::Sha256;
42 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::DigestSha256));
Yingdi Yu21157162014-02-28 13:02:34 -080043 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070044
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070045 SignatureSha256(const Signature& signature)
Yingdi Yu21157162014-02-28 13:02:34 -080046 : Signature(signature)
47 {
48 if (getType() != Signature::Sha256)
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070049 throw Error("Incorrect signature type");
Yingdi Yu21157162014-02-28 13:02:34 -080050 }
51};
52
53} // namespace ndn
54
55#endif //NDN_SECURITY_SIGNATURE_SHA256_HPP