diff --git a/CMakeLists_Headers.txt b/CMakeLists_Headers.txt index e6581ebb..396efcc0 100644 --- a/CMakeLists_Headers.txt +++ b/CMakeLists_Headers.txt @@ -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 diff --git a/src/include/workflow/MD5Util.h b/src/include/workflow/MD5Util.h deleted file mode 120000 index 8d8eb0df..00000000 --- a/src/include/workflow/MD5Util.h +++ /dev/null @@ -1 +0,0 @@ -../../util/MD5Util.h \ No newline at end of file diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 94b8bcd6..74d4f190 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -6,7 +6,6 @@ set(SRC EncodeStream.cc StringUtil.cc URIParser.cc - MD5Util.cc ) add_library(${PROJECT_NAME} OBJECT ${SRC}) diff --git a/src/util/MD5Util.cc b/src/util/MD5Util.cc deleted file mode 100644 index 9deeb33a..00000000 --- a/src/util/MD5Util.cc +++ /dev/null @@ -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 -#include -#include -#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 MD5Util::md5_integer_32(const std::string& str) -{ - unsigned char md[16]; - std::pair 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; -} - diff --git a/src/util/MD5Util.h b/src/util/MD5Util.h deleted file mode 100644 index 5dc356a2..00000000 --- a/src/util/MD5Util.h +++ /dev/null @@ -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 -#include -#include - -/** - * @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 md5_integer_32(const std::string& str); - //64 bit integer style - static uint64_t md5_integer_16(const std::string& str); -}; - -#endif -