14 #include <openssl/md5.h> 29 unsigned char digest[MD5_DIGEST_LENGTH];
37 for (
unsigned i=0; i< dsz; i++)
66 FILE* fd = fopen(filename.c_str(),
"rb" );
85 unsigned char this_digest[MD5_DIGEST_LENGTH];
86 unsigned char file_digest[MD5_DIGEST_LENGTH];
92 size_t ret = fread(file_digest,
sizeof(
unsigned char), MD5_DIGEST_LENGTH, fh);
93 if (ret != MD5_DIGEST_LENGTH) {
94 std::cerr <<
"fread could not read " << MD5_DIGEST_LENGTH <<
" items. Read only " << ret <<
" bytes." << std::endl;
100 if (MD5_Final(this_digest, &md5_sig) != 1) {
107 std::cerr <<
"Enable -DUSING_OPENSSL to use the TPZMD5Stream class." << std::endl;
122 FILE* fd = fopen(filename.c_str(),
"wb");
123 if (fd == NULL)
return 1;
140 unsigned char digest[MD5_DIGEST_LENGTH];
142 if (last_status != 1)
145 if (MD5_Final(digest, &md5_sig) != 1) {
149 if (fwrite( (
const void*) digest,
sizeof(
unsigned char), MD5_DIGEST_LENGTH, fh) < MD5_DIGEST_LENGTH)
154 std::cerr <<
"Enable -DUSING_OPENSSL to use the TPZMD5Stream class." << std::endl;
166 return MD5_Init(&md5_sig);
168 std::cerr <<
"Enable -DUSING_OPENSSL to use the TPZMD5Stream class." << std::endl;
174 virtual void Write(
const int *p,
int size) {
178 virtual void Write(
const int64_t *p,
int size) {
179 Writes<int64_t>(p,size);
182 virtual void Write(
const unsigned int *p,
int size) {
183 Writes<unsigned int>(p,size);
186 virtual void Write(
const float *p,
int size) {
187 Writes<float>(p,size);
190 virtual void Write(
const double *p,
int size) {
191 Writes<double>(p,size);
194 virtual void Write(
const long double *p,
int size) {
195 Writes<long double>(p,size);
198 virtual void Write(
const char *p,
int size) {
199 Writes<char>(p,size);
202 virtual void Write(
const std::string *p,
int size) {
204 for(c=0; c<size; c++)
206 int sz = p[c].size();
208 Write(p[c].c_str(),p[c].size());
212 virtual void Write(
const std::complex <float> *p,
int size) {
213 Writes< std::complex <float> >(p,size);
216 virtual void Write(
const std::complex <double> *p,
int size) {
217 Writes< std::complex <double> >(p,size);
220 virtual void Write(
const std::complex <long double> *p,
int size) {
221 Writes< std::complex <long double> >(p,size);
227 Writes< Fad <float> >(p,size);
231 Writes< Fad <double> >(p,size);
235 Writes< Fad <long double> >(p,size);
244 if (last_status == 1)
245 last_status = MD5_Update(&md5_sig, (
const void*) p,
sizeof(T)*size);
247 std::cerr <<
"Enable -DUSING_OPENSSL to use the TPZMD5Stream class." << std::endl;
266 virtual void Read(
int *p,
int size) {
270 virtual void Read(int64_t *p,
int size) {
274 virtual void Read(
unsigned int *p,
int size) {
278 virtual void Read(
float *p,
int size) {
282 virtual void Read(
double *p,
int size) {
286 virtual void Read(
long double *p,
int size) {
290 virtual void Read(
char *p,
int size) {
294 virtual void Read(std::string *p,
int size)
299 virtual void Read(std::complex <float> *p,
int size) {
303 virtual void Read(std::complex <double> *p,
int size) {
307 virtual void Read(std::complex <long double> *p,
int size) {
313 std::cerr <<
"ERROR: Read methods for TPZMD5Stream object invoked." << std::endl;
319 #endif // PZMD5STREAM_H int CheckMD5(FILE *fh)
Check Stream MD5 signature against MD5 signature store on file.
virtual void Read(std::complex< long double > *p, int size)
Reads size complex-long double from pointer location p.
int ResetMD5()
Reset the MD5 signature.
int WriteMD5(FILE *fh)
Write computed MD5 signature to file.
virtual void Read(float *p, int size)
Reads size floating points from pointer location p.
virtual void Read(unsigned int *p, int size)
Reads size integers from pointer location p.
virtual ~TPZMD5Stream()
Default destructor.
virtual void Read(int *p, int size)
Reads size integers from pointer location p.
virtual void Read(char *p, int size)
Reads size chars from pointer location p.
virtual void Read(std::string *p, int size)
Reads size strings from pointer location p.
virtual void Read(double *p, int size)
Reads size floating points from pointer location p.
int compare_digests(unsigned char *d1, unsigned char *d2, unsigned int dsz)
Return 0 if digests are equal. -2 otherwise.
virtual void Read(int64_t *p, int size)
Reads size longs from pointer location p.
virtual void Write(const std::complex< double > *p, int size)
Writes size complex-double at pointer location p.
void Writes(const T *p, int size)
Writes size objects of the class T at pointer location p.
virtual void Write(const float *p, int size)
Writes size floating points at pointer location p.
int CheckMD5(const std::string &filename)
Check Stream MD5 signature against MD5 signature store on file.
virtual void Read(std::complex< float > *p, int size)
Reads size complex-float from pointer location p.
virtual void Write(const unsigned int *p, int size)
Writes size integers at pointer location p.
virtual void Read(long double *p, int size)
Reads size floating points from pointer location p.
virtual void Write(const std::complex< float > *p, int size)
Writes size complex-float at pointer location p.
virtual void Write(const std::string *p, int size)
Writes size strings at pointer location p.
int WriteMD5(const std::string &filename)
Write computed MD5 signature to file.
virtual void Write(const std::complex< long double > *p, int size)
Writes size complex-long double at pointer location p.
virtual void Read(std::complex< double > *p, int size)
Reads size complex-double from pointer location p.
virtual void Write(const int64_t *p, int size)
Writes size longs at pointer location p.
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
Defines the interface for saving and reading data. Persistency.
TPZMD5Stream()
Default constructor.
virtual void Write(const char *p, int size)
Writes size chars at pointer location p.
virtual void Write(const double *p, int size)
Writes size floating points at pointer location p.
virtual void Write(const int *p, int size)
Writes size integers at pointer location p.
virtual void Write(const long double *p, int size)
Writes size floating points at pointer location p.
Implements the interface to write and check MD5 files. Persistency.