From 0d10472c9c375026d0f98cfb066a6fb9d2992030 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 16 Jun 2012 01:11:23 +0000 Subject: Cipher will fill with zeros when flushed. There seems to be some odd interaction still, here and there. I'll see if I can track it down. --- src/experimental/cipher.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/experimental/cipher.h') diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h index a17030d..814e88c 100644 --- a/src/experimental/cipher.h +++ b/src/experimental/cipher.h @@ -80,21 +80,33 @@ namespace Bu while( iPos < iBytes ) { - int iLeft = Bu::min((int)(iBytes-iPos),iBlockSize-iReadBufFill); - memcpy( aReadBuf+iReadBufFill, (char *)pBuf+iPos, iLeft ); + int iLeft = Bu::min((int)(iBytes-iPos),iBlockSize-iWriteBufFill); + memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); iPos += iLeft; - iReadBufFill += iLeft; - if( iReadBufFill == iBlockSize ) + iWriteBufFill += iLeft; + if( iWriteBufFill == iBlockSize ) { - encipher( aReadBuf ); - rNext.write( aReadBuf, iBlockSize ); - iReadBufFill = 0; + encipher( aWriteBuf ); + rNext.write( aWriteBuf, iBlockSize ); + iWriteBufFill = 0; } } return iPos; } + virtual void flush() + { + if( iWriteBufFill < iBlockSize ) + { + memset( aWriteBuf+iWriteBufFill, 0, iBlockSize-iWriteBufFill ); + encipher( aWriteBuf ); + rNext.write( aWriteBuf, iBlockSize ); + iWriteBufFill = 0; + } + rNext.flush(); + } + using Bu::Stream::read; using Bu::Stream::write; -- cgit v1.2.3