Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

oblowfishstream.hpp

00001 /************************************************************************************
00002  *    This file is part of the MynahSA streaming and archiving toolkit              *
00003  *    Copyright (C) 2006 Mynah-Software Ltd. All Rights Reserved.                   *
00004  *                                                                                  *
00005  *    This program is free software; you can redistribute it and/or modify          *
00006  *    it under the terms of the GNU General Public License, version 2               *
00007  *    as published by the Free Software Foundation.                                 *
00008  *                                                                                  *
00009  *    This program is distributed in the hope that it will be useful,               *
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00012  *    GNU General Public License for more details.                                  *
00013  *                                                                                  *
00014  *    You should have received a copy of the GNU General Public License along       *
00015  *    with this program; if not, write to the Free Software Foundation, Inc.,       *
00016  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                   *
00017  *                                                                                  *
00018  ************************************************************************************/
00019 
00020 #ifndef __o_blowfish_stream_hpp
00021 #define __o_blowfish_stream_hpp
00022 
00023 #include <mynahsa/ostreambase.hpp>
00024 
00025 #include <openssl/blowfish.h>
00026 
00027 #include <iostream>
00028 
00029 namespace MynahSA { 
00030   class OBlowfishStream : public OStreamBase {
00031   public:
00032     
00041     OBlowfishStream(std::ostream& os, const std::string& key);
00042     
00044     OBlowfishStream(const OBlowfishStream& os);
00045     
00047     virtual ~OBlowfishStream();
00048     
00050     virtual OStreamBase& operator<<(const char);
00051     
00053     virtual OStreamBase& operator<<(const unsigned char);
00054     
00056     virtual OStreamBase& operator<<(const short);
00057     
00059     virtual OStreamBase& operator<<(const unsigned short);
00060     
00062     virtual OStreamBase& operator<<(const bool);
00063     
00065     virtual OStreamBase& operator<<(const int);
00066     
00068     virtual OStreamBase& operator<<(const unsigned int);
00069     
00071     virtual OStreamBase& operator<<(const long long);
00072     
00074     virtual OStreamBase& operator<<(const unsigned long long);
00075     
00077     virtual OStreamBase& operator<<(const double);
00078     
00080     virtual OStreamBase& operator<<(const float);   
00081         
00082     // using declaration to make base class members accessible
00083     using OStreamBase::operator<<;
00084 
00086     void close();
00087 
00088     
00089   private:
00096     void flush();
00097     
00099     void bfWriteChar(unsigned char value);
00100 
00102     std::ostream& _os;
00103     
00105     unsigned char _buffer[8];
00106     
00108     unsigned char _outBuffer[8];
00109     
00111     unsigned char _ivec[8];
00112     
00114     unsigned int _buffPtr;
00115   
00117     BF_KEY _bfKey;
00118     
00120     bool _open;
00121     
00122 
00123   };  // class OBlowfishStream
00124 
00125 };  // namespace MynahSA
00126 
00127 #endif