blob: c9db4a33e3f5f3fda76f914bdf706a2f1d992107 [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
Yingdi Yufc40d872014-02-18 12:56:04 -08008#ifndef NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
9#define NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080010
Yingdi Yu4f324632014-01-15 18:10:03 -080011#include "../data.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080012#include "../encoding/tlv.hpp"
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080013
14namespace ndn {
15
16/**
17 * Representing of SHA256-with-RSA signature in a data packet.
18 */
19class SignatureSha256WithRsa : public Signature {
20public:
21 SignatureSha256WithRsa()
22 {
23 info_ = Block(Tlv::SignatureInfo);
24
25 type_ = Signature::Sha256WithRsa;
26 info_.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, Tlv::SignatureSha256WithRsa));
Alexander Afanasyeve9a66e52014-01-17 16:07:17 -080027 info_.push_back(keyLocator_.wireEncode());
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080028 }
29
30 SignatureSha256WithRsa(const Signature &signature)
31 : Signature(signature)
32 {
33 if (getType() != Signature::Sha256WithRsa)
34 throw Signature::Error("Incorrect signature type");
35
36 info_.parse();
Alexander Afanasyev29e5c3d2014-02-11 00:01:10 -080037 Block::element_const_iterator i = info_.find(Tlv::KeyLocator);
38 if (i != info_.elements_end())
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080039 {
40 keyLocator_.wireDecode(*i);
41 }
42 }
43
44 const KeyLocator&
45 getKeyLocator() const
46 {
47 return keyLocator_;
48 }
49
50 void
51 setKeyLocator(const KeyLocator& keyLocator)
52 {
53 keyLocator_ = keyLocator;
54
Alexander Afanasyeve9a66e52014-01-17 16:07:17 -080055 info_.remove(ndn::Tlv::KeyLocator);
Alexander Afanasyevfa13f8e2014-01-03 15:19:07 -080056 info_.push_back(keyLocator_.wireEncode());
57 }
58
59private:
60 KeyLocator keyLocator_;
61};
62
63} // namespace ndn
64
Yingdi Yufc40d872014-02-18 12:56:04 -080065#endif //NDN_SECURITY_SIGNATURE_SHA256_WITH_RSA_HPP