accumulators/mac.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 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_MAC_HPP
27 #define CRYPTO3_ACCUMULATORS_MAC_HPP
28 
29 #include <boost/parameter/value_type.hpp>
30 
31 #include <boost/accumulators/framework/accumulator_base.hpp>
32 #include <boost/accumulators/framework/extractor.hpp>
33 #include <boost/accumulators/framework/depends_on.hpp>
34 #include <boost/accumulators/framework/parameters/sample.hpp>
35 
37 
38 namespace nil {
39  namespace crypto3 {
40  namespace accumulators {
41  namespace impl {
42  template<typename ProcessingPolicy>
43  struct mac_impl : boost::accumulators::accumulator_base {
44  protected:
45  typedef ProcessingPolicy processing_policy;
46  typedef typename processing_policy::mac_type mac_type;
47  typedef typename processing_policy::key_type key_type;
48  typedef typename processing_policy::internal_accumulator_type internal_accumulator_type;
49 
50  public:
51  typedef typename processing_policy::result_type result_type;
52 
53  template<typename Args>
54  mac_impl(const Args &args) : key(args[boost::accumulators::sample]) {
55  processing_policy::init_accumulator(key, acc);
56  }
57 
58  template<typename ArgumentPack>
59  inline void operator()(const ArgumentPack &args) {
60  resolve_type(args[boost::accumulators::sample],
61  args[::nil::crypto3::accumulators::iterator_last | nullptr]);
62  }
63 
64  inline result_type result(boost::accumulators::dont_care) const {
65  return processing_policy::process(key, acc);
66  }
67 
68  protected:
69  template<typename InputRange, typename InputIterator>
70  inline void resolve_type(const InputRange &range, InputIterator) {
71  processing_policy::update(key, acc, range);
72  }
73 
74  template<typename InputIterator>
75  inline void resolve_type(InputIterator first, InputIterator second) {
76  processing_policy::update(key, acc, first, second);
77  }
78 
81  };
82  } // namespace impl
83 
84  namespace tag {
85  template<typename ProcessingPolicy>
86  struct mac : boost::accumulators::depends_on<> {
87  typedef ProcessingPolicy processing_policy;
88 
91 
92  typedef boost::mpl::always<accumulators::impl::mac_impl<processing_policy>> impl;
93  };
94  } // namespace tag
95 
96  namespace extract {
97  template<typename ProcessingPolicy, typename AccumulatorSet>
98  typename boost::mpl::apply<AccumulatorSet, tag::mac<ProcessingPolicy>>::type::result_type
99  mac(const AccumulatorSet &acc) {
100  return boost::accumulators::extract_result<tag::mac<ProcessingPolicy>>(acc);
101  }
102  } // namespace extract
103  } // namespace accumulators
104  } // namespace crypto3
105 } // namespace nil
106 
107 #endif // CRYPTO3_ACCUMULATORS_MAC_HPP
boost::mpl::apply< AccumulatorSet, tag::mac< ProcessingPolicy > >::type::result_type mac(const AccumulatorSet &acc)
Definition: accumulators/mac.hpp:99
Definition: pair.hpp:31
Definition: accumulators/mac.hpp:43
ProcessingPolicy processing_policy
Definition: accumulators/mac.hpp:45
void resolve_type(InputIterator first, InputIterator second)
Definition: accumulators/mac.hpp:75
internal_accumulator_type acc
Definition: accumulators/mac.hpp:80
void resolve_type(const InputRange &range, InputIterator)
Definition: accumulators/mac.hpp:70
key_type key
Definition: accumulators/mac.hpp:79
processing_policy::result_type result_type
Definition: accumulators/mac.hpp:51
processing_policy::mac_type mac_type
Definition: accumulators/mac.hpp:46
result_type result(boost::accumulators::dont_care) const
Definition: accumulators/mac.hpp:64
processing_policy::internal_accumulator_type internal_accumulator_type
Definition: accumulators/mac.hpp:48
processing_policy::key_type key_type
Definition: accumulators/mac.hpp:47
void operator()(const ArgumentPack &args)
Definition: accumulators/mac.hpp:59
mac_impl(const Args &args)
Definition: accumulators/mac.hpp:54
Definition: accumulators/mac.hpp:86
boost::mpl::always< accumulators::impl::mac_impl< processing_policy > > impl
Definition: accumulators/mac.hpp:92
ProcessingPolicy processing_policy
Definition: accumulators/mac.hpp:87