Panda3D
 All Classes Functions Variables Enumerations
hashVal.h
00001 // Filename: hashVal.h
00002 // Created by:  drose (14Nov00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef HASHVAL_H
00016 #define HASHVAL_H
00017 
00018 #include "pandabase.h"
00019 #include "typedef.h"
00020 #include "pnotify.h"
00021 #include "ramfile.h"
00022 #include "datagram.h"
00023 #include "datagramIterator.h"
00024 #include "streamWriter.h"
00025 #include "streamReader.h"
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : HashVal
00029 // Description : Stores a 128-bit value that represents the hashed
00030 //               contents (typically MD5) of a file or buffer.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDAEXPRESS HashVal {
00033 PUBLISHED:
00034   INLINE HashVal();
00035   INLINE HashVal(const HashVal &copy);
00036   INLINE void operator = (const HashVal &copy);
00037 
00038   INLINE bool operator == (const HashVal &other) const;
00039   INLINE bool operator != (const HashVal &other) const;
00040   INLINE bool operator < (const HashVal &other) const;
00041   INLINE int compare_to(const HashVal &other) const;
00042 
00043   INLINE void merge_with(const HashVal &other);
00044 
00045   INLINE void output_dec(ostream &out) const;
00046   INLINE void input_dec(istream &in);
00047   void output_hex(ostream &out) const;
00048   void input_hex(istream &in);
00049   void output_binary(ostream &out) const;
00050   void input_binary(istream &in);
00051 
00052   INLINE void output(ostream &out) const;
00053 
00054   string as_dec() const;
00055   bool set_from_dec(const string &text);
00056 
00057   string as_hex() const;
00058   bool set_from_hex(const string &text);
00059 
00060   string as_bin() const;
00061   bool set_from_bin(const string &text);
00062 
00063   INLINE void write_datagram(Datagram &destination) const;
00064   INLINE void read_datagram(DatagramIterator &source);
00065   INLINE void write_stream(StreamWriter &destination) const;
00066   INLINE void read_stream(StreamReader &source);
00067 
00068 #ifdef HAVE_OPENSSL
00069   bool hash_file(const Filename &filename);
00070   bool hash_stream(istream &stream);
00071   INLINE void hash_ramfile(const Ramfile &ramfile);
00072   INLINE void hash_string(const string &data);
00073   void hash_buffer(const char *buffer, int length);
00074 #endif  // HAVE_OPENSSL
00075 
00076 private:
00077   static void encode_hex(PN_uint32 val, char *buffer);
00078   static void decode_hex(const char *buffer, PN_uint32 &val);
00079   INLINE static char tohex(unsigned int nibble);
00080   INLINE static unsigned int fromhex(char digit);
00081 
00082   PN_uint32 _hv[4];
00083 };
00084 
00085 INLINE ostream &operator << (ostream &out, const HashVal &hv);
00086 
00087 #include "hashVal.I"
00088 
00089 #endif
 All Classes Functions Variables Enumerations