00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef NABSTRACTHASH_H
00023 #define NABSTRACTHASH_H
00024
00032 #include <exception>
00033 #include <new>
00034 #include <openssl/evp.h>
00035
00036 #include "ndefs.h"
00037 #include "nobject.h"
00038 #include "nhash.h"
00039 #include "nstring.h"
00040 #include "ndatastream.h"
00041
00042 class NFile;
00043
00048 class DllDeclSpec NAbstractHash: public NObject {
00049 public:
00053 NAbstractHash(void);
00054
00058 virtual ~NAbstractHash(void);
00059
00065 virtual NHash calculate(const NString &str) = 0;
00066
00073 virtual NHash calculate(const NDataStream &data, nint32 size) = 0;
00074
00080 virtual NHash calculateFile(const NString &filename) = 0;
00081
00087 virtual NHash calculateFile(NFile *file) = 0;
00088
00095 bool match(const NString &str, const NString &hash);
00096
00103 bool match(const NString &str, const NHash &hash);
00104
00111 bool match(NFile *file, const NString &hash);
00112
00119 bool match(NFile *file, const NHash &hash);
00120
00121 protected:
00128 void init(const NString &hash_name);
00129
00136 int update(const void *data, int bytes);
00137
00142 NString cleanup(void);
00143
00148 void setHashBufferSize(int size);
00149
00154 int getHashBufferSize(void) const;
00155
00156 private:
00157 EVP_MD_CTX m_digest_context;
00158 const EVP_MD *m_message_digest;
00159 int m_total;
00160 int m_hash_buffer_size;
00161
00162 NAbstractHash(const NAbstractHash &other);
00163 NAbstractHash &operator=(const NAbstractHash &rhs);
00164
00169 char *p_cleanup(void);
00170 };
00171
00172 #endif // NABSTRACTHASH_H