CsCrypto  1.0.1
sym_traits.h
1 /***********************************************************************
2 *
3 * Copyright (c) 2021-2024 Tim van Deurzen
4 * Copyright (c) 2021-2024 Barbara Geller
5 * Copyright (c) 2021-2024 Ansel Sermersheim
6 *
7 * This file is part of CsCrypto.
8 *
9 * CsCrypto is free software, released under the BSD 2-Clause license.
10 * For license details refer to LICENSE provided with this project.
11 *
12 * CsCrypto is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * https://opensource.org/licenses/BSD-2-Clause
17 *
18 ***********************************************************************/
19 
20 #ifndef CS_CRYPTO_SYM_TRAITS_H
21 #define CS_CRYPTO_SYM_TRAITS_H
22 
23 #include <util/tools/crypto_traits.h>
24 #include <util/tools/is_detected_traits.h>
25 
26 namespace cs_crypto::cipher::traits {
27 
28 template <typename T>
29 using has_key_size = decltype(T::key_size);
30 
31 template <typename T>
32 struct key_size {
33  static_assert(cs_crypto::traits::is_detected_v<has_key_size, T>, "No key_size constexpr data member found");
34 
35  using size_type = decltype(T::key_size);
36  constexpr static const size_type value = T::key_size;
37 };
38 
39 template <typename T>
40 [[maybe_unused]] inline constexpr const auto key_size_v = key_size<T>::value;
41 
42 template <typename T>
43 using has_iv_size = decltype(T::iv_size);
44 
45 template <typename T>
46 struct iv_size {
47  static_assert(cs_crypto::traits::is_detected_v<has_iv_size, T>, "No iv_size constexpr data member found");
48 
49  using size_type = decltype(T::iv_size);
50  constexpr static const size_type value = T::iv_size;
51 };
52 
53 template <typename T>
54 [[maybe_unused]] inline constexpr const auto iv_size_v = iv_size<T>::value;
55 
56 } // namespace cs_crypto::cipher::traits
57 
58 #endif