From 03e8c5ad314252cde58c53688c70b9f836a1d5b4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 28 Nov 2012 17:39:09 +0000 Subject: More comments; moved the encryption system to unstable. --- src/experimental/cipher.h | 127 ---------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 src/experimental/cipher.h (limited to 'src/experimental/cipher.h') diff --git a/src/experimental/cipher.h b/src/experimental/cipher.h deleted file mode 100644 index 6e58613..0000000 --- a/src/experimental/cipher.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2007-2012 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#ifndef BU_CIPHER_H -#define BU_CIPHER_H - -#include "bu/filter.h" -#include "bu/util.h" - -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; - }; -}; - -#endif -- cgit v1.2.3