diff options
| author | Egor Tensin <egor@tensin.name> | 2026-07-20 18:32:43 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-07-20 18:32:43 +0200 |
| commit | e01da5638274dee81238fa1272bb138bf3586f00 (patch) | |
| tree | 0b83d638d8e6e8784524fe754367f9cecc4209b5 /aesxx | |
| parent | Merge pull request #8 from egor-tensin/dependabot/github_actions/actions/cache-6 (diff) | |
| download | aes-tools-e01da5638274dee81238fa1272bb138bf3586f00.tar.gz aes-tools-e01da5638274dee81238fa1272bb138bf3586f00.zip | |
aesxx: use if constexpr for get_number_of_rounds
Diffstat (limited to 'aesxx')
| -rw-r--r-- | aesxx/include/aesxx/aes.hpp | 15 | ||||
| -rw-r--r-- | 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 @@ -33,11 +33,6 @@ struct Types<AES_AES128> { }; template <> -inline std::size_t get_number_of_rounds<AES_AES128>() { - return 11; -} - -template <> inline void from_string<AES_AES128>(aes128::Block& dest, std::string_view src) { aes_AES128_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } @@ -108,11 +103,6 @@ struct Types<AES_AES192> { }; template <> -inline std::size_t get_number_of_rounds<AES_AES192>() { - return 13; -} - -template <> inline void from_string<AES_AES192>(aes192::Block& dest, std::string_view src) { aes_AES192_parse_block(&dest, src.data(), ErrorDetailsThrowsInDestructor{}); } @@ -183,11 +173,6 @@ struct Types<AES_AES256> { }; template <> -inline std::size_t get_number_of_rounds<AES_AES256>() { - return 15; -} - -template <> inline void from_string<AES_AES256>(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 <Algorithm algorithm> struct Types; template <Algorithm algorithm> -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 <Algorithm algorithm> void from_string(typename Types<algorithm>::Block&, std::string_view); |
