[Botan-devel] Pipe API doc example

Jack Lloyd lloyd at randombit.net
Tue Dec 6 01:50:44 EST 2005


Actually, Pipe does keep all of the messages. That includes messages which
you've already read out of; so when you set the default read message to 0,
you're always reading from the very first message; calling
start_msg()/end_msg() only adds new messages, it never deletes them.

If you change 
    pipe.set_default_msg(k); 
to
    pipe.set_default_msg(3*(j-1)+k); 
everything should work as you expect. Pipe can certainly handle multiple
messages; otherwise there would be no need for the start_msg/end_msg nonsense.

And yes, you're right - the example was completely wrong. I'm not sure if the
example just predates to sometime sufficiently far back that Pipe operated
differently (which would mean pre-0.7.0, I think), or if (more likely) I copied
some code that worked and changed various things without ever testing the final
version.

Jack

On Tue, Dec 06, 2005 at 02:28:29PM +0800, Matt Johnston wrote:
> 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;
> }
> 
> 
> _______________________________________________
> botan-devel mailing list
> botan-devel at randombit.net
> http://www.randombit.net/mailman/listinfo/botan-devel



More information about the botan-devel mailing list