// Copyright (c) 2015 Egor Tensin // This file is part of the "AES tools" project. // For details, see https://github.com/egor-tensin/aes-tools // Distributed under the MIT License. #pragma once #include #include #include #include #include #include #include namespace boost { inline void validate(any& dest, const std::vector& values, aes::Mode*, int) { using namespace program_options; validators::check_first_occurrence(dest); const auto& src = validators::get_single_string(values); static const std::unordered_map lookup_table = { {"ecb", AES_ECB}, {"cbc", AES_CBC}, {"cfb", AES_CFB}, {"ofb", AES_OFB}, {"ctr", AES_CTR}, }; const auto it = lookup_table.find(algorithm::to_lower_copy(src)); if (it == lookup_table.cend()) throw invalid_option_value(src); dest = it->second; } inline void validate(any& dest, const std::vector& values, aes::Algorithm*, int) { using namespace program_options; validators::check_first_occurrence(dest); const auto& src = validators::get_single_string(values); static const std::unordered_map lookup_table = { {"aes128", AES_AES128}, {"aes192", AES_AES192}, {"aes256", AES_AES256}, }; const auto it = lookup_table.find(algorithm::to_lower_copy(src)); if (it == lookup_table.cend()) throw invalid_option_value(src); dest = it->second; } inline void validate(any& dest, const std::vector& values, aes::Block*, int) { const std::string& src = program_options::validators::get_single_string(values); dest = aes::Block::parse(src); } } // namespace boost