accumulators/sign.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_SIGN_HPP
27 #define CRYPTO3_ACCUMULATORS_PUBKEY_SIGN_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 
42 
43 namespace nil {
44  namespace crypto3 {
45  namespace pubkey {
46  namespace accumulators {
47  namespace impl {
48  template<typename ProcessingMode, typename = void>
49  struct sign_impl;
50 
51  template<typename ProcessingMode>
52  struct sign_impl<ProcessingMode> : boost::accumulators::accumulator_base {
53  protected:
54  typedef ProcessingMode processing_mode_type;
55  typedef typename processing_mode_type::key_type key_type;
56  typedef typename processing_mode_type::internal_accumulator_type internal_accumulator_type;
57 
58  public:
59  typedef typename processing_mode_type::result_type result_type;
60 
61  template<typename Args>
62  sign_impl(const Args &args) : key(args[boost::accumulators::sample]) {
63  processing_mode_type::init_accumulator(key, acc);
64  }
65 
66  template<typename Args>
67  inline void operator()(const Args &args) {
68  resolve_type(args[boost::accumulators::sample | nullptr],
69  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
70  }
71 
72  inline result_type result(boost::accumulators::dont_care) const {
73  return processing_mode_type::process(key, acc);
74  }
75 
76  protected:
77  //
78  // pop prove
79  //
80  inline void resolve_type(std::nullptr_t, std::nullptr_t) {
81  }
82 
83  template<typename InputRange>
84  inline void resolve_type(const InputRange &range, std::nullptr_t) {
85  processing_mode_type::update(key, acc, range);
86  }
87 
88  template<typename InputIterator>
89  inline void resolve_type(InputIterator first, InputIterator last) {
90  processing_mode_type::update(key, acc, first, last);
91  }
92 
95  };
96  } // namespace impl
97 
98  namespace tag {
99  template<typename ProcessingMode>
100  struct sign : boost::accumulators::depends_on<> {
101  typedef ProcessingMode processing_mode_type;
102 
105 
106  typedef boost::mpl::always<accumulators::impl::sign_impl<processing_mode_type>> impl;
107  };
108  } // namespace tag
109 
110  namespace extract {
111  template<typename ProcessingMode, typename AccumulatorSet>
112  typename boost::mpl::apply<AccumulatorSet, tag::sign<ProcessingMode>>::type::result_type
113  sign(const AccumulatorSet &acc) {
114  return boost::accumulators::extract_result<tag::sign<ProcessingMode>>(acc);
115  }
116  } // namespace extract
117  } // namespace accumulators
118  } // namespace pubkey
119  } // namespace crypto3
120 } // namespace nil
121 
122 #endif // CRYPTO3_ACCUMULATORS_PUBKEY_SIGN_HPP
boost::mpl::apply< AccumulatorSet, tag::sign< ProcessingMode > >::type::result_type sign(const AccumulatorSet &acc)
Definition: accumulators/sign.hpp:113
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: accumulators/sign.hpp:80
ProcessingMode processing_mode_type
Definition: accumulators/sign.hpp:54
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/sign.hpp:72
sign_impl(const Args &args)
Definition: accumulators/sign.hpp:62
void operator()(const Args &args)
Definition: accumulators/sign.hpp:67
internal_accumulator_type acc
Definition: accumulators/sign.hpp:94
processing_mode_type::key_type key_type
Definition: accumulators/sign.hpp:55
processing_mode_type::internal_accumulator_type internal_accumulator_type
Definition: accumulators/sign.hpp:56
void resolve_type(InputIterator first, InputIterator last)
Definition: accumulators/sign.hpp:89
void resolve_type(const InputRange &range, std::nullptr_t)
Definition: accumulators/sign.hpp:84
processing_mode_type::result_type result_type
Definition: accumulators/sign.hpp:59
Definition: accumulators/sign.hpp:49
Definition: accumulators/sign.hpp:100
boost::mpl::always< accumulators::impl::sign_impl< processing_mode_type > > impl
Definition: accumulators/sign.hpp:106
ProcessingMode processing_mode_type
Definition: accumulators/sign.hpp:101