20 #include <openssl/md5.h>    21 #endif  // HAVE_OPENSSL    24 using std::istringstream;
    26 using std::ostringstream;
    36   encode_hex(_hv[0], buffer);
    37   encode_hex(_hv[1], buffer + 8);
    38   encode_hex(_hv[2], buffer + 16);
    39   encode_hex(_hv[3], buffer + 24);
    40   out.write(buffer, 32);
    53   while (ch != EOF && !in.fail() && isxdigit(ch)) {
    62     in.clear(std::ios::failbit|in.rdstate());
    72   decode_hex(buffer, _hv[0]);
    73   decode_hex(buffer + 8, _hv[1]);
    74   decode_hex(buffer + 16, _hv[2]);
    75   decode_hex(buffer + 24, _hv[3]);
   120   istringstream strm(text);
   131   encode_hex(_hv[0], buffer);
   132   encode_hex(_hv[1], buffer + 8);
   133   encode_hex(_hv[2], buffer + 16);
   134   encode_hex(_hv[3], buffer + 24);
   135   return string(buffer, 32);
   144   istringstream strm(text);
   165   nassertr(text.size() == 16, 
false);
   179 hash_file(
const Filename &filename) {
   180   Filename bin_filename = Filename::binary_filename(filename);
   183   if (istr == 
nullptr) {
   188   bool result = hash_stream(*istr);
   193 #endif  // HAVE_OPENSSL   202 hash_stream(istream &stream) {
   203   unsigned char md[16];
   208   static const int buffer_size = 1024;
   209   char buffer[buffer_size];
   212   stream.seekg(0, std::ios::beg);
   214   stream.read(buffer, buffer_size);
   215   size_t count = stream.gcount();
   217     MD5_Update(&ctx, buffer, count);
   218     stream.read(buffer, buffer_size);
   219     count = stream.gcount();
   230   _hv[0] = (md[0] << 24) | (md[1] << 16) | (md[2] << 8) | (md[3]);
   231   _hv[1] = (md[4] << 24) | (md[5] << 16) | (md[6] << 8) | (md[7]);
   232   _hv[2] = (md[8] << 24) | (md[9] << 16) | (md[10] << 8) | (md[11]);
   233   _hv[3] = (md[12] << 24) | (md[13] << 16) | (md[14] << 8) | (md[15]);
   237 #endif  // HAVE_OPENSSL   247 hash_buffer(
const char *buffer, 
int length) {
   248   unsigned char md[16];
   249   MD5((
const unsigned char *)buffer, length, md);
   253   _hv[0] = (md[0] << 24) | (md[1] << 16) | (md[2] << 8) | (md[3]);
   254   _hv[1] = (md[4] << 24) | (md[5] << 16) | (md[6] << 8) | (md[7]);
   255   _hv[2] = (md[8] << 24) | (md[9] << 16) | (md[10] << 8) | (md[11]);
   256   _hv[3] = (md[12] << 24) | (md[13] << 16) | (md[14] << 8) | (md[15]);
   259 #endif  // HAVE_OPENSSL   267 encode_hex(uint32_t val, 
char *buffer) {
   268   buffer[0] = tohex(val >> 28);
   269   buffer[1] = tohex(val >> 24);
   270   buffer[2] = tohex(val >> 20);
   271   buffer[3] = tohex(val >> 16);
   272   buffer[4] = tohex(val >> 12);
   273   buffer[5] = tohex(val >> 8);
   274   buffer[6] = tohex(val >> 4);
   275   buffer[7] = tohex(val);
   282 decode_hex(
const char *buffer, uint32_t &val) {
   283   unsigned int bytes[8];
   284   for (
int i = 0; i < 8; i++) {
   285     bytes[i] = fromhex(buffer[i]);
   288   val = ((bytes[0] << 28) |
 A StreamWriter object is used to write sequential binary data directly to an ostream.
 
A hierarchy of directories and files that appears to be one continuous file system,...
 
void output_dec(std::ostream &out) const
Outputs the HashVal as four unsigned decimal integers.
 
std::istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read,...
 
Stores a 128-bit value that represents the hashed contents (typically MD5) of a file or buffer.
 
bool set_from_dec(const std::string &text)
Sets the HashVal from a string with four decimal numbers.
 
bool set_from_bin(const vector_uchar &text)
Sets the HashVal from a 16-byte binary string.
 
void output_hex(std::ostream &out) const
Outputs the HashVal as a 32-digit hexadecimal number.
 
void add_be_uint32(uint32_t value)
Adds an unsigned 32-bit big-endian integer to the streamWriter.
 
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
 
void input_binary(std::istream &in)
Inputs the HashVal as a binary stream of bytes in order.
 
The name of a file, such as a texture file or an Egg file.
 
void input_hex(std::istream &in)
Inputs the HashVal as a 32-digit hexadecimal number.
 
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
 
uint32_t get_be_uint32()
Extracts an unsigned big-endian 32-bit integer.
 
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
 
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
 
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
 
A class to retrieve the individual data elements previously stored in a Datagram.
 
A class to read sequential binary data directly from an istream.
 
void output_binary(std::ostream &out) const
Outputs the HashVal as a binary stream of bytes in order.
 
std::string as_hex() const
Returns the HashVal as a 32-byte hexadecimal string.
 
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
 
bool set_from_hex(const std::string &text)
Sets the HashVal from a 32-byte hexademical string.
 
size_t get_length() const
Returns the number of bytes in the datagram.
 
vector_uchar as_bin() const
Returns the HashVal as a 16-byte binary string.
 
std::string as_dec() const
Returns the HashVal as a string with four decimal numbers.
 
void input_dec(std::istream &in)
Inputs the HashVal as four unsigned decimal integers.
 
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.