pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2021 Ilias Khairullin <ilias@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ACCUMULATORS_PK_PAD_VERIFY_HPP
27 #define CRYPTO3_ACCUMULATORS_PK_PAD_VERIFY_HPP
28 
29 #include <iterator>
30 #include <type_traits>
31 
32 #include <boost/parameter/value_type.hpp>
33 
34 #include <boost/accumulators/framework/accumulator_base.hpp>
35 #include <boost/accumulators/framework/extractor.hpp>
36 #include <boost/accumulators/framework/depends_on.hpp>
37 #include <boost/accumulators/framework/parameters/sample.hpp>
38 
40 
41 namespace nil {
42  namespace crypto3 {
43  namespace pubkey {
44  namespace padding {
45  namespace accumulators {
46  namespace impl {
47  template<typename ProcessingPolicy, typename = void>
48  struct verify_impl;
49 
50  template<typename ProcessingPolicy>
51  struct verify_impl<ProcessingPolicy> : boost::accumulators::accumulator_base {
52  protected:
53  typedef ProcessingPolicy processing_policy;
54  typedef typename processing_policy::msg_repr_type msg_repr_type;
55  typedef typename processing_policy::internal_accumulator_type internal_accumulator_type;
56 
57  public:
58  typedef typename processing_policy::result_type result_type;
59 
60  template<typename Args>
61  verify_impl(const Args &args) : msg_repr(args[boost::accumulators::sample]) {
62  }
63 
64  template<typename Args>
65  inline void operator()(const Args &args) {
66  resolve_type(args[boost::accumulators::sample],
67  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
68  }
69 
70  inline result_type result(boost::accumulators::dont_care) const {
71  return processing_policy::process(acc, msg_repr);
72  }
73 
74  protected:
75  template<typename InputRange, typename InputIterator>
76  inline void resolve_type(const InputRange &range, InputIterator) {
77  processing_policy::update(acc, range);
78  }
79 
80  template<typename InputIterator>
81  inline void resolve_type(InputIterator first, InputIterator last) {
82  processing_policy::update(acc, first, last);
83  }
84 
87  };
88  } // namespace impl
89 
90  namespace tag {
91  template<typename ProcessingPolicy>
92  struct verify : boost::accumulators::depends_on<> {
93  typedef ProcessingPolicy processing_policy;
94 
97 
98  typedef boost::mpl::always<accumulators::impl::verify_impl<processing_policy>> impl;
99  };
100  } // namespace tag
101 
102  namespace extract {
103  template<typename ProcessingPolicy, typename AccumulatorSet>
104  typename boost::mpl::apply<AccumulatorSet, tag::verify<ProcessingPolicy>>::type::result_type
105  verify(const AccumulatorSet &acc) {
106  return boost::accumulators::extract_result<tag::verify<ProcessingPolicy>>(acc);
107  }
108  } // namespace extract
109  } // namespace accumulators
110  } // namespace padding
111  } // namespace pubkey
112  } // namespace crypto3
113 } // namespace nil
114 
115 #endif // CRYPTO3_ACCUMULATORS_PK_PAD_VERIFY_HPP
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
boost::mpl::apply< AccumulatorSet, tag::verify< ProcessingPolicy > >::type::result_type verify(const AccumulatorSet &acc)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:105
Definition: pair.hpp:31
void operator()(const Args &args)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:65
processing_policy::internal_accumulator_type internal_accumulator_type
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:55
void resolve_type(InputIterator first, InputIterator last)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:81
processing_policy::msg_repr_type msg_repr_type
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:54
msg_repr_type msg_repr
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:85
verify_impl(const Args &args)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:61
internal_accumulator_type acc
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:86
ProcessingPolicy processing_policy
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:53
processing_policy::result_type result_type
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:58
result_type result(boost::accumulators::dont_care) const
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:70
void resolve_type(const InputRange &range, InputIterator)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:76
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:48
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:92
ProcessingPolicy processing_policy
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:93
boost::mpl::always< accumulators::impl::verify_impl< processing_policy > > impl
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/verify.hpp:98