[Botan-devel] Converting pipe result to unsigned char*

Jack Lloyd lloyd at randombit.net
Fri Dec 2 12:46:38 EST 2005


However, be careful, since this method doubles up the amount of memory you're
using for a brief time (during the copy, when the source and destination both
have to exist at once), which could be important if you're encrypting more than
a few megabytes of data at once. If you're planning on processing a lot of data
at once, and will be dumping it straight from the character array to a file or
socket, look at the DataSink class - you can use DataSink_Stream directly for
files, or subclass DataSink for sockets. Just inherit from DataSink, implement
the write() member function, and build it into the pipeline.

-J

On Fri, Dec 02, 2005 at 12:12:20PM -0500, Jack Lloyd wrote:
> 
> If the output is binary, using Pipe's read() functions should work nicely; they
> will write the output directly into a provided array of unsigned chars. The
> basic idiom is:
> 
> Pipe pipe(/* some filters */);
> pipe.process_msg(/* blah */);
> 
> const u32bit expecting = pipe.remaining();
> 
> // byte == Botan's typedef for unsigned char
> byte* output = new byte[expecting];
> 
> if(pipe.read(output, expecting) != expecting)
>    signal_error(); // this should never happen, but just to be safe...
> 
> -Jack
> 
> On Fri, Dec 02, 2005 at 04:55:57PM +0000, Kang Chung wrote:
> > I need to convert the pipe encryption/decryption result to a unsigned char* somehow.
> > I've tried the std::string to a unsigned char[], but this does not seem to be a good solution.
> > 
> > Does anyone have any good ideas? Please?
> > 
> > /Kang Chung
> > _______________________________________________
> > botan-devel mailing list
> > botan-devel at randombit.net
> > http://www.randombit.net/mailman/listinfo/botan-devel
> 
> _______________________________________________
> 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