blob: 9200ac5074cbf822ada1262b7c8e9fb5f701ce79 [file] [log] [blame]
Yingdi Yu21157162014-02-28 13:02:34 -08001/* -*- 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
13namespace ndn {
14
15/**
16 * Representing of SHA256 signature in a data packet.
17 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070018class SignatureSha256 : public Signature
19{
Yingdi Yu21157162014-02-28 13:02:34 -080020public:
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070021 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 Yu21157162014-02-28 13:02:34 -080031 SignatureSha256()
32 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070033 m_info = Block(Tlv::SignatureInfo);
34
35 m_type = Signature::Sha256;
36 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::DigestSha256));
Yingdi Yu21157162014-02-28 13:02:34 -080037 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070038
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070039 SignatureSha256(const Signature& signature)
Yingdi Yu21157162014-02-28 13:02:34 -080040 : Signature(signature)
41 {
42 if (getType() != Signature::Sha256)
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070043 throw Error("Incorrect signature type");
Yingdi Yu21157162014-02-28 13:02:34 -080044 }
45};
46
47} // namespace ndn
48
49#endif //NDN_SECURITY_SIGNATURE_SHA256_HPP