pkpad/include/nil/crypto3/detail/strxor.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2020-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-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_DETAIL_STRXOR_HPP
27 #define CRYPTO3_DETAIL_STRXOR_HPP
28 
29 #include <iterator>
30 
31 #include <boost/concept/assert.hpp>
32 #include <boost/assert.hpp>
33 #include <boost/range/concepts.hpp>
34 
35 namespace nil {
36  namespace crypto3 {
37  namespace detail {
38  template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
39  constexpr inline typename std::enable_if<
40  std::is_same<typename std::iterator_traits<InputIterator1>::value_type,
41  typename std::iterator_traits<InputIterator2>::value_type>::value &&
42  std::is_same<typename std::iterator_traits<InputIterator1>::value_type,
43  typename std::iterator_traits<OutputIterator>::value_type>::value,
44  OutputIterator>::type
45  strxor(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
46  OutputIterator out) {
47  BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator1>));
48  BOOST_CONCEPT_ASSERT((boost::InputIteratorConcept<InputIterator2>));
49  BOOST_CONCEPT_ASSERT(
50  (boost::OutputIteratorConcept<OutputIterator,
51  typename std::iterator_traits<OutputIterator>::value_type>));
52 
53  assert(std::distance(first1, last1) == std::distance(first2, last2));
54 
55  for (; first1 != last1 && first2 != last2; first1++, first2++, out++) {
56  *out = *first1 ^ *first2;
57  }
58 
59  return out;
60  }
61 
62  template<typename InputRange1, typename InputRange2, typename OutputIterator>
63  constexpr inline OutputIterator strxor(const InputRange1 &in1, const InputRange2 &in2, OutputIterator out) {
64  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<InputRange1>));
65  BOOST_CONCEPT_ASSERT((boost::SinglePassRangeConcept<InputRange2>));
66 
67  return strxor(in1.cbegin(), in1.cend(), in2.cbegin(), in2.cend(), out);
68  }
69  } // namespace detail
70  } // namespace crypto3
71 } // namespace nil
72 
73 #endif // CRYPTO3_DETAIL_STRXOR_HPP
constexpr std::enable_if< std::is_same< typename std::iterator_traits< InputIterator1 >::value_type, typename std::iterator_traits< InputIterator2 >::value_type >::value &&std::is_same< typename std::iterator_traits< InputIterator1 >::value_type, typename std::iterator_traits< OutputIterator >::value_type >::value, OutputIterator >::type strxor(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator out)
Definition: hash/include/nil/crypto3/detail/strxor.hpp:45
Definition: pair.hpp:31