1 /* 2 * (C) 2009 Jack Lloyd 3 * 4 * Distributed under the terms of the Botan license 5 */ 6 7 #include <iostream> 8 #include <fstream> 9 #include <botan/botan.h> 10 main(int argc,char * argv[])11int main(int argc, char* argv[]) 12 { 13 if(argc < 3) 14 { 15 std::cout << "Usage: " << argv[0] << " digest <filenames>" << std::endl; 16 return 1; 17 } 18 19 Botan::LibraryInitializer init; 20 21 std::string hash = argv[1]; 22 /* a couple of special cases, kind of a crock */ 23 if(hash == "sha1") hash = "SHA-1"; 24 if(hash == "md5") hash = "MD5"; 25 26 try { 27 if(!Botan::have_hash(hash)) 28 { 29 std::cout << "Unknown hash \"" << argv[1] << "\"" << std::endl; 30 return 1; 31 } 32 33 Botan::Pipe pipe(new Botan::Hash_Filter(hash), 34 new Botan::Hex_Encoder); 35 36 int skipped = 0; 37 for(int j = 2; argv[j] != 0; j++) 38 { 39 std::ifstream file(argv[j], std::ios::binary); 40 if(!file) 41 { 42 std::cout << "ERROR: could not open " << argv[j] << std::endl; 43 skipped++; 44 continue; 45 } 46 pipe.start_msg(); 47 file >> pipe; 48 pipe.end_msg(); 49 pipe.set_default_msg(j-2-skipped); 50 std::cout << pipe << " " << argv[j] << std::endl; 51 } 52 } 53 catch(std::exception& e) 54 { 55 std::cout << "Exception caught: " << e.what() << std::endl; 56 } 57 return 0; 58 } 59