Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/md5.cpp
Go to the documentation of this file.
1 /*
2  * calculates md5 checksum of standard input or file in the 1st parameter
3  *
4  */
5 
6 #include <xstream/digest.h>
7 
8 #include <iostream>
9 #include <fstream>
10 #include <cstdio>
11 
12 using namespace std;;
13 using namespace xstream;;
14 
15 int main(int argc, char* argv[]){
16 
17  const size_t len = 4*1024;
18  char buf[len];
19 
20  istream* readfrom;
21 
22  try{
23  if(1<argc){
24  readfrom = new ifstream(argv[1]);
25  }else{
26  readfrom = &cin;
27  }
28 
29  digest::md5 md;
30  ostream out(&md);
31 
32  //raise exceptions
33  out.exceptions(ios::badbit);
34 
35 
36  while(readfrom->good()){
37  readfrom->read(buf,len);
38  out.write(buf,readfrom->gcount());
39  }
40 
41  out.flush();
42  struct digest::md5::result res = md.digest();
43  cout<<res<<endl;
44  }
45  catch(exception& e){
46  cerr<<"Error: "<<e.what()<<endl;
47  }
48 
49  //pointers not being freed
50 
51  return 0;
52 }
C++ objects to calculate digests of data.
TEllipse * e
int main(int argc, char *argv[])
Definition: gendoc.cc:6