1
1
// ---------------------------------------------------------------------------//
2
- // Copyright (c) 2018-2019 Nil Foundation AG
3
- // Copyright (c) 2018-2019 Mikhail Komarov <[email protected] >
2
+ // Copyright (c) 2018-2020 Nil Foundation AG
3
+ // Copyright (c) 2018-2020 Mikhail Komarov <[email protected] >
4
4
//
5
5
// Distributed under the Boost Software License, Version 1.0
6
6
// See accompanying file LICENSE_1_0.txt or copy at
60
60
template <class T > \
61
61
struct has_ ##member : public std::integral_constant<bool , HasMember_##member<T>::RESULT> {};
62
62
63
+ #define GENERATE_HAS_MEMBER_FUNCTION (Function, ...) \
64
+ \
65
+ template <typename T> \
66
+ struct has_ ##Function { \
67
+ struct Fallback { \
68
+ void Function (##__VA_ARGS__); \
69
+ }; \
70
+ \
71
+ struct Derived : Fallback {}; \
72
+ \
73
+ template <typename C, C> \
74
+ struct ChT ; \
75
+ \
76
+ template <typename C> \
77
+ static char (&f (ChT<void (Fallback::*)(##__VA_ARGS__), &C::Function> *))[1]; \
78
+ \
79
+ template <typename C> \
80
+ static char (&f (...))[2]; \
81
+ \
82
+ static bool const value = sizeof (f<Derived>(0 )) == 2; \
83
+ };
84
+
85
+ #define GENERATE_HAS_MEMBER_CONST_FUNCTION (Function, ...) \
86
+ \
87
+ template <typename T> \
88
+ struct has_ ##Function { \
89
+ struct Fallback { \
90
+ void Function (##__VA_ARGS__) const ; \
91
+ }; \
92
+ \
93
+ struct Derived : Fallback {}; \
94
+ \
95
+ template <typename C, C> \
96
+ struct ChT ; \
97
+ \
98
+ template <typename C> \
99
+ static char (&f (ChT<void (Fallback::*)(##__VA_ARGS__) const , &C::Function> *))[1]; \
100
+ \
101
+ template <typename C> \
102
+ static char (&f (...))[2]; \
103
+ \
104
+ static bool const value = sizeof (f<Derived>(0 )) == 2; \
105
+ };
106
+
107
+ #define GENERATE_HAS_MEMBER_RETURN_FUNCTION (Function, ReturnType, ...) \
108
+ \
109
+ template <typename T> \
110
+ struct has_ ##Function { \
111
+ struct Dummy { \
112
+ typedef void ReturnType; \
113
+ }; \
114
+ typedef typename std::conditional<has_##ReturnType<T>::value, T, Dummy>::type TType; \
115
+ typedef typename TType::ReturnType type; \
116
+ \
117
+ struct Fallback { \
118
+ type Function (##__VA_ARGS__); \
119
+ }; \
120
+ \
121
+ struct Derived : TType, Fallback {}; \
122
+ \
123
+ template <typename C, C> \
124
+ struct ChT ; \
125
+ \
126
+ template <typename C> \
127
+ static char (&f (ChT<type (Fallback::*)(##__VA_ARGS__), &C::Function> *))[1]; \
128
+ \
129
+ template <typename C> \
130
+ static char (&f (...))[2]; \
131
+ \
132
+ static bool const value = sizeof (f<Derived>(0 )) == 2; \
133
+ };
134
+
135
+ #define GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION (Function, ReturnType, ...) \
136
+ \
137
+ template <typename T> \
138
+ struct has_ ##Function { \
139
+ struct Dummy { \
140
+ typedef void ReturnType; \
141
+ }; \
142
+ typedef typename std::conditional<has_##ReturnType<T>::value, T, Dummy>::type TType; \
143
+ typedef typename TType::ReturnType type; \
144
+ \
145
+ struct Fallback { \
146
+ type Function (##__VA_ARGS__) const ; \
147
+ }; \
148
+ \
149
+ struct Derived : TType, Fallback {}; \
150
+ \
151
+ template <typename C, C> \
152
+ struct ChT ; \
153
+ \
154
+ template <typename C> \
155
+ static char (&f (ChT<type (Fallback::*)(##__VA_ARGS__) const , &C::Function> *))[1]; \
156
+ \
157
+ template <typename C> \
158
+ static char (&f (...))[2]; \
159
+ \
160
+ static bool const value = sizeof (f<Derived>(0 )) == 2; \
161
+ };
162
+
63
163
namespace nil {
64
164
namespace crypto3 {
65
165
namespace detail {
166
+ GENERATE_HAS_MEMBER_TYPE (iterator)
66
167
GENERATE_HAS_MEMBER_TYPE (const_iterator)
67
168
68
169
GENERATE_HAS_MEMBER_TYPE (encoded_value_type)
@@ -89,6 +190,18 @@ namespace nil {
89
190
90
191
GENERATE_HAS_MEMBER (rounds)
91
192
193
+ GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION (begin, const_iterator)
194
+ GENERATE_HAS_MEMBER_CONST_RETURN_FUNCTION (end, const_iterator)
195
+
196
+ GENERATE_HAS_MEMBER_RETURN_FUNCTION (encode, block_type)
197
+ GENERATE_HAS_MEMBER_RETURN_FUNCTION (decode, block_type)
198
+
199
+ GENERATE_HAS_MEMBER_RETURN_FUNCTION (encrypt, block_type)
200
+ GENERATE_HAS_MEMBER_RETURN_FUNCTION (decrypt, block_type)
201
+
202
+ GENERATE_HAS_MEMBER_FUNCTION (generate)
203
+ GENERATE_HAS_MEMBER_CONST_FUNCTION (check)
204
+
92
205
template <typename T>
93
206
struct is_iterator {
94
207
static char test (...);
@@ -105,62 +218,26 @@ namespace nil {
105
218
106
219
template <typename Container>
107
220
struct is_container {
108
- private:
109
- template <typename T>
110
- struct has_begin_end {
111
- struct Dummy {
112
- typedef void const_iterator;
113
- };
114
- typedef typename std::conditional<has_const_iterator<T>::value, T, Dummy>::type TType;
115
- typedef typename TType::const_iterator iter;
116
-
117
- struct Fallback {
118
- iter begin () const ;
119
-
120
- iter end () const ;
121
- };
122
-
123
- struct Derived : TType, Fallback {};
124
-
125
- template <typename C, C>
126
- struct ChT ;
127
-
128
- template <typename C>
129
- static char (&f (ChT<iter (Fallback::*)() const , &C::begin> *))[1];
130
-
131
- template <typename C>
132
- static char (&f (...))[2];
133
-
134
- template <typename C>
135
- static char (&g (ChT<iter (Fallback::*)() const , &C::end> *))[1];
136
-
137
- template <typename C>
138
- static char (&g (...))[2];
139
-
140
- static bool const beg_value = sizeof (f<Derived>(0 )) == 2;
141
- static bool const end_value = sizeof (g<Derived>(0 )) == 2;
142
- };
143
-
144
- public:
145
- static const bool value = has_const_iterator<Container>::value && has_begin_end<Container>::beg_value &&
146
- has_begin_end<Container>::end_value;
221
+ static const bool value =
222
+ has_const_iterator<Container>::value && has_begin<Container>::value && has_end<Container>::value;
147
223
};
148
224
149
225
template <typename T>
150
226
struct is_codec {
151
227
static const bool value = has_encoded_value_type<T>::value && has_encoded_value_bits<T>::value &&
152
228
has_decoded_value_type<T>::value && has_decoded_value_bits<T>::value &&
153
229
has_encoded_block_type<T>::value && has_encoded_block_bits<T>::value &&
154
- has_decoded_block_type<T>::value && has_decoded_block_bits<T>::value;
230
+ has_decoded_block_type<T>::value && has_decoded_block_bits<T>::value &&
231
+ has_encode<T>::value && has_decode<T>::value;
155
232
typedef T type;
156
233
};
157
234
158
235
template <typename T>
159
236
struct is_block_cipher {
160
237
static const bool value = has_word_type<T>::value && has_word_bits<T>::value &&
161
238
has_block_type<T>::value && has_block_bits<T>::value &&
162
- has_key_type<T>::value && has_key_bits<T>::value &&
163
- has_rounds <T>::value;
239
+ has_key_type<T>::value && has_key_bits<T>::value && has_rounds<T>::value &&
240
+ has_encrypt<T>::value && has_decrypt <T>::value;
164
241
typedef T type;
165
242
};
166
243
@@ -198,8 +275,14 @@ namespace nil {
198
275
has_key_type<T>::value && has_key_bits<T>::value;
199
276
typedef T type;
200
277
};
278
+
279
+ template <typename T>
280
+ struct is_passhash {
281
+ static const bool value = has_generate<T>::value && has_check<T>::value;
282
+ typedef T type;
283
+ };
201
284
} // namespace detail
202
285
} // namespace crypto3
203
286
} // namespace nil
204
287
205
- #endif // CRYPTO3_CODEC_TYPE_TRAITS_HPP
288
+ #endif // CRYPTO3_TYPE_TRAITS_HPP
0 commit comments