00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : CryptedOutputStream 00006 * Package : Zeus.ZeusBase.Security 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef CryptedOutputStreamH 00033 #define CryptedOutputStreamH 00034 00035 #include <zeusbase/System/FilterOutputStream.h> 00036 #include <zeusbase/Security/SecurityDefines.hpp> 00037 00038 BEGIN_NAMESPACE_Zeus 00039 00040 class TAbstractCrypter; 00041 00042 /***************************************************************************/ 00046 /***************************************************************************/ 00047 zeusbase_class TCryptedOutputStream : public TFilterOutputStream 00048 { 00049 public: 00050 TCryptedOutputStream(IOutputStream& rParentStream, ECryptType eType); 00051 00052 virtual Retval MQUALIFIER write(const char* pBuffer, Int iBufferSize); 00053 virtual Retval MQUALIFIER writeInt8(Int8 cData); 00054 virtual void MQUALIFIER flush(); 00055 00056 void setKey(Uint64 uldKey); 00057 void setKey(const IByteArray& rKey); 00058 00059 protected: 00060 virtual ~TCryptedOutputStream(); 00061 00062 private: 00063 00064 static TAbstractCrypter& getCryptingObject(ECryptType eType); 00065 Retval writeBufferedData(); 00066 00068 TAbstractCrypter& m_rCrypting; 00070 TByteArray m_aBufferedData; 00071 }; 00072 00073 00074 /***************************************************************************/ 00077 /***************************************************************************/ 00078 inline Retval MQUALIFIER TCryptedOutputStream::write(const char* pBuffer, Int iBufferSize) 00079 { 00080 return delegateWriteBlockToWriteInt8(pBuffer, iBufferSize); 00081 } 00082 00083 END_NAMESPACE_Zeus 00084 00085 #endif