mirror of
https://github.com/simon987/sist2.git
synced 2025-12-12 06:58:54 +00:00
Update openssl api #374
This commit is contained in:
@@ -68,9 +68,7 @@ void database_scan_begin(scan_args_t *args) {
|
||||
desc->version_patch = VersionPatch;
|
||||
|
||||
// generate new index id based on timestamp
|
||||
unsigned char index_md5[MD5_DIGEST_LENGTH];
|
||||
MD5((unsigned char *) &ScanCtx.index.desc.timestamp, sizeof(ScanCtx.index.desc.timestamp), index_md5);
|
||||
buf2hex(index_md5, MD5_DIGEST_LENGTH, ScanCtx.index.desc.id);
|
||||
md5_hexdigest(&ScanCtx.index.desc.timestamp, sizeof(ScanCtx.index.desc.timestamp), ScanCtx.index.desc.id);
|
||||
|
||||
database_initialize(db);
|
||||
database_open(db);
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
#define SIST2_FS_UTIL_H
|
||||
|
||||
#include "src/sist.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#define CLOSE_FILE(f) if ((f).close != NULL) {(f).close(&(f));};
|
||||
|
||||
static int fs_read(struct vfile *f, void *buf, size_t size) {
|
||||
if (f->fd == -1) {
|
||||
SHA1_Init(&f->sha1_ctx);
|
||||
f->sha1_ctx = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(f->sha1_ctx, EVP_sha1(), NULL);
|
||||
|
||||
f->fd = open(f->filepath, O_RDONLY);
|
||||
if (f->fd == -1) {
|
||||
EVP_MD_CTX_free(f->sha1_ctx);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +22,7 @@ static int fs_read(struct vfile *f, void *buf, size_t size) {
|
||||
|
||||
if (ret != 0 && f->calculate_checksum) {
|
||||
f->has_checksum = TRUE;
|
||||
safe_sha1_update(&f->sha1_ctx, (unsigned char *) buf, ret);
|
||||
safe_digest_update(f->sha1_ctx, (unsigned char *) buf, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -27,8 +30,11 @@ static int fs_read(struct vfile *f, void *buf, size_t size) {
|
||||
|
||||
static void fs_close(struct vfile *f) {
|
||||
if (f->fd != -1) {
|
||||
SHA1_Final(f->sha1_digest, &f->sha1_ctx);
|
||||
EVP_DigestFinal_ex(f->sha1_ctx, f->sha1_digest, NULL);
|
||||
EVP_MD_CTX_free(f->sha1_ctx);
|
||||
f->sha1_ctx = NULL;
|
||||
close(f->fd);
|
||||
f->fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/util.h
18
src/util.h
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "third-party/utf8.h/utf8.h"
|
||||
#include "libscan/scan.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
char *abspath(const char *path);
|
||||
@@ -86,13 +87,22 @@ static void buf2hex(const unsigned char *buf, size_t buflen, char *hex_string) {
|
||||
*s = '\0';
|
||||
}
|
||||
|
||||
static void md5_hexdigest(void *data, size_t size, char *output) {
|
||||
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL);
|
||||
|
||||
EVP_DigestUpdate(md_ctx, data, size);
|
||||
|
||||
unsigned char digest[MD5_DIGEST_LENGTH];
|
||||
EVP_DigestFinal_ex(md_ctx, digest, NULL);
|
||||
EVP_MD_CTX_free(md_ctx);
|
||||
|
||||
buf2hex(digest, MD5_DIGEST_LENGTH, output);
|
||||
}
|
||||
|
||||
__always_inline
|
||||
static void generate_doc_id(const char *rel_path, char *doc_id) {
|
||||
unsigned char md[MD5_DIGEST_LENGTH];
|
||||
|
||||
MD5((unsigned char *) rel_path, strlen(rel_path), md);
|
||||
buf2hex(md, sizeof(md), doc_id);
|
||||
md5_hexdigest(rel_path, strlen(rel_path), doc_id);
|
||||
}
|
||||
|
||||
#define MILLISECOND 1000
|
||||
|
||||
Reference in New Issue
Block a user