diff options
author | Simon Warta <[email protected]> | 2015-12-08 17:25:03 +0100 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-12-09 15:28:07 +0100 |
commit | 1a0f3438a97b7913ccf444bc48510e0d145af551 (patch) | |
tree | bb4f275f5eba30076d9b48a9164c38b71e2a11e6 /src/cli/hash.cpp | |
parent | 0261351f68674105a40d1938a001ba65dda756ed (diff) |
Rename cmd/app -> cli
Diffstat (limited to 'src/cli/hash.cpp')
-rw-r--r-- | src/cli/hash.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/cli/hash.cpp b/src/cli/hash.cpp new file mode 100644 index 000000000..81a72ca17 --- /dev/null +++ b/src/cli/hash.cpp @@ -0,0 +1,63 @@ +/* +* (C) 2009 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include "apps.h" + +#if defined(BOTAN_HAS_CODEC_FILTERS) + +#include <botan/filters.h> +#include <iostream> +#include <fstream> + +using namespace Botan; + +namespace { + +int hash(const std::vector<std::string> &args) + { + if(args.size() < 3) + { + std::cout << "Usage: " << args[0] << " digest <filenames>" << std::endl; + return 1; + } + + std::string hash = args[1]; + /* a couple of special cases, kind of a crock */ + if(hash == "sha1") hash = "SHA-1"; + if(hash == "md5") hash = "MD5"; + + try { + Pipe pipe(new Hash_Filter(hash), new Hex_Encoder); + + int skipped = 0; + for(int j = 2; j < args.size(); j++) + { + std::ifstream file(args[j], std::ios::binary); + if(!file) + { + std::cout << "ERROR: could not open " << args[j] << std::endl; + skipped++; + continue; + } + pipe.start_msg(); + file >> pipe; + pipe.end_msg(); + pipe.set_default_msg(j-2-skipped); + std::cout << pipe << " " << args[j] << std::endl; + } + } + catch(std::exception& e) + { + std::cout << "Exception caught: " << e.what() << std::endl; + } + return 0; + } + +REGISTER_APP(hash); + +} + +#endif // BOTAN_HAS_CODEC_FILTERS |