Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CryptHelpers.h

Go to the documentation of this file.
00001 #ifndef CryptHelpers_H 00002 #define CryptHelpers_H 00003 00004 #include "RageFile.h" 00005 00006 // crypt headers 00007 #include "crypto51/files.h" 00008 #include "crypto51/filters.h" 00009 #include "crypto51/cryptlib.h" 00010 00011 using namespace CryptoPP; 00012 00014 class RageFileStore : public Store, private FilterPutSpaceHelper 00015 { 00016 public: 00017 class Err : public Exception 00018 { 00019 public: 00020 Err(const std::string &s) : Exception(IO_ERROR, s) {} 00021 }; 00022 class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileStore: error opening file for reading: " + filename) {}}; 00023 struct ReadErr : public Err { ReadErr(const RageFile &f) : Err("RageFileStore(" + f.GetPath() + "): read error: " + f.GetError() ) {}}; 00024 00025 RageFileStore() {} 00026 RageFileStore(const char *filename) 00027 {StoreInitialize(MakeParameters("InputFileName", filename));} 00028 00029 unsigned long MaxRetrievable() const; 00030 unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true); 00031 unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const; 00032 00033 private: 00034 void StoreInitialize(const NameValuePairs &parameters); 00035 00036 mutable RageFile m_file; // mutable because reading from a file is not a const operation 00037 byte *m_space; 00038 int m_len; 00039 bool m_waiting; 00040 }; 00041 00043 class RageFileSource : public SourceTemplate<RageFileStore> 00044 { 00045 public: 00046 typedef FileStore::Err Err; 00047 typedef FileStore::OpenErr OpenErr; 00048 typedef FileStore::ReadErr ReadErr; 00049 00050 RageFileSource(BufferedTransformation *attachment = NULL) 00051 : SourceTemplate<RageFileStore>(attachment) {} 00052 RageFileSource(std::istream &in, bool pumpAll, BufferedTransformation *attachment = NULL) 00053 : SourceTemplate<RageFileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputStreamPointer", &in));} 00054 RageFileSource(const char *filename, bool pumpAll, BufferedTransformation *attachment = NULL, bool binary=true) 00055 : SourceTemplate<RageFileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputFileName", filename)("InputBinaryMode", binary));} 00056 }; 00057 00058 00060 class RageFileSink : public Sink 00061 { 00062 public: 00063 class Err : public Exception 00064 { 00065 public: 00066 Err(const std::string &s) : Exception(IO_ERROR, s) {} 00067 }; 00068 class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileSink: error opening file for writing: " + filename) {}}; 00069 struct WriteErr : public Err { WriteErr(const RageFile &f) : Err("RageFileSink(" + f.GetPath() + "): write error: " + f.GetError()) {}}; 00070 00071 RageFileSink() {} 00072 RageFileSink(const char *filename, bool binary=true) 00073 {IsolatedInitialize(MakeParameters("OutputFileName", filename)("OutputBinaryMode", binary));} 00074 00075 void IsolatedInitialize(const NameValuePairs &parameters); 00076 unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking); 00077 bool IsolatedFlush(bool hardFlush, bool blocking); 00078 00079 private: 00080 RageFile m_file; 00081 }; 00082 00083 #endif 00084 00085 /* 00086 * (c) 2001-2004 Chris Danford 00087 * All rights reserved. 00088 * 00089 * Permission is hereby granted, free of charge, to any person obtaining a 00090 * copy of this software and associated documentation files (the 00091 * "Software"), to deal in the Software without restriction, including 00092 * without limitation the rights to use, copy, modify, merge, publish, 00093 * distribute, and/or sell copies of the Software, and to permit persons to 00094 * whom the Software is furnished to do so, provided that the above 00095 * copyright notice(s) and this permission notice appear in all copies of 00096 * the Software and that both the above copyright notice(s) and this 00097 * permission notice appear in supporting documentation. 00098 * 00099 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00100 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00101 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00102 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00103 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00104 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00105 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00106 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00107 * PERFORMANCE OF THIS SOFTWARE. 00108 */

Generated on Thu Jan 27 20:57:19 2005 for StepMania by doxygen 1.3.7