blob: a26c4cad4ad677e1e8dfde3b9b330c6cf1a3b399 [file] [log] [blame]
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -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.
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080011 */
12
Yingdi Yufc40d872014-02-18 12:56:04 -080013#ifndef NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
14#define NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080015
Yingdi Yu4f324632014-01-15 18:10:03 -080016#include "../data.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080017#include "../encoding/tlv.hpp"
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080018
19namespace ndn {
20
21/**
22 * Representing of SHA256-with-RSA signature in a data packet.
23 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070024class SignatureSha256WithRsa : public Signature
25{
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -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
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080037 SignatureSha256WithRsa()
38 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070039 m_info = Block(Tlv::SignatureInfo);
40
41 m_type = Signature::Sha256WithRsa;
42 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
43 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080044 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070045
46 SignatureSha256WithRsa(const Signature& signature)
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080047 : Signature(signature)
48 {
49 if (getType() != Signature::Sha256WithRsa)
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070050 throw Error("Incorrect signature type");
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080051
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070052 m_info.parse();
53 Block::element_const_iterator i = m_info.find(Tlv::KeyLocator);
54 if (i != m_info.elements_end())
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080055 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070056 m_keyLocator.wireDecode(*i);
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080057 }
58 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070059
60 const KeyLocator&
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080061 getKeyLocator() const
62 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070063 return m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080064 }
65
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070066 void
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080067 setKeyLocator(const KeyLocator& keyLocator)
68 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070069 m_keyLocator = keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080070
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070071 m_info.remove(ndn::Tlv::KeyLocator);
72 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080073 }
74
75private:
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070076 KeyLocator m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080077};
78
79} // namespace ndn
80
Yingdi Yufc40d872014-02-18 12:56:04 -080081#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP