check.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_PASSHASH_CHECK_HPP
26 #define CRYPTO3_PASSHASH_CHECK_HPP
27 
29 
32 
33 namespace nil {
34  namespace crypto3 {
35  namespace passhash {
51  template<typename Hasher, typename InputIterator, typename OutputIterator>
52  OutputIterator check(InputIterator first, InputIterator last, OutputIterator out) {
53 
54  typedef detail::value_hash_impl<Passhash> PasshashImpl;
55  typedef detail::itr_hash_impl<Hasher, PasshashImpl, OutputIterator> HashImpl;
56 
57  return HashImpl(first, last, std::move(out), Passhash());
58  }
59 
76  template<typename Hasher, typename InputIterator, typename PasshashAccumulator =
78  OutputIterator check(InputIterator first, InputIterator last, PasshashAccumulator &sh) {
79 
80  typedef detail::ref_hash_impl<Passhash> PasshashImpl;
81  typedef detail::itr_hash_impl<Hasher, PasshashImpl, OutputIterator> HashImpl;
82 
83  return HashImpl(first, last, sh);
84  }
85 
98  template<typename Hasher,
99  typename InputIterator,
100  typename Passhash = typename itr_stream_hash_traits<Hasher, InputIterator>::type,
101  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
102  detail::range_hash_impl<Hasher, detail::value_hash_impl<Passhash>> check(InputIterator first,
103  InputIterator last) {
104  typedef detail::value_hash_impl<Passhash> PasshashImpl;
105  typedef detail::range_hash_impl<Hasher, PasshashImpl> HashImpl;
106 
107  return HashImpl(first, last, Passhash());
108  }
109 
123  template<typename Hasher,
124  typename InputIterator,
125  typename Passhash = typename itr_stream_hash_traits<Hasher, InputIterator>::type,
126  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
127  detail::range_hash_impl<Hasher, detail::ref_hash_impl<Passhash>>
128  check(InputIterator first, InputIterator last, Passhash &sh) {
129  typedef detail::ref_hash_impl<Passhash> PasshashImpl;
130  typedef detail::range_hash_impl<Hasher, PasshashImpl> HashImpl;
131 
132  return HashImpl(first, last, sh);
133  }
134 
148  template<typename Hasher,
149  typename SinglePassRange,
150  typename OutputIterator,
151  typename Passhash = typename range_stream_hash_traits<Hasher, SinglePassRange>::type,
152  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
153  OutputIterator check(const SinglePassRange &rng, OutputIterator out) {
154 
155  typedef detail::value_hash_impl<Passhash> PasshashImpl;
156  typedef detail::itr_hash_impl<Hasher, PasshashImpl, OutputIterator> HashImpl;
157 
158  return HashImpl(rng, std::move(out), Passhash());
159  }
160 
175  template<typename Hasher,
176  typename SinglePassRange,
177  typename OutputIterator,
178  typename Passhash = typename range_stream_hash_traits<Hasher, SinglePassRange>::type,
179  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
180  OutputIterator check(const SinglePassRange &rng, OutputIterator out, Passhash &sh) {
181 
182  typedef detail::ref_hash_impl<Passhash> PasshashImpl;
183  typedef detail::itr_hash_impl<Hasher, PasshashImpl, OutputIterator> HashImpl;
184 
185  return HashImpl(rng, std::move(out), sh);
186  }
187 
199  template<typename Hasher,
200  typename SinglePassRange,
201  typename Passhash = typename range_stream_hash_traits<Hasher, SinglePassRange>::type,
202  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
203  detail::range_hash_impl<Hasher, detail::value_hash_impl<Passhash>> check(const SinglePassRange &r) {
204 
205  typedef detail::value_hash_impl<Passhash> PasshashImpl;
206  typedef detail::range_hash_impl<Hasher, PasshashImpl> HashImpl;
207 
208  return HashImpl(r, Passhash());
209  }
210 
223  template<typename Hasher,
224  typename SinglePassRange,
225  typename Passhash = typename range_stream_hash_traits<Hasher, SinglePassRange>::type,
226  typename = typename std::enable_if<detail::is_stream_hash<Passhash>::value>::type>
227  detail::range_hash_impl<Hasher, detail::ref_hash_impl<Passhash>> check(const SinglePassRange &rng,
228  Passhash &sh) {
229  typedef detail::ref_hash_impl<Passhash> PasshashImpl;
230  typedef detail::range_hash_impl<Hasher, PasshashImpl> HashImpl;
231 
232  return HashImpl(rng, sh);
233  }
234  } // namespace passhash
235  } // namespace crypto3
236 } // namespace nil
237 
238 #endif // CRYPTO3_HASH_HPP
OutputIterator check(InputIterator first, InputIterator last, OutputIterator out)
Definition: check.hpp:52
boost::accumulators::accumulator_set< static_digest< Passhash::input_block_bits >, boost::accumulators::features< accumulators::tag::passhash< Passhash > >> accumulator_set
Definition: passhash_state.hpp:44
boost::mpl::apply< AccumulatorSet, tag::passhash< Hash > >::type::result_type passhash(const AccumulatorSet &acc)
Definition: accumulators/passhash.hpp:121
OutputIterator move(const SinglePassRange &rng, OutputIterator result)
Definition: move.hpp:45
Definition: pair.hpp:31