提交 53ef96c8 编写于 作者: W wujing 提交者: lifeng68

Use iSulad's base64 function instead of libwebsockets library function

Signed-off-by: Nwujing <wujing50@huawei.com>
上级 4dce99e8
......@@ -10,3 +10,4 @@ GTAGS
iSula-libutils
compile_commands.json
tags
.clangd
......@@ -1315,10 +1315,10 @@ static bool should_use_origin_name(const char *name)
// Convert a BigData key name into an acceptable file name.
static char *make_big_data_base_name(const char *key)
{
#define MAX_BIG_DATA_BASE_NAME_LEN 100
int ret = 0;
int nret = 0;
char encode_name[MAX_BIG_DATA_BASE_NAME_LEN] = { 0x00 };
char *b64_encode_name = NULL;
size_t b64_encode_name_len = 0;
char *base_name = NULL;
size_t name_size;
......@@ -1326,16 +1326,30 @@ static char *make_big_data_base_name(const char *key)
return util_strdup_s(key);
}
(void)lws_b64_encode_string(key, (int)strlen(key), encode_name, (int)sizeof(encode_name));
name_size = 1 + strlen(encode_name) + 1; // '=' + encode string + '\0'
b64_encode_name_len = util_base64_encode_len(strlen(key));
b64_encode_name = util_common_calloc_s(b64_encode_name_len + 1);
if (b64_encode_name == NULL) {
ERROR("Out of memory");
ret = -1;
goto out;
}
nret = util_base64_encode((unsigned char *)key, strlen(key), b64_encode_name, b64_encode_name_len);
if (nret < 0) {
ret = -1;
ERROR("Encode auth to base64 failed");
goto out;
}
name_size = 1 + strlen(b64_encode_name) + 1; // '=' + encode string + '\0'
base_name = (char *)util_common_calloc_s(name_size * sizeof(char));
if (base_name == NULL) {
ERROR("Out of memory");
return NULL;
ret = -1;
goto out;
}
nret = snprintf(base_name, name_size, "=%s", encode_name);
nret = snprintf(base_name, name_size, "=%s", b64_encode_name);
if (nret < 0 || (size_t)nret >= name_size) {
ERROR("Out of memory");
ret = -1;
......@@ -1348,6 +1362,7 @@ out:
free(base_name);
base_name = NULL;
}
free(b64_encode_name);
return base_name;
}
......@@ -2834,7 +2849,7 @@ int image_store_get_images_number()
ERROR("Failed to lock image store");
return -1;
}
number = g_image_store->images_list_len;
image_store_unlock();
......
......@@ -11,6 +11,7 @@ add_executable(${EXE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_convert.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_file.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_images.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/utils_base64.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/cutils/util_atomic.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/log.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/sha256/sha256.c
......@@ -52,4 +53,4 @@ target_include_directories(${EXE} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../../../../src/image/oci/storage/image_store
)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lwebsockets -lcrypto -lyajl -lz)
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lcrypto -lyajl -lz)
......@@ -277,7 +277,8 @@ TEST_F(StorageImagesUnitTest, test_image_store_create)
free_imagetool_image(image);
char *toplayer = NULL;
ASSERT_STREQ((toplayer = image_store_top_layer(id.c_str())), "6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a");
ASSERT_STREQ((toplayer = image_store_top_layer(id.c_str())),
"6194458b07fcf01f1483d96cd6c34302ffff7f382bb151a6d023c4e80ba3050a");
free(toplayer);
ASSERT_EQ(image_store_set_image_size(id.c_str(), 1000), 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册