remove MD5Util

This commit is contained in:
XieHan
2022-10-31 17:53:04 +08:00
parent b77d7599ed
commit 4aaffe02f7
5 changed files with 0 additions and 147 deletions

View File

@@ -77,7 +77,6 @@ set(INCLUDE_HEADERS
src/util/LRUCache.h
src/util/StringUtil.h
src/util/URIParser.h
src/util/MD5Util.h
src/factory/WFConnection.h
src/factory/WFTask.h
src/factory/WFTask.inl

View File

@@ -1 +0,0 @@
../../util/MD5Util.h

View File

@@ -6,7 +6,6 @@ set(SRC
EncodeStream.cc
StringUtil.cc
URIParser.cc
MD5Util.cc
)
add_library(${PROJECT_NAME} OBJECT ${SRC})

View File

@@ -1,95 +0,0 @@
/*
Copyright (c) 2019 Sogou, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Wu Jiaxu (wujiaxu@sogou-inc.com)
*/
#include <openssl/md5.h>
#include <string.h>
#include <string>
#include "MD5Util.h"
static inline void __md5(const std::string& str, unsigned char *md)
{
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, str.c_str(), str.size());
MD5_Final(md, &ctx);
}
std::string MD5Util::md5_bin(const std::string& str)
{
unsigned char md[16];
__md5(str, md);
return std::string((const char *)md, 16);
}
static inline char __hex_char(int v)
{
return v < 10 ? '0' + v : 'a' + v - 10;
}
static inline void __plain_hex(char *s, int ch)
{
*s = __hex_char(ch / 16);
*(s + 1) = __hex_char(ch % 16);
}
std::string MD5Util::md5_string_32(const std::string& str)
{
unsigned char md[16];
char out[32];
__md5(str, md);
for (int i = 0; i < 16; i++)
__plain_hex(out + (i * 2), md[i]);
return std::string((const char *)out, 32);
}
std::string MD5Util::md5_string_16(const std::string& str)
{
unsigned char md[16];
char out[16];
__md5(str, md);
for (int i = 0; i < 8; i++)
__plain_hex(out + (i * 2), md[i + 4]);
return std::string((const char *)out, 16);
}
std::pair<uint64_t, uint64_t> MD5Util::md5_integer_32(const std::string& str)
{
unsigned char md[16];
std::pair<uint64_t, uint64_t> res;
__md5(str, md);
memcpy(&res.first, md, sizeof (uint64_t));
memcpy(&res.second, md + 8, sizeof (uint64_t));
return res;
}
uint64_t MD5Util::md5_integer_16(const std::string& str)
{
unsigned char md[16];
uint64_t res;
__md5(str, md);
memcpy(&res, md + 4, sizeof (uint64_t));
return res;
}

View File

@@ -1,49 +0,0 @@
/*
Copyright (c) 2019 Sogou, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Authors: Wu Jiaxu (wujiaxu@sogou-inc.com)
*/
#ifndef _MD5UTIL_H_
#define _MD5UTIL_H_
#include <stdint.h>
#include <string>
#include <utility>
/**
* @file MD5Util.h
* @brief MD5 toolbox
*/
// static class
class MD5Util
{
public:
//128 bit binary data
static std::string md5_bin(const std::string& str);
//128 bit hex string style, lower case
static std::string md5_string_32(const std::string& str);
//64 bit hex string style, lower case
static std::string md5_string_16(const std::string& str);
//128 bit integer style
static std::pair<uint64_t, uint64_t> md5_integer_32(const std::string& str);
//64 bit integer style
static uint64_t md5_integer_16(const std::string& str);
};
#endif