nabstracthash.h

Go to the documentation of this file.
00001 // LICENSE: (Please see the file COPYING for details)
00002 //
00003 // NUS - Nemesis Utilities System: A C++ application development framework 
00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske
00005 //
00006 //  This file is part of NUS
00007 //
00008 //  This library is free software; you can redistribute it and/or
00009 //  modify it under the terms of the GNU Lesser General Public
00010 //  License as published by the Free Software Foundation version 2.1
00011 //  of the License.
00012 //
00013 //  This library is distributed in the hope that it will be useful,
00014 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //  Lesser General Public License for more details.
00017 //
00018 //  You should have received a copy of the GNU Lesser General Public
00019 //  License along with this library; if not, write to the Free Software
00020 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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

Generated on Wed Mar 5 23:10:35 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4