Panda3D
 All Classes Functions Variables Enumerations
hashVal.h
1 // Filename: hashVal.h
2 // Created by: drose (14Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef HASHVAL_H
16 #define HASHVAL_H
17 
18 #include "pandabase.h"
19 #include "typedef.h"
20 #include "pnotify.h"
21 #include "ramfile.h"
22 #include "datagram.h"
23 #include "datagramIterator.h"
24 #include "streamWriter.h"
25 #include "streamReader.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : HashVal
29 // Description : Stores a 128-bit value that represents the hashed
30 // contents (typically MD5) of a file or buffer.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDAEXPRESS HashVal {
33 PUBLISHED:
34  INLINE HashVal();
35  INLINE HashVal(const HashVal &copy);
36  INLINE void operator = (const HashVal &copy);
37 
38  INLINE bool operator == (const HashVal &other) const;
39  INLINE bool operator != (const HashVal &other) const;
40  INLINE bool operator < (const HashVal &other) const;
41  INLINE int compare_to(const HashVal &other) const;
42 
43  INLINE void merge_with(const HashVal &other);
44 
45  INLINE void output_dec(ostream &out) const;
46  INLINE void input_dec(istream &in);
47  void output_hex(ostream &out) const;
48  void input_hex(istream &in);
49  void output_binary(ostream &out) const;
50  void input_binary(istream &in);
51 
52  INLINE void output(ostream &out) const;
53 
54  string as_dec() const;
55  bool set_from_dec(const string &text);
56 
57  string as_hex() const;
58  bool set_from_hex(const string &text);
59 
60  string as_bin() const;
61  bool set_from_bin(const string &text);
62 
63  INLINE void write_datagram(Datagram &destination) const;
64  INLINE void read_datagram(DatagramIterator &source);
65  INLINE void write_stream(StreamWriter &destination) const;
66  INLINE void read_stream(StreamReader &source);
67 
68 #ifdef HAVE_OPENSSL
69  bool hash_file(const Filename &filename);
70  bool hash_stream(istream &stream);
71  INLINE void hash_ramfile(const Ramfile &ramfile);
72  INLINE void hash_string(const string &data);
73  void hash_buffer(const char *buffer, int length);
74 #endif // HAVE_OPENSSL
75 
76 private:
77  static void encode_hex(PN_uint32 val, char *buffer);
78  static void decode_hex(const char *buffer, PN_uint32 &val);
79  INLINE static char tohex(unsigned int nibble);
80  INLINE static unsigned int fromhex(char digit);
81 
82  PN_uint32 _hv[4];
83 };
84 
85 INLINE ostream &operator << (ostream &out, const HashVal &hv);
86 
87 #include "hashVal.I"
88 
89 #endif
A StreamWriter object is used to write sequential binary data directly to an ostream.
Definition: streamWriter.h:33
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer...
Definition: hashVal.h:32
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
An in-memory buffer specifically designed for downloading files to memory.
Definition: ramfile.h:27
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
A class to retrieve the individual data elements previously stored in a Datagram. ...
A class to read sequential binary data directly from an istream.
Definition: streamReader.h:30
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43