diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-08-04 04:37:12 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-08-04 04:37:12 +0300 |
commit | 0c593583dccd88e90450972e6a1b9e6bc67e0911 (patch) | |
tree | d38de5fb6255fec9424bf9694c1cf3fcfd8b9c39 /utils/data_parsers.hpp | |
parent | test/toolkit.py: fix utility names (diff) | |
download | aes-tools-0c593583dccd88e90450972e6a1b9e6bc67e0911.tar.gz aes-tools-0c593583dccd88e90450972e6a1b9e6bc67e0911.zip |
utils: bugfix & refactoring
Diffstat (limited to 'utils/data_parsers.hpp')
-rw-r--r-- | utils/data_parsers.hpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/data_parsers.hpp b/utils/data_parsers.hpp new file mode 100644 index 0000000..08486fa --- /dev/null +++ b/utils/data_parsers.hpp @@ -0,0 +1,55 @@ +/** + * \file + * \author Egor Tensin <Egor.Tensin@gmail.com> + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include <aesnixx/all.hpp> + +#include <boost/algorithm/string.hpp> +#include <boost/program_options.hpp> + +#include <istream> +#include <string> + +static std::istream& operator>>(std::istream& is, aesni::Mode& dest) +{ + std::string src; + is >> src; + + if (boost::iequals(src, "ecb")) + dest = AESNI_ECB; + else if (boost::iequals(src, "cbc")) + dest = AESNI_CBC; + else if (boost::iequals(src, "cfb")) + dest = AESNI_CFB; + else if (boost::iequals(src, "ofb")) + dest = AESNI_OFB; + else if (boost::iequals(src, "ctr")) + dest = AESNI_CTR; + else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value, "mode", src); + + return is; +} + +static std::istream& operator>>(std::istream& is, aesni::Algorithm& dest) +{ + std::string src; + is >> src; + + if (boost::iequals(src, "aes128")) + dest = AESNI_AES128; + else if (boost::iequals(src, "aes192")) + dest = AESNI_AES192; + else if (boost::iequals(src, "aes256")) + dest = AESNI_AES256; + else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value, "algorithm", src); + + return is; +} |