pkpad/include/nil/crypto3/pkpad/accumulators/encode.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_ENCODE_HPP
27 #define CRYPTO3_ACCUMULATORS_PK_PAD_ENCODE_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 encode_impl;
49 
50  // TODO: maybe add dependant hash accumulator instead manually work with it inside
51  template<typename ProcessingPolicy>
52  struct encode_impl<ProcessingPolicy> : boost::accumulators::accumulator_base {
53  protected:
54  typedef ProcessingPolicy processing_policy;
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  encode_impl(const Args &args) {
62  processing_policy::init_accumulator(acc);
63  }
64 
65  template<typename Args>
66  inline void operator()(const Args &args) {
67  resolve_type(args[boost::accumulators::sample],
68  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
69  }
70 
71  inline result_type result(boost::accumulators::dont_care) const {
72  return processing_policy::process(acc);
73  }
74 
75  protected:
76  template<typename InputRange, typename InputIterator>
77  inline void resolve_type(const InputRange &range, InputIterator) {
78  processing_policy::update(acc, range);
79  }
80 
81  template<typename InputIterator>
82  inline void resolve_type(InputIterator first, InputIterator last) {
83  processing_policy::update(acc, first, last);
84  }
85 
87  };
88  } // namespace impl
89 
90  namespace tag {
91  template<typename ProcessingPolicy>
92  struct encode : boost::accumulators::depends_on<> {
93  typedef ProcessingPolicy processing_policy;
94 
97 
98  typedef boost::mpl::always<accumulators::impl::encode_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::encode<ProcessingPolicy>>::type::result_type
105  encode(const AccumulatorSet &acc) {
106  return boost::accumulators::extract_result<tag::encode<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_ENCODE_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::encode< ProcessingPolicy > >::type::result_type encode(const AccumulatorSet &acc)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:105
Definition: pair.hpp:31
encode_impl(const Args &args)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:61
internal_accumulator_type acc
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:86
void resolve_type(const InputRange &range, InputIterator)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:77
ProcessingPolicy processing_policy
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:54
void resolve_type(InputIterator first, InputIterator last)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:82
processing_policy::internal_accumulator_type internal_accumulator_type
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:55
void operator()(const Args &args)
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:66
result_type result(boost::accumulators::dont_care) const
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:71
processing_policy::result_type result_type
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:58
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:48
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:92
boost::mpl::always< accumulators::impl::encode_impl< processing_policy > > impl
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:98
ProcessingPolicy processing_policy
Definition: pkpad/include/nil/crypto3/pkpad/accumulators/encode.hpp:93