[Botan-devel] Pipe API doc example

Matt Johnston matt at ucc.asn.au
Tue Dec 6 01:28:29 EST 2005


Hi.

It seems that the Filter Example (6.3, p24) of the API doc
doesn't work for multiple files. As far as I can tell, a
Pipe can't really be used for more than one
send_msg()/end_msg() pair, as the number of internal
'message' elements will keep growing.  For each file after
the first, the hashes are empty. 

The examples/hasher.cpp example creates a new Pipe for each
file so works correctly.

Should reusing a Pipe be supported? It seems inefficient to
have to lookup, construct, and destruct a hash/hmac/cipher
filter for every message, for things like network packets.

Cheers,
Matt



#include <iostream>
#include <fstream>
#include <botan/botan.h>

using namespace std;
using namespace Botan;

int main(int argc, char ** argv)
{
  LibraryInitializer init;

  string name[3] = { "MD5", "SHA-1", "RIPEMD-160" }; 
  Botan::Filter* hash[3] = { 
	  new Botan::Chain(new Botan::Hash_Filter(name[0]), 
			  new Botan::Hex_Encoder), 
	  new Botan::Chain(new Botan::Hash_Filter(name[1]), 
			  new Botan::Hex_Encoder), 
	  new Botan::Chain(new Botan::Hash_Filter(name[2]), 
			  new Botan::Hex_Encoder) }; 
  Botan::Pipe pipe(new Botan::Fork(hash, 3)); 
  for(u32bit j = 1; argv[j] != 0; j++) 
  { 
	  ifstream file(argv[j]); 
	  pipe.start_msg(); 
	  file >> pipe; 
	  pipe.end_msg(); 
	  file.close(); 
	  for(u32bit k = 0; k != 3; k++) 
	  { 
		  pipe.set_default_msg(k); 
		  cout << name[k] << "(" << argv[j] << ") = " << pipe << endl; 
	  } 
  } 

  return 0;
}





More information about the botan-devel mailing list