我的程序向服务器发送一个大小为 512KB 的数据请求。为了检查数据完整性,它具有来自元信息文件的给定 SHA1。我将把接收到的数据的 SHA1 与给定的 SHA1 进行比较,但我认为出现问题是因为缓冲区太大。
int main(int argc, char** argv)
{
char given_SHA1[20]; // assume that it has some value.
char received_buffer[524288]; // Assume that this holds 512KB data from a socket. does not make sense. it is too big.
char SHA1_received[20];
SHA1(received_buffer, SHA1_received); // SHA1_received will get SHA1 of 512KB data.
if(strcmp(SHA1_received, given_SHA1) == 0)
{
printf("received data is OK\n");
}
else
{
printf("error\n");
exit(0);
}
}
有没有其他方法可以做这段代码所做的事情,而不是将 512KB 缓冲区声明为局部变量?