From e01da5638274dee81238fa1272bb138bf3586f00 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 20 Jul 2026 18:32:43 +0200 Subject: aesxx: use if constexpr for get_number_of_rounds --- aesxx/include/aesxx/aes.hpp | 15 --------------- aesxx/include/aesxx/api.hpp | 10 +++++++++- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/aesxx/include/aesxx/aes.hpp b/aesxx/include/aesxx/aes.hpp index 241e051..1b5aefa 100644 --- a/aesxx/include/aesxx/aes.hpp +++ b/aesxx/include/aesxx/aes.hpp @@ -32,11 +32,6 @@ struct Types { typedef aes128::Key Key; }; -template <> -inline std::size_t get_number_of_rounds() { - return 11; -} - template <> inline void from_string(aes128::Block& dest, std::string_view src) { aes_AES128_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); @@ -107,11 +102,6 @@ struct Types { typedef aes192::Key Key; }; -template <> -inline std::size_t get_number_of_rounds() { - return 13; -} - template <> inline void from_string(aes192::Block& dest, std::string_view src) { aes_AES192_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); @@ -182,11 +172,6 @@ struct Types { typedef aes256::Key Key; }; -template <> -inline std::size_t get_number_of_rounds() { - return 15; -} - template <> inline void from_string(aes256::Block& dest, std::string_view src) { aes_AES256_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); diff --git a/aesxx/include/aesxx/api.hpp b/aesxx/include/aesxx/api.hpp index 70891c9..131e5e5 100644 --- a/aesxx/include/aesxx/api.hpp +++ b/aesxx/include/aesxx/api.hpp @@ -19,7 +19,15 @@ template struct Types; template -std::size_t get_number_of_rounds(); +std::size_t get_number_of_rounds() { + if constexpr (algorithm == AES_AES128) + return 11; + if constexpr (algorithm == AES_AES192) + return 13; + if constexpr (algorithm == AES_AES256) + return 15; + static_assert("Unrecognized algorithm"); +} template void from_string(typename Types::Block&, std::string_view); -- cgit v1.3