blob: 7e19a1eeff24c06bbdf1a8cadaf2f562d8fa3855 [file] [log] [blame]
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -08004 * See COPYING for copyright and distribution information.
5 */
6
Yingdi Yufc40d872014-02-18 12:56:04 -08007#ifndef NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
8#define NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -08009
Yingdi Yu4f324632014-01-15 18:10:03 -080010#include "../data.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080011#include "../encoding/tlv.hpp"
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080012
13namespace ndn {
14
15/**
16 * Representing of SHA256-with-RSA signature in a data packet.
17 */
18class SignatureSha256WithRsa : public Signature {
19public:
20 SignatureSha256WithRsa()
21 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070022 m_info = Block(Tlv::SignatureInfo);
23
24 m_type = Signature::Sha256WithRsa;
25 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
26 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080027 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070028
29 SignatureSha256WithRsa(const Signature& signature)
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080030 : Signature(signature)
31 {
32 if (getType() != Signature::Sha256WithRsa)
33 throw Signature::Error("Incorrect signature type");
34
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070035 m_info.parse();
36 Block::element_const_iterator i = m_info.find(Tlv::KeyLocator);
37 if (i != m_info.elements_end())
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080038 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070039 m_keyLocator.wireDecode(*i);
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080040 }
41 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070042
43 const KeyLocator&
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080044 getKeyLocator() const
45 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070046 return m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080047 }
48
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070049 void
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080050 setKeyLocator(const KeyLocator& keyLocator)
51 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070052 m_keyLocator = keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080053
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070054 m_info.remove(ndn::Tlv::KeyLocator);
55 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080056 }
57
58private:
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070059 KeyLocator m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080060};
61
62} // namespace ndn
63
Yingdi Yufc40d872014-02-18 12:56:04 -080064#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP