1 Star 0 Fork 1

yuxiating/myfun

forked from ChendongSun/myfun 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qemu 2.34 KB
一键复制 编辑 原始数据 按行查看 历史
ChendongSun 提交于 2023-04-28 10:25 +08:00 . update qemu.
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int check_sha256(const char *data, size_t len, const char *sha256_str)
{
unsigned char sha256[SHA256_DIGEST_LENGTH];
char sha256_hex[2 * SHA256_DIGEST_LENGTH + 1];
int i;
// Compute SHA-256 of the input data
SHA256((const unsigned char *)data, len, sha256);
// Convert SHA-256 to hexadecimal string
for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
sprintf(&sha256_hex[2 * i], "%02x", sha256[i]);
}
sha256_hex[2 * SHA256_DIGEST_LENGTH] = '\0';
// Compare the computed SHA-256 with the given SHA-256 string
return strcmp(sha256_hex, sha256_str) == 0;
}
int main()
{
const char *data = "Hello, world!";
const char *sha256_str = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";
if (check_sha256(data, strlen(data), sha256_str)) {
printf("SHA-256 check passed!\n");
} else {
printf("SHA-256 check failed!\n");
}
return 0;
}
#######################
int64_t qmp_guest_exec_cmd(const char *filetype,
const char *filename,
const char *arg,
const char *sha256,
Error **errp)
{
int iRet = 0;
int dwRet = 0;
int exit = -1;
char pszCommand[BUFFER_SIZE] = {0};
iRet = CheckArg(filetype, filename, arg, sha256);
/*For security reasons, the command parameters are not printed.*/
slog(SLOG_INFO, "try guest-exec-cmd: %s, %s, %s", filetype, filename, sha256);
if(EXEC_ARG_OK == iRet)
{
if(snprintf(pszCommand, BUFFER_SIZE, "timeout 30 %s %s%s %s",
filetype, GUEST_CMD_FILE_PATH, filename, arg) < 0)
{
PERROR("snprintf_s failed.");
return EXEC_FAILED;
}
exit = system(pszCommand);
dwRet = WEXITSTATUS(exit);
if (SHELL_TIMEOUT_RET == dwRet)
{
/* timeout return 124 */
PERROR("execmd %s timeout.", pszCommand);
iRet = EXEC_CMD_TIME_OUT;
}
else if (dwRet)
{
PERROR("execmd %s, ret %d.", pszCommand, dwRet);
iRet = EXEC_FAILED;
}
else
{
iRet = EXEC_DONE;
}
}
return iRet;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuxiating2021/myfun.git
git@gitee.com:yuxiating2021/myfun.git
yuxiating2021
myfun
myfun
master

搜索帮助