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