blob: 34e3c1d9fee45aaade2ac86244d6bbabc758fff0 [file] [log] [blame]
Yingdi Yub263f152015-07-12 16:50:13 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento8aad3722017-09-16 20:57:28 -04002/*
Davide Pesavento794f6872017-05-15 23:33:38 -04003 * Copyright (c) 2013-2017 Regents of the University of California.
Yingdi Yub263f152015-07-12 16:50:13 -07004 *
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_CXX_SECURITY_TRANSFORM_VERIFIER_FILTER_HPP
23#define NDN_CXX_SECURITY_TRANSFORM_VERIFIER_FILTER_HPP
24
25#include "transform-base.hpp"
Yingdi Yub263f152015-07-12 16:50:13 -070026#include "../security-common.hpp"
27
28namespace ndn {
29namespace security {
30namespace transform {
31
Davide Pesavento8aad3722017-09-16 20:57:28 -040032class PublicKey;
33
Yingdi Yub263f152015-07-12 16:50:13 -070034/**
Davide Pesavento8aad3722017-09-16 20:57:28 -040035 * @brief The module to verify signatures.
Yingdi Yub263f152015-07-12 16:50:13 -070036 *
Davide Pesavento8aad3722017-09-16 20:57:28 -040037 * The next module in the chain is usually BoolSink.
Davide Pesavento8a14b9b2017-09-17 01:26:06 -040038 *
39 * @note This module cannot be used to verify HMACs.
Yingdi Yub263f152015-07-12 16:50:13 -070040 */
41class VerifierFilter : public Transform
42{
43public:
44 /**
Davide Pesavento8aad3722017-09-16 20:57:28 -040045 * @brief Create a verifier module to verify signature @p sig using algorithm @p algo and key @p key
Yingdi Yub263f152015-07-12 16:50:13 -070046 */
47 VerifierFilter(DigestAlgorithm algo, const PublicKey& key, const uint8_t* sig, size_t sigLen);
48
Davide Pesavento8aad3722017-09-16 20:57:28 -040049 ~VerifierFilter();
50
Yingdi Yub263f152015-07-12 16:50:13 -070051private:
52 /**
53 * @brief Write data @p buf into verifier
54 *
55 * @return The number of bytes that are actually written
56 */
Davide Pesavento57c07df2016-12-11 18:41:45 -050057 size_t
Yingdi Yub263f152015-07-12 16:50:13 -070058 convert(const uint8_t* buf, size_t size) final;
59
60 /**
61 * @brief Finalize verification and write the result (single byte) into next module.
62 */
Davide Pesavento57c07df2016-12-11 18:41:45 -050063 void
Yingdi Yub263f152015-07-12 16:50:13 -070064 finalize() final;
65
66private:
67 class Impl;
Davide Pesavento794f6872017-05-15 23:33:38 -040068 const unique_ptr<Impl> m_impl;
Yingdi Yub263f152015-07-12 16:50:13 -070069};
70
71unique_ptr<Transform>
72verifierFilter(DigestAlgorithm algo, const PublicKey& key, const uint8_t* sig, size_t sigLen);
73
74} // namespace transform
75} // namespace security
76} // namespace ndn
77
78#endif // NDN_CXX_SECURITY_TRANSFORM_VERIFIER_FILTER_HPP