Optimisation in hash_object
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -54,27 +54,18 @@ int full_object(struct object *obj, char *buffer, size_t buffer_size)
|
||||
void hash_object(struct object *obj, char* result)
|
||||
{
|
||||
unsigned char md_buffer[DIGEST_LENGTH] = {0};
|
||||
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
|
||||
size_t data_size = object_size(obj);
|
||||
char* data = malloc(data_size);
|
||||
full_object(obj, data, data_size);
|
||||
|
||||
char* hr_size = malloc(decimal_len(obj->size) + 1);
|
||||
sprintf(hr_size, "%li", obj->size);
|
||||
|
||||
EVP_DigestInit(ctx, EVP_sha1());
|
||||
EVP_DigestUpdate(ctx, obj->object_type, strlen(obj->object_type));
|
||||
EVP_DigestUpdate(ctx, " ", 1);
|
||||
EVP_DigestUpdate(ctx, hr_size, decimal_len(obj->size));
|
||||
EVP_DigestUpdate(ctx, "\0", 1);
|
||||
EVP_DigestUpdate(ctx, obj->content, obj->size);
|
||||
|
||||
EVP_DigestFinal(ctx, md_buffer, NULL);
|
||||
free(hr_size);
|
||||
SHA1(data, data_size, md_buffer);
|
||||
|
||||
for (int i = 0; i < DIGEST_LENGTH; i++)
|
||||
{
|
||||
sprintf((result + 2 * i), "%.2x", md_buffer[i]);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(ctx);
|
||||
free(data);
|
||||
}
|
||||
|
||||
int uncompress_object(struct object *obj, char* compressed, uLongf comp_size)
|
||||
|
||||
Reference in New Issue
Block a user