Merge branch 'gitee-master' into gitlab-upstream

This commit is contained in:
zhengshuxin 2023-07-06 22:23:52 +08:00
commit 448cfef2ee
4 changed files with 31 additions and 40 deletions

View File

@ -22,7 +22,7 @@ static int __max_sections = DEF_DEBUG_SECTIONS;
static int *__debug_levels = NULL; static int *__debug_levels = NULL;
void acl_debug_end() void acl_debug_end(void)
{ {
if (__debug_levels != NULL) { if (__debug_levels != NULL) {
acl_myfree(__debug_levels); acl_myfree(__debug_levels);

View File

@ -6,8 +6,7 @@ namespace acl {
class istream; class istream;
class ACL_CPP_API md5 : public noncopyable class ACL_CPP_API md5 : public noncopyable {
{
public: public:
md5(void); md5(void);
~md5(void); ~md5(void);
@ -112,15 +111,17 @@ public:
#endif #endif
/** /**
* 16 MD5 32 * , .
* @param in {const void*} 128 ( 16 ) md5 in * @param in {const void*}
* >= 16 * @param len {size_t} in
* @param out {char*} * @param out {char*}
* @param size {size_t} out 33 * @param size {size_t} out , len * 2 + 1,
* @return {const char*} ( out ) * \0
* \0 32 ( \0) * @return {const char*} ( out ),
* \0 .
*/ */
static const char* hex_encode(const void *in, char* out, size_t size); static const char* hex_encode(const void *in, size_t len,
char* out, size_t size);
private: private:
unsigned int buf_[4]; unsigned int buf_[4];

View File

@ -247,7 +247,7 @@ const char* md5::get_digest(void) const
const char* md5::get_string(void) const const char* md5::get_string(void) const
{ {
const_cast<md5*>(this)->hex_encode(digest_, const_cast<md5*>(this)->hex_encode(digest_, 16,
(char*) digest_s_, sizeof(digest_s_)); (char*) digest_s_, sizeof(digest_s_));
return (const char*) digest_s_; return (const char*) digest_s_;
} }
@ -280,7 +280,7 @@ const char* md5::md5_string(const void *dat, size_t dlen,
md5.finish(); md5.finish();
const unsigned char* d = (const unsigned char*) md5.get_digest(); const unsigned char* d = (const unsigned char*) md5.get_digest();
hex_encode(d, out, size); hex_encode(d, 16, out, size);
return out; return out;
} }
@ -327,43 +327,33 @@ acl_int64 md5::md5_file(istream& in, const void *key, size_t klen,
md5.finish(); md5.finish();
const char* ptr = md5.get_digest(); const char* ptr = md5.get_digest();
hex_encode(ptr, out, size); hex_encode(ptr, 16, out, size);
return n; return n;
} }
const char* md5::hex_encode(const void *in, char* out, size_t size) static const unsigned char hex_chars[] = "0123456789abcdef";
{
size_t i;
char buf[34]; // xxx: ±ØÐëÊÇ 34 ¸ö×Ö½Ú
char *ptr;
unsigned char digest[16];
if (size < 33) { #define UCHAR_PTR(x) ((const unsigned char *)(x))
const char* md5::hex_encode(const void* in, size_t len, char* out, size_t size)
{
// size ³¤¶ÈÖÁÉÙÓ¦¸ÃΪ: len * 2 + 1
if (size < 2 * len + 1) {
abort(); abort();
} }
memcpy(digest, in, 16); const unsigned char *cp;
int ch;
size_t count, i = 0;
for (i = 0; i < 16; i++) { for (cp = UCHAR_PTR(in), count = len; count > 0; count--, cp++) {
#if _MSC_VER >= 1500 ch = *cp;
sprintf_s(&(buf[2 * i]), 3, "%02x", (unsigned char) digest[i]); out[i++] = hex_chars[(ch >> 4) & 0xf];
sprintf_s(&(buf[2 * i + 1]), 3, "%02x", out[i++] = hex_chars[ch & 0xf];
(unsigned char) (digest[i] << 4));
#else
sprintf(&(buf[2 * i]), "%02x", (unsigned char) digest[i]);
sprintf(&(buf[2 * i + 1]), "%02x",
(unsigned char) (digest[i] << 4));
#endif
} }
ptr = out; out[i] = 0;
return out;
for (i = 0; i < 32; i++) {
*ptr++ = buf[i];
}
*ptr = '\0';
return (out);
} }
} // namespace acl } // namespace acl

View File

@ -113,7 +113,7 @@ static ICMP_PKT* timer_popup(ICMP_TIMER* timer)
return (pkt); return (pkt);
} }
ICMP_TIMER *icmp_timer_new() ICMP_TIMER *icmp_timer_new(void)
{ {
ICMP_TIMER *timer; ICMP_TIMER *timer;