hex_policy.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_HEX_POLICY_HPP
26 #define CRYPTO3_HEX_POLICY_HPP
27 
28 #include <array>
29 
30 #include <boost/integer.hpp>
31 
32 #include <nil/crypto3/detail/inline_variable.hpp>
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace codec {
37  namespace mode {
38  struct upper {
39  typedef const char *constants_type;
40  CRYPTO3_INLINE_VARIABLE(constants_type, constants, ("0123456789ABCDEF"));
41  };
42 
43  struct lower {
44  typedef const char *constants_type;
45  CRYPTO3_INLINE_VARIABLE(constants_type, constants, ("0123456789abcdef"));
46  };
47  } // namespace mode
48 
49  namespace detail {
50  template<typename Mode>
51  struct hex_policy {
52  typedef Mode mode_type;
53 
54  typedef typename boost::uint_t<CHAR_BIT>::exact byte_type;
55 
56  typedef typename mode_type::constants_type constants_type;
57  CRYPTO3_INLINE_VARIABLE(constants_type, constants, (mode_type::constants()));
58  constexpr static const std::size_t decoded_value_bits = CHAR_BIT;
60 
61  constexpr static const std::size_t encoded_value_bits = CHAR_BIT;
63 
64  constexpr static const std::size_t decoded_block_values = 1;
65  constexpr static const std::size_t decoded_block_bits = decoded_value_bits * decoded_block_values;
66  typedef std::array<decoded_value_type, decoded_block_values> decoded_block_type;
67 
68  constexpr static const std::size_t encoded_block_values = 2;
69  constexpr static const std::uint8_t encoded_block_bits = encoded_block_values * encoded_value_bits;
70  typedef std::array<encoded_value_type, encoded_block_values> encoded_block_type;
71  };
72  } // namespace detail
73  } // namespace codec
74  } // namespace crypto3
75 } // namespace nil
76 
77 #endif // CRYPTO3_HEX_POLICY_HPP
boost::mpl::apply< AccumulatorSet, tag::codec< Mode > >::type::result_type codec(const AccumulatorSet &acc)
Definition: accumulators/codec.hpp:261
Definition: pair.hpp:31
Definition: hex_policy.hpp:51
constexpr static const std::size_t decoded_block_bits
Definition: hex_policy.hpp:65
constexpr static const std::uint8_t encoded_block_bits
Definition: hex_policy.hpp:69
std::array< decoded_value_type, decoded_block_values > decoded_block_type
Definition: hex_policy.hpp:66
mode_type::constants_type constants_type
Definition: hex_policy.hpp:56
CRYPTO3_INLINE_VARIABLE(constants_type, constants,(mode_type::constants()))
constexpr static const std::size_t encoded_value_bits
Definition: hex_policy.hpp:61
constexpr static const std::size_t decoded_block_values
Definition: hex_policy.hpp:64
boost::uint_t< CHAR_BIT >::exact byte_type
Definition: hex_policy.hpp:54
std::array< encoded_value_type, encoded_block_values > encoded_block_type
Definition: hex_policy.hpp:70
byte_type encoded_value_type
Definition: hex_policy.hpp:62
byte_type decoded_value_type
Definition: hex_policy.hpp:59
Mode mode_type
Definition: hex_policy.hpp:52
constexpr static const std::size_t decoded_value_bits
Definition: hex_policy.hpp:58
constexpr static const std::size_t encoded_block_values
Definition: hex_policy.hpp:68
Definition: hex_policy.hpp:43
CRYPTO3_INLINE_VARIABLE(constants_type, constants,("0123456789abcdef"))
const char * constants_type
Definition: hex_policy.hpp:44
Definition: hex_policy.hpp:38
CRYPTO3_INLINE_VARIABLE(constants_type, constants,("0123456789ABCDEF"))
const char * constants_type
Definition: hex_policy.hpp:39