blob: abaa85af63ca3fad759d892d2cc95f9beb86a66b [file] [log] [blame]
Yingdi Yuebfa4cb2014-06-17 15:28:53 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_SECURITY_SIGNATURE_WITH_PUBLIC_KEY_HPP
23#define NDN_SECURITY_SIGNATURE_WITH_PUBLIC_KEY_HPP
24
25#include "../data.hpp"
26#include "../encoding/tlv.hpp"
27
28namespace ndn {
29
30/**
31 * Base class of public key signature.
32 */
33class SignatureWithPublicKey : public Signature
34{
35public:
36 class Error : public Signature::Error
37 {
38 public:
39 explicit
40 Error(const std::string& what)
41 : Signature::Error(what)
42 {
43 }
44 };
45
46 explicit
47 SignatureWithPublicKey(const Tlv::SignatureTypeValue& signatureType)
48 {
49 m_info = Block(Tlv::SignatureInfo);
50
51 m_type = signatureType;
52 m_info.push_back(nonNegativeIntegerBlock(Tlv::SignatureType, signatureType));
53 m_info.push_back(m_keyLocator.wireEncode());
54 }
55
56 explicit
57 SignatureWithPublicKey(const Signature& signature)
58 : Signature(signature)
59 {
60 m_info.parse();
61 Block::element_const_iterator i = m_info.find(Tlv::KeyLocator);
62 if (i != m_info.elements_end())
63 {
64 m_keyLocator.wireDecode(*i);
65 }
66 }
67
68 const KeyLocator&
69 getKeyLocator() const
70 {
71 return m_keyLocator;
72 }
73
74 void
75 setKeyLocator(const KeyLocator& keyLocator)
76 {
77 m_keyLocator = keyLocator;
78
79 m_info.remove(ndn::Tlv::KeyLocator);
80 m_info.push_back(m_keyLocator.wireEncode());
81 }
82
83private:
84 KeyLocator m_keyLocator;
85};
86
87} // namespace ndn
88
89#endif //NDN_SECURITY_SIGNATURE_WITH_PUBLIC_KEY_HPP