diff options
author | x1b6e6 | 2020-09-03 09:53:35 +0700 |
---|---|---|
committer | x1b6e6 | 2020-09-03 09:53:35 +0700 |
commit | c0a1ad90778d0e0ff597667910677c265dbf319f (patch) | |
tree | aeede2b7d17951162ed9fa401da7e60b885f63e8 | |
parent | b03b9c56b36260fa3dd4e23a7bd30c00926512a4 (diff) | |
download | aur-c0a1ad90778d0e0ff597667910677c265dbf319f.tar.gz |
aes: using --input and --output for setting in/out
Signed-off-by: x1b6e6 <ftdabcde@gmail.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | PKGBUILD | 6 | ||||
-rw-r--r-- | aes.cc | 38 |
3 files changed, 34 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a985bf04e9a..da499fab7e4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(aes VERSION 0.1.1 LANGUAGES CXX) +project(aes VERSION 0.2.0 LANGUAGES CXX) add_definitions(-DPROJECT_VERSION="${PROJECT_VERSION}") @@ -1,7 +1,7 @@ # Maintainer: x1b6e6 <ftdabcde@gmail.com> pkgname=aes -pkgver=0.1.1 +pkgver=0.2.0 pkgrel=1 pkgdesc="encryption utility with very simple interface" arch=('any') @@ -16,8 +16,8 @@ source=( ) sha1sums=( - "bbd6a785cd0c62baf7de7e6dcb9cd970678515fe" - "10c4f9d10e133a1c2c13b91108e472c2e0da3287" + "a14bc448b2c43536dffc1e6d63ea257dd6fa33ea" + "d0734f8497ecc33ba3e406c873eb33b71d8dce8b" ) build(){ @@ -5,6 +5,7 @@ #include <termios.h> #include <unistd.h> #include <cstring> +#include <fstream> #include <iostream> #include <memory> #include <stdexcept> @@ -15,12 +16,10 @@ #endif auto get_version() { - /* TODO */ return "aes v" PROJECT_VERSION; } auto get_usage() { - /* TODO */ return get_version() + std::string(R"( Usage: @@ -30,6 +29,8 @@ Options: -h, --help Pring this message -v, --version Print version and exit -d, --decrypt Decrypt data + -i, --input=FILE Set input file [default: /dev/stdin] + -o, --output=FILE Set output file [default: /dev/stdout] -p, --password=PASSWORD Use password [default: prompt] -k, --key=KEY Use key instead password [default: ] -l, --last=LAST Size of last block [default: 0] @@ -66,6 +67,8 @@ int main(int argc, const char** argv) { auto key = args.at("--key").asString(); auto bits = args.at("--bits").asLong(); auto last = args.at("--last").asLong(); + auto input = args.at("--input").asString(); + auto output = args.at("--output").asString(); try { if (password != "prompt" && key != "") { throw std::invalid_argument( @@ -92,6 +95,18 @@ int main(int argc, const char** argv) { return 1; } + std::ifstream fin; + std::ofstream fout; + + if (input != "/dev/stdin") { + fin.open(input); + std::cin.rdbuf(fin.rdbuf()); + } + if (output != "/dev/stdout") { + fout.open(output); + std::cout.rdbuf(fout.rdbuf()); + } + size_t key_size = bits >> 2; std::unique_ptr<char[]> key_arr(new char[key_size]); @@ -109,14 +124,19 @@ int main(int argc, const char** argv) { gcry_md_close(md_handle); } else { - for (size_t i = 0; i < key_size; ++i) { - char buf[3]{0, 0, 0}; + try { + for (size_t i = 0; i < key_size; ++i) { + char buf[3]{0, 0, 0}; - buf[0] = key[(i << 1) + 0]; - buf[1] = key[(i << 1) + 1]; - buf[2] = 0; + buf[0] = key[(i << 1) + 0]; + buf[1] = key[(i << 1) + 1]; + buf[2] = 0; - key_arr[i] = std::strtol(buf, nullptr, 16); + key_arr[i] = std::strtol(buf, nullptr, 16); + } + } catch (const std::invalid_argument& e) { + std::cerr << "Error parsing key: " << e.what() << '\n'; + return 1; } } @@ -162,3 +182,5 @@ int main(int argc, const char** argv) { return 0; } + +// vim: set ts=4 sw=4 : |