00001
#ifndef CryptHelpers_H
00002
#define CryptHelpers_H
00003
00004
#include "RageFile.h"
00005
00006
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 ¶meters);
00035
00036 mutable
RageFile m_file;
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 ¶meters);
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
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108