--- parser3/src/classes/math.C 2003/04/15 14:12:15 1.29 +++ parser3/src/classes/math.C 2003/05/26 09:32:29 1.32 @@ -8,7 +8,7 @@ Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o. */ -static const char* IDENT_MATH_C="$Date: 2003/04/15 14:12:15 $"; +static const char* IDENT_MATH_C="$Date: 2003/05/26 09:32:29 $"; #include "pa_common.h" #include "pa_vint.h" @@ -148,7 +148,7 @@ static void random(void *buffer, size_t static inline int _random(uint top) { uint raw; random(&raw, sizeof(raw)); - return int(double(raw) / 0x100000000 * top ); + return int(double(raw) / 0xFFFFFFFFu * top ); } static void _random(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -282,6 +282,24 @@ static void _crypt(Request& r, const Str } } +static const char* hex_string(Pool& pool, unsigned char* bytes, size_t size, bool upcase) { + char *bytes_hex=(char *)pool.malloc(size*2/*byte->hh*/+1/*for zero-teminator*/); + unsigned char *src=bytes; + unsigned char *end=bytes+size; + char *dest=bytes_hex; + + static const char *hex=upcase?"0123456789ABCDEF":"0123456789abcdef"; + + const char *format=upcase?"%02X":"%02x"; + for(; srcas_string(0, "parameter must be string").cstr(); @@ -293,14 +311,8 @@ static void _md5(Request& r, const Strin PA_MD5Update(&context, (const unsigned char*)string, strlen(string)); PA_MD5Final(digest, &context); - char *digest_bytes_hex=(char *)pool.malloc(sizeof(digest)*2/*byte->hh*/+1/*for zero-teminator*/); - unsigned char *src=digest; - unsigned char *end=digest+sizeof(digest); - char *dest=digest_bytes_hex; - while(src