From ec05778d5718a7912e506764d443a78d6a6179e3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 5 Nov 2012 22:41:51 +0000 Subject: Converted tabs to spaces with tabconv. --- src/experimental/cipher.h | 218 +++++++++++++++++++++++----------------------- 1 file changed, 109 insertions(+), 109 deletions(-) (limited to 'src/experimental/cipher.h') diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h index 5d5cb07..6e58613 100644 --- a/src/experimental/cipher.h +++ b/src/experimental/cipher.h @@ -13,115 +13,115 @@ namespace Bu { - template - class Cipher : public Bu::Filter - { - public: - Cipher( Bu::Stream &rNext ) : - Bu::Filter( rNext ), - iReadBufFill( 0 ), - iReadBufPos( 0 ), - iWriteBufFill( 0 ) - { - } - - virtual ~Cipher() - { - } - - virtual void start() - { - } - - virtual Bu::size stop() - { - flush(); - return 0; - } - - virtual Bu::size read( void *pBuf, Bu::size iBytes ) - { - Bu::size iRead = 0; - while( iRead < iBytes ) - { - if( iReadBufFill < iBlockSize ) - { - int iR = rNext.read( - aReadBuf+iReadBufFill, - iBlockSize-iReadBufFill - ); - if( iR == 0 ) - return iRead; - - iReadBufFill += iR; - - if( iReadBufFill == iBlockSize ) - decipher( aReadBuf ); - } - - if( iReadBufFill == iBlockSize ) - { - int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); - memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); - iRead += iCpy; - iReadBufPos += iCpy; - if( iReadBufPos == iBlockSize ) - { - iReadBufPos = iReadBufFill = 0; - } - } - } - - return iRead; - } - - virtual Bu::size write( const void *pBuf, Bu::size iBytes ) - { - Bu::size iPos = 0; - - while( iPos < iBytes ) - { - int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill); - memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); - iPos += iLeft; - iWriteBufFill += iLeft; - if( iWriteBufFill == iBlockSize ) - { - encipher( aWriteBuf ); - rNext.write( aWriteBuf, iBlockSize ); - iWriteBufFill = 0; - } - } - - return iPos; - } - - virtual void flush() - { - if( iWriteBufFill > 0 && 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; - - protected: - virtual void encipher( void *pData )=0; - virtual void decipher( void *pData )=0; - - private: - char aReadBuf[iBlockSize]; - char aWriteBuf[iBlockSize]; - int iReadBufFill; - int iReadBufPos; - int iWriteBufFill; - }; + template + class Cipher : public Bu::Filter + { + public: + Cipher( Bu::Stream &rNext ) : + Bu::Filter( rNext ), + iReadBufFill( 0 ), + iReadBufPos( 0 ), + iWriteBufFill( 0 ) + { + } + + virtual ~Cipher() + { + } + + virtual void start() + { + } + + virtual Bu::size stop() + { + flush(); + return 0; + } + + virtual Bu::size read( void *pBuf, Bu::size iBytes ) + { + Bu::size iRead = 0; + while( iRead < iBytes ) + { + if( iReadBufFill < iBlockSize ) + { + int iR = rNext.read( + aReadBuf+iReadBufFill, + iBlockSize-iReadBufFill + ); + if( iR == 0 ) + return iRead; + + iReadBufFill += iR; + + if( iReadBufFill == iBlockSize ) + decipher( aReadBuf ); + } + + if( iReadBufFill == iBlockSize ) + { + int iCpy = Bu::buMin( (int)(iBytes-iRead), iBlockSize-iReadBufPos ); + memcpy( ((char *)pBuf)+iRead, aReadBuf+iReadBufPos, iCpy ); + iRead += iCpy; + iReadBufPos += iCpy; + if( iReadBufPos == iBlockSize ) + { + iReadBufPos = iReadBufFill = 0; + } + } + } + + return iRead; + } + + virtual Bu::size write( const void *pBuf, Bu::size iBytes ) + { + Bu::size iPos = 0; + + while( iPos < iBytes ) + { + int iLeft = Bu::buMin((int)(iBytes-iPos),iBlockSize-iWriteBufFill); + memcpy( aWriteBuf+iWriteBufFill, (char *)pBuf+iPos, iLeft ); + iPos += iLeft; + iWriteBufFill += iLeft; + if( iWriteBufFill == iBlockSize ) + { + encipher( aWriteBuf ); + rNext.write( aWriteBuf, iBlockSize ); + iWriteBufFill = 0; + } + } + + return iPos; + } + + virtual void flush() + { + if( iWriteBufFill > 0 && 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; + + protected: + virtual void encipher( void *pData )=0; + virtual void decipher( void *pData )=0; + + private: + char aReadBuf[iBlockSize]; + char aWriteBuf[iBlockSize]; + int iReadBufFill; + int iReadBufPos; + int iWriteBufFill; + }; }; #endif -- cgit v1.2.3