Panda3D
Loading...
Searching...
No Matches
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 */
31class EXPCL_PANDA_EXPRESS HashVal {
32PUBLISHED:
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
76private:
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
85INLINE std::ostream &operator << (std::ostream &out, const HashVal &hv);
86
87#include "hashVal.I"
88
89#endif
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer.
Definition hashVal.h:31
void input_binary(std::istream &in)
Inputs the HashVal as a binary stream of bytes in order.
Definition hashVal.cxx:96
void output_dec(std::ostream &out) const
Outputs the HashVal as four unsigned decimal integers.
Definition hashVal.I:103
void output_hex(std::ostream &out) const
Outputs the HashVal as a 32-digit hexadecimal number.
Definition hashVal.cxx:34
bool set_from_bin(const vector_uchar &text)
Sets the HashVal from a 16-byte binary string.
Definition hashVal.cxx:164
void output_binary(std::ostream &out) const
Outputs the HashVal as a binary stream of bytes in order.
Definition hashVal.cxx:83
void input_dec(std::istream &in)
Inputs the HashVal as four unsigned decimal integers.
Definition hashVal.I:111
bool set_from_hex(const std::string &text)
Sets the HashVal from a 32-byte hexademical string.
Definition hashVal.cxx:143
std::string as_dec() const
Returns the HashVal as a string with four decimal numbers.
Definition hashVal.cxx:108
std::string as_hex() const
Returns the HashVal as a 32-byte hexadecimal string.
Definition hashVal.cxx:129
bool set_from_dec(const std::string &text)
Sets the HashVal from a string with four decimal numbers.
Definition hashVal.cxx:119
void merge_with(const HashVal &other)
Generates a new HashVal representing the xor of this one and the other one.
Definition hashVal.I:92
vector_uchar as_bin() const
Returns the HashVal as a 16-byte binary string.
Definition hashVal.cxx:153
void input_hex(std::istream &in)
Inputs the HashVal as a 32-digit hexadecimal number.
Definition hashVal.cxx:47
An in-memory buffer specifically designed for downloading files to memory.
Definition ramfile.h:25
A class to read sequential binary data directly from an istream.
A StreamWriter object is used to write sequential binary data directly to an ostream.
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.
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.