blob: f809709be05d00e4df3293e74552c2ae63a58a7d [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 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070018class SignatureSha256WithRsa : public Signature
19{
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -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
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080031 SignatureSha256WithRsa()
32 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070033 m_info = Block(Tlv::SignatureInfo);
34
35 m_type = Signature::Sha256WithRsa;
36 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
37 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080038 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070039
40 SignatureSha256WithRsa(const Signature& signature)
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080041 : Signature(signature)
42 {
43 if (getType() != Signature::Sha256WithRsa)
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070044 throw Error("Incorrect signature type");
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080045
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070046 m_info.parse();
47 Block::element_const_iterator i = m_info.find(Tlv::KeyLocator);
48 if (i != m_info.elements_end())
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080049 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070050 m_keyLocator.wireDecode(*i);
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080051 }
52 }
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070053
54 const KeyLocator&
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080055 getKeyLocator() const
56 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070057 return m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080058 }
59
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070060 void
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080061 setKeyLocator(const KeyLocator& keyLocator)
62 {
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070063 m_keyLocator = keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080064
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070065 m_info.remove(ndn::Tlv::KeyLocator);
66 m_info.push_back(m_keyLocator.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080067 }
68
69private:
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070070 KeyLocator m_keyLocator;
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080071};
72
73} // namespace ndn
74
Yingdi Yufc40d872014-02-18 12:56:04 -080075#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP