pubkey/include/nil/crypto3/pubkey/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_PUBKEY_VERIFY_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_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 
41 
43 
44 namespace nil {
45  namespace crypto3 {
46  namespace pubkey {
47  namespace accumulators {
48  namespace impl {
49  // TODO: consider different possible modes (aggregation)
50  template<typename ProcessingMode, typename = void>
51  struct verify_impl;
52 
53  template<typename ProcessingMode>
54  struct verify_impl<ProcessingMode> : boost::accumulators::accumulator_base {
55  protected:
56  typedef ProcessingMode processing_mode_type;
57  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
58  typedef typename processing_mode_type::key_type key_type;
59  typedef typename key_type::signature_type signature_type;
60 
61  public:
62  typedef typename processing_mode_type::result_type result_type;
63 
64  template<typename Args>
65  verify_impl(const Args &args) :
66  key(args[boost::accumulators::sample]),
67  signature(args[::nil::crypto3::accumulators::signature]) {
68  processing_mode_type::init_accumulator(key, acc);
69  }
70 
71  template<typename Args>
72  inline void operator()(const Args &args) {
73  resolve_type(args[boost::accumulators::sample | nullptr],
74  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
75  }
76 
77  inline result_type result(boost::accumulators::dont_care) const {
78  return processing_mode_type::process(key, acc, signature);
79  }
80 
81  protected:
82  //
83  // pop verify
84  //
85  inline void resolve_type(std::nullptr_t, std::nullptr_t) {
86  }
87 
88  template<typename InputRange>
89  inline void resolve_type(const InputRange &range, std::nullptr_t) {
90  processing_mode_type::update(key, acc, range);
91  }
92 
93  template<typename InputIterator>
94  inline void resolve_type(InputIterator first, InputIterator last) {
95  processing_mode_type::update(key, acc, first, last);
96  }
97 
98  inline void resolve_type(const signature_type &new_signature, std::nullptr_t) {
99  signature = new_signature;
100  }
101 
105  };
106  } // namespace impl
107 
108  namespace tag {
109  template<typename ProcessingMode>
110  struct verify : boost::accumulators::depends_on<> {
111  typedef ProcessingMode processing_mode_type;
112 
115 
116  typedef boost::mpl::always<accumulators::impl::verify_impl<processing_mode_type>> impl;
117  };
118  } // namespace tag
119 
120  namespace extract {
121  template<typename ProcessingMode, typename AccumulatorSet>
122  typename boost::mpl::apply<AccumulatorSet, tag::verify<ProcessingMode>>::type::result_type
123  verify(const AccumulatorSet &acc) {
124  return boost::accumulators::extract_result<tag::verify<ProcessingMode>>(acc);
125  }
126  } // namespace extract
127  } // namespace accumulators
128  } // namespace pubkey
129  } // namespace crypto3
130 } // namespace nil
131 
132 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_VERIFY_HPP
boost::mpl::apply< AccumulatorSet, tag::verify< ProcessingMode > >::type::result_type verify(const AccumulatorSet &acc)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:123
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
void resolve_type(std::nullptr_t, std::nullptr_t)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:85
void operator()(const Args &args)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:72
processing_mode_type::key_type key_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:58
internal_accumulator_type acc
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:104
result_type result(boost::accumulators::dont_care) const
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:77
ProcessingMode processing_mode_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:56
key_type key
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:102
key_type::signature_type signature_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:59
processing_mode_type::result_type result_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:62
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:89
void resolve_type(InputIterator first, InputIterator last)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:94
signature_type signature
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:103
verify_impl(const Args &args)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:65
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:57
void resolve_type(const signature_type &new_signature, std::nullptr_t)
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:98
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:51
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:110
boost::mpl::always< accumulators::impl::verify_impl< processing_mode_type > > impl
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:116
ProcessingMode processing_mode_type
Definition: pubkey/include/nil/crypto3/pubkey/accumulators/verify.hpp:111