blob: b59c765c13c8fc7cafc0994af9121c11fef8b7ce [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.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_SIGNATURE_SHA256_WITH_RSA_HPP
9#define NDN_SIGNATURE_SHA256_WITH_RSA_HPP
10
Yingdi Yu4f324632014-01-15 18:10:03 -080011#include "../data.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 {
22 info_ = Block(Tlv::SignatureInfo);
23
24 type_ = Signature::Sha256WithRsa;
25 info_.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
Alexander Afanasyeve9a66e52014-01-17 16:07:17 -080026 info_.push_back(keyLocator_.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080027 }
28
29 SignatureSha256WithRsa(const Signature &signature)
30 : Signature(signature)
31 {
32 if (getType() != Signature::Sha256WithRsa)
33 throw Signature::Error("Incorrect signature type");
34
35 info_.parse();
36 Block::element_iterator i = info_.find(Tlv::KeyLocator);
37 if (i != info_.getAll().end())
38 {
39 keyLocator_.wireDecode(*i);
40 }
41 }
42
43 const KeyLocator&
44 getKeyLocator() const
45 {
46 return keyLocator_;
47 }
48
49 void
50 setKeyLocator(const KeyLocator& keyLocator)
51 {
52 keyLocator_ = keyLocator;
53
Alexander Afanasyeve9a66e52014-01-17 16:07:17 -080054 info_.remove(ndn::Tlv::KeyLocator);
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080055 info_.push_back(keyLocator_.wireEncode());
56 }
57
58private:
59 KeyLocator keyLocator_;
60};
61
62} // namespace ndn
63
64#endif