diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-21 14:50:03 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-21 14:52:12 +0300 |
commit | 3304264990b96c09b174716ecb8da63d24457ae8 (patch) | |
tree | 9ec5711da75d4aa67587a8e39c24daaf6088c498 /aesxx/utils/data_parsers.hpp | |
parent | test: move data files to test/data (diff) | |
download | aes-tools-3304264990b96c09b174716ecb8da63d24457ae8.tar.gz aes-tools-3304264990b96c09b174716ecb8da63d24457ae8.zip |
utils/ -> aesxx/utils/
Diffstat (limited to 'aesxx/utils/data_parsers.hpp')
-rw-r--r-- | aesxx/utils/data_parsers.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/aesxx/utils/data_parsers.hpp b/aesxx/utils/data_parsers.hpp new file mode 100644 index 0000000..1207c7c --- /dev/null +++ b/aesxx/utils/data_parsers.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com> +// 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 <aesxx/all.hpp> + +#include <boost/algorithm/string.hpp> +#include <boost/program_options.hpp> + +#include <istream> +#include <string> +#include <unordered_map> + +inline std::istream& operator>>(std::istream& is, aes::Mode& dest) +{ + std::string src; + is >> src; + + static const std::unordered_map<std::string, aes::Mode> lookup_table = + { + {"ecb", AES_ECB}, + {"cbc", AES_CBC}, + {"cfb", AES_CFB}, + {"ofb", AES_OFB}, + {"ctr", AES_CTR}, + }; + + const auto it = lookup_table.find(boost::algorithm::to_lower_copy(src)); + + if (it == lookup_table.cend()) + throw boost::program_options::invalid_option_value(src); + + dest = it->second; + return is; +} + +inline std::istream& operator>>(std::istream& is, aes::Algorithm& dest) +{ + std::string src; + is >> src; + + static const std::unordered_map<std::string, aes::Algorithm> lookup_table = + { + {"aes128", AES_AES128}, + {"aes192", AES_AES192}, + {"aes256", AES_AES256}, + }; + + const auto it = lookup_table.find(boost::algorithm::to_lower_copy(src)); + + if (it == lookup_table.cend()) + throw boost::program_options::invalid_option_value(src); + + dest = it->second; + return is; +} |