[Botan-devel] [PATCH] Use ios::binary on streams that are expected to be binary

Jack Lloyd lloyd at randombit.net
Tue Nov 29 10:51:44 EST 2005

I took a look at this last night. I think the 'best' (as in, easiest, simplest)
thing to do is add a bool argument to the DataSink_Stream and DataSource_Stream
constructors which defaults to false; if true, binary I/O is used instead. So
any uses of those in an application can be set to binary mode as needed by the
application programmer, but the semantics of using them in existing
applications won't change.

That leaves uses of the stream sink/sources in the library itself. The sink is
not used anywhere, and the source is only used for reading certain PKCS #8 and
X.509 structures. The sticky point there is that those files can contain either
base64 text or raw binary; we don't know which until after we've read it and
done some tests on the input. However, I realized that since the base64 decoder
ignores whitespace anyway, there shouldn't be any harm in using binary I/O
regardless of if the input is binary or base64. So the idea is that all of
those signal to the DataSource_Stream that binary I/O should be used, and it
should work regardless.

As far as I know, the only platform in modern use that text vs binary actually
matters is Windows (unless VMS does? I've never really figured out how files in
VMS are supposed to work). I presume this problem came up because trying to
read PKCS #8 keys on Windows was failing? (I haven't had time to check through
the Monotone archives to confirm this.)

If anyone notices any potential problems with this proposal, or has a better
solution to handling binary vs text mode in the sink/stream code, I'm certainly
open to ideas.


On Tue, Nov 29, 2005 at 11:25:10AM +1300, Matthew Gregan wrote:

> There are a few places in Botan that read from C++ fstreams and appear to
> assume the stream is binary clean, but don't open the stream explicitly as
> binary.  This patch fixes that issue.

More information about the botan-devel mailing list