From 156b4f3fabe607dd279cb89e2baac42b110c536c Mon Sep 17 00:00:00 2001 From: wangxuanxuan Date: Fri, 16 Jun 2023 10:06:44 +0800 Subject: [PATCH 1/2] clean codecheck Signed-off-by: wangxuanxuan --- utils/src/dinput_utils_tool.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index b388881..f629918 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -37,6 +37,15 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { +namesapce { + constexpr int32_t HEX_TO_UINT8 = 2; + constexpr size_t INT32_SHORT_ID_LENGTH = 20; + constexpr size_t INT32_PLAINTEXT_LENGTH = 4; + constexpr size_t INT32_MIN_ID_LENGTH = 3; + constexpr int32_t WIDTH = 4; + constexpr unsigned char MASK = 0x0F; + constexpr int32_t DOUBLE_TIMES = 2; +} DevInfo GetLocalDeviceInfo() { DevInfo devInfo{"", "", 0}; @@ -217,9 +226,6 @@ std::string GetNodeDesc(std::string parameters) std::string GetAnonyString(const std::string &value) { - constexpr size_t INT32_SHORT_ID_LENGTH = 20; - constexpr size_t INT32_PLAINTEXT_LENGTH = 4; - constexpr size_t INT32_MIN_ID_LENGTH = 3; std::string res; std::string tmpStr("******"); size_t strLen = value.length(); @@ -263,16 +269,13 @@ std::string GetAnonyInt32(const int32_t value) std::string Sha256(const std::string& in) { - unsigned char out[SHA256_DIGEST_LENGTH * 2 + 1] = {0}; + unsigned char out[SHA256_DIGEST_LENGTH * HEX_TO_UINT8 + 1] = {0}; SHA256_CTX ctx; SHA256_Init(&ctx); SHA256_Update(&ctx, in.data(), in.size()); SHA256_Final(&out[SHA256_DIGEST_LENGTH], &ctx); // here we translate sha256 hash to hexadecimal. each 8-bit char will be presented by two characters([0-9a-f]) - constexpr int32_t WIDTH = 4; - constexpr unsigned char MASK = 0x0F; const char* hexCode = "0123456789abcdef"; - constexpr int32_t DOUBLE_TIMES = 2; for (int32_t i = 0; i < SHA256_DIGEST_LENGTH; ++i) { unsigned char value = out[SHA256_DIGEST_LENGTH + i]; // uint8_t is 2 digits in hexadecimal. -- Gitee From 06d23f9eaf1d2df0f8f23cebe0d65d3fa94a5823 Mon Sep 17 00:00:00 2001 From: wangxuanxuan Date: Fri, 16 Jun 2023 11:56:37 +0800 Subject: [PATCH 2/2] clean codecheck Signed-off-by: wangxuanxuan --- utils/src/dinput_utils_tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index f629918..48fc186 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -37,7 +37,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -namesapce { +namespace { constexpr int32_t HEX_TO_UINT8 = 2; constexpr size_t INT32_SHORT_ID_LENGTH = 20; constexpr size_t INT32_PLAINTEXT_LENGTH = 4; -- Gitee