padding_value.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_PK_PAD_SCHEME_VALUE_HPP
27 #define CRYPTO3_PK_PAD_SCHEME_VALUE_HPP
28 
29 #include <type_traits>
30 #include <iterator>
31 
32 #include <boost/assert.hpp>
33 #include <boost/concept_check.hpp>
34 
35 #include <boost/range/concepts.hpp>
36 
37 #include <boost/mpl/front.hpp>
38 #include <boost/mpl/apply.hpp>
39 
42 
43 namespace nil {
44  namespace crypto3 {
45  namespace pubkey {
46  namespace padding {
47  namespace detail {
48  template<typename PaddingAccumulator>
50  typedef PaddingAccumulator accumulator_set_type;
51  typedef typename boost::mpl::front<typename accumulator_set_type::features_type>::type
53 
55  }
56 
58  };
59 
60  template<typename PaddingAccumulator>
62  typedef PaddingAccumulator accumulator_set_type;
63  typedef typename boost::mpl::front<typename accumulator_set_type::features_type>::type
65 
67  accumulator_set(std::forward<accumulator_set_type>(acc)) {
68  }
69 
71  };
72 
73  template<typename PaddingStateImpl>
74  struct range_padding_impl : public PaddingStateImpl {
75  typedef PaddingStateImpl padding_state_impl_type;
76 
77  typedef typename padding_state_impl_type::accumulator_type accumulator_type;
78  typedef typename padding_state_impl_type::accumulator_set_type accumulator_set_type;
79 
80  typedef typename boost::mpl::apply<accumulator_set_type, accumulator_type>::type::result_type
82 
83  template<typename SinglePassRange>
84  range_padding_impl(const SinglePassRange &range, accumulator_set_type &&ise) :
85  PaddingStateImpl(std::forward<accumulator_set_type>(ise)) {
86  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
87 
88  this->accumulator_set(range);
89  }
90 
91  template<typename InputIterator>
92  range_padding_impl(InputIterator first, InputIterator last, accumulator_set_type &&ise) :
93  PaddingStateImpl(std::forward<accumulator_set_type>(ise)) {
94  BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator>));
95 
96  this->accumulator_set(first, ::nil::crypto3::accumulators::iterator_last = last);
97  }
98 
99  template<typename OutputRange>
100  operator OutputRange() const {
101  result_type result =
102  boost::accumulators::extract_result<accumulator_type>(this->accumulator_set);
103  return OutputRange(result.cbegin(), result.cend());
104  }
105 
106  operator result_type() const {
107  return boost::accumulators::extract_result<accumulator_type>(this->accumulator_set);
108  }
109 
110  operator accumulator_set_type &() const {
111  return this->accumulator_set;
112  }
113 
114 #ifdef CRYPTO3_ASCII_STRING_CODEC_OUTPUT
115  template<typename Char, typename CharTraits, typename Alloc>
116  operator std::basic_string<Char, CharTraits, Alloc>() const {
117  return std::to_string(
118  boost::accumulators::extract_result<accumulator_type>(this->accumulator_set));
119  }
120 #endif
121  };
122 
123  template<typename PaddingStateImpl, typename OutputIterator>
124  struct itr_padding_impl : public PaddingStateImpl {
125  private:
126  mutable OutputIterator out;
127 
128  public:
129  typedef PaddingStateImpl padding_state_impl_type;
130 
131  typedef typename padding_state_impl_type::accumulator_type accumulator_type;
132  typedef typename padding_state_impl_type::accumulator_set_type accumulator_set_type;
133 
134  typedef typename boost::mpl::apply<accumulator_set_type, accumulator_type>::type::result_type
136 
137  template<typename SinglePassRange>
138  itr_padding_impl(const SinglePassRange &range, OutputIterator out, accumulator_set_type &&ise) :
139  PaddingStateImpl(std::forward<accumulator_set_type>(ise)), out(std::move(out)) {
140  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
141  BOOST_CONCEPT_ASSERT((boost::OutputIteratorConcept<OutputIterator, result_type>));
142 
143  this->accumulator_set(range);
144  }
145 
146  template<typename InputIterator>
147  itr_padding_impl(InputIterator first, InputIterator last, OutputIterator out,
148  accumulator_set_type &&ise) :
149  PaddingStateImpl(std::forward<accumulator_set_type>(ise)),
150  out(std::move(out)) {
151  BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator>));
152  BOOST_CONCEPT_ASSERT((boost::OutputIteratorConcept<OutputIterator, result_type>));
153 
154  this->accumulator_set(first, ::nil::crypto3::accumulators::iterator_last = last);
155  }
156 
157  operator OutputIterator() const {
158  *out++ = boost::accumulators::extract_result<accumulator_type>(this->accumulator_set);
159  return out;
160  }
161  };
162  } // namespace detail
163  } // namespace padding
164  } // namespace pubkey
165  } // namespace crypto3
166 } // namespace nil
167 
168 #endif // CRYPTO3_CODEC_POSTPROCESSOR_HPP
boost::accumulators::accumulator_set< digest< ProcessingMode::block_bits >, boost::accumulators::features< accumulators::tag::block< ProcessingMode > >, std::size_t > accumulator_set
Accumulator set with pre-defined block cipher accumulator params.
Definition: block/include/nil/crypto3/block/cipher_state.hpp:51
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
boost::mpl::apply< AccumulatorSet, tag::pubkey< ProcessingMode > >::type::result_type pubkey(const AccumulatorSet &acc)
Definition: accumulators/pubkey.hpp:106
Definition: pair.hpp:31
Definition: hash_state.hpp:43
padding_state_impl_type::accumulator_type accumulator_type
Definition: padding_value.hpp:131
itr_padding_impl(const SinglePassRange &range, OutputIterator out, accumulator_set_type &&ise)
Definition: padding_value.hpp:138
padding_state_impl_type::accumulator_set_type accumulator_set_type
Definition: padding_value.hpp:132
PaddingStateImpl padding_state_impl_type
Definition: padding_value.hpp:129
boost::mpl::apply< accumulator_set_type, accumulator_type >::type::result_type result_type
Definition: padding_value.hpp:135
itr_padding_impl(InputIterator first, InputIterator last, OutputIterator out, accumulator_set_type &&ise)
Definition: padding_value.hpp:147
boost::mpl::apply< accumulator_set_type, accumulator_type >::type::result_type result_type
Definition: padding_value.hpp:81
padding_state_impl_type::accumulator_set_type accumulator_set_type
Definition: padding_value.hpp:78
PaddingStateImpl padding_state_impl_type
Definition: padding_value.hpp:75
range_padding_impl(InputIterator first, InputIterator last, accumulator_set_type &&ise)
Definition: padding_value.hpp:92
padding_state_impl_type::accumulator_type accumulator_type
Definition: padding_value.hpp:77
range_padding_impl(const SinglePassRange &range, accumulator_set_type &&ise)
Definition: padding_value.hpp:84
ref_padding_impl(accumulator_set_type &&acc)
Definition: padding_value.hpp:54
boost::mpl::front< typename accumulator_set_type::features_type >::type accumulator_type
Definition: padding_value.hpp:52
accumulator_set_type & accumulator_set
Definition: padding_value.hpp:57
PaddingAccumulator accumulator_set_type
Definition: padding_value.hpp:50
accumulator_set_type accumulator_set
Definition: padding_value.hpp:70
PaddingAccumulator accumulator_set_type
Definition: padding_value.hpp:62
boost::mpl::front< typename accumulator_set_type::features_type >::type accumulator_type
Definition: padding_value.hpp:64
value_padding_impl(accumulator_set_type &&acc)
Definition: padding_value.hpp:66