mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-14 00:40:55 +08:00
Merge branch 'gitee-master' into gitlab-upstream
This commit is contained in:
commit
448cfef2ee
@ -22,7 +22,7 @@ static int __max_sections = DEF_DEBUG_SECTIONS;
|
||||
|
||||
static int *__debug_levels = NULL;
|
||||
|
||||
void acl_debug_end()
|
||||
void acl_debug_end(void)
|
||||
{
|
||||
if (__debug_levels != NULL) {
|
||||
acl_myfree(__debug_levels);
|
||||
|
@ -6,8 +6,7 @@ namespace acl {
|
||||
|
||||
class istream;
|
||||
|
||||
class ACL_CPP_API md5 : public noncopyable
|
||||
{
|
||||
class ACL_CPP_API md5 : public noncopyable {
|
||||
public:
|
||||
md5(void);
|
||||
~md5(void);
|
||||
@ -112,15 +111,17 @@ public:
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 将 16 字节长度的 MD5 二进制结果转换为 32 字节长度的字符串
|
||||
* @param in {const void*} 128 位(即 16 字节)的 md5 值,即 in 的数据长度
|
||||
* 至少应该 >= 16,否则会引起内存起越界
|
||||
* 通过将一个字节变成两个字节, 将二进制数据转换为字符串数据.
|
||||
* @param in {const void*} 输入的二进制数据地址
|
||||
* @param len {size_t} in 的长度
|
||||
* @param out {char*} 存储字符串形式的结果
|
||||
* @param size {size_t} out 内存大小,至少为 33 字节,否则内部产生断言
|
||||
* @return {const char*} 返回存储结果的地址(即 out 地址),
|
||||
* 且返回值为以 \0 结尾的 32 字节长度(不含 \0)字符串
|
||||
* @param size {size_t} out 内存大小, 至少为 len * 2 + 1,
|
||||
* 最后一个字节存 \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:
|
||||
unsigned int buf_[4];
|
||||
|
@ -247,7 +247,7 @@ const char* md5::get_digest(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_));
|
||||
return (const char*) digest_s_;
|
||||
}
|
||||
@ -280,7 +280,7 @@ const char* md5::md5_string(const void *dat, size_t dlen,
|
||||
md5.finish();
|
||||
|
||||
const unsigned char* d = (const unsigned char*) md5.get_digest();
|
||||
hex_encode(d, out, size);
|
||||
hex_encode(d, 16, out, size);
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -327,43 +327,33 @@ acl_int64 md5::md5_file(istream& in, const void *key, size_t klen,
|
||||
md5.finish();
|
||||
|
||||
const char* ptr = md5.get_digest();
|
||||
hex_encode(ptr, out, size);
|
||||
hex_encode(ptr, 16, out, size);
|
||||
return n;
|
||||
}
|
||||
|
||||
const char* md5::hex_encode(const void *in, char* out, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
char buf[34]; // xxx: ±ØÐëÊÇ 34 ¸ö×Ö½Ú
|
||||
char *ptr;
|
||||
unsigned char digest[16];
|
||||
static const unsigned char hex_chars[] = "0123456789abcdef";
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
memcpy(digest, in, 16);
|
||||
const unsigned char *cp;
|
||||
int ch;
|
||||
size_t count, i = 0;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
#if _MSC_VER >= 1500
|
||||
sprintf_s(&(buf[2 * i]), 3, "%02x", (unsigned char) digest[i]);
|
||||
sprintf_s(&(buf[2 * i + 1]), 3, "%02x",
|
||||
(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
|
||||
for (cp = UCHAR_PTR(in), count = len; count > 0; count--, cp++) {
|
||||
ch = *cp;
|
||||
out[i++] = hex_chars[(ch >> 4) & 0xf];
|
||||
out[i++] = hex_chars[ch & 0xf];
|
||||
}
|
||||
|
||||
ptr = out;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
*ptr++ = buf[i];
|
||||
}
|
||||
|
||||
*ptr = '\0';
|
||||
return (out);
|
||||
out[i] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace acl
|
||||
|
@ -113,7 +113,7 @@ static ICMP_PKT* timer_popup(ICMP_TIMER* timer)
|
||||
return (pkt);
|
||||
}
|
||||
|
||||
ICMP_TIMER *icmp_timer_new()
|
||||
ICMP_TIMER *icmp_timer_new(void)
|
||||
{
|
||||
ICMP_TIMER *timer;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user