summaryrefslogtreecommitdiff
path: root/lib/libalpm/sha1.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/sha1.c')
-rw-r--r--lib/libalpm/sha1.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/lib/libalpm/sha1.c b/lib/libalpm/sha1.c
index cf1831ea..956e87a9 100644
--- a/lib/libalpm/sha1.c
+++ b/lib/libalpm/sha1.c
@@ -386,35 +386,34 @@ documentation and/or software.
char* _alpm_SHAFile(char *filename) {
- FILE *file;
- struct sha_ctx context;
- int len, i;
- unsigned char buffer[1024], digest[20];
- char *ret;
-
- ALPM_LOG_FUNC;
-
- if((file = fopen(filename, "rb")) == NULL) {
- fprintf(stderr, _("%s can't be opened\n"), filename);
- } else {
- sha_init_ctx(&context);
- while((len = fread(buffer, 1, 1024, file))) {
- sha_process_bytes(buffer, len, &context);
+ FILE *file;
+ struct sha_ctx context;
+ int len, i;
+ unsigned char buffer[1024], digest[20];
+ char *ret;
+
+ ALPM_LOG_FUNC;
+
+ if((file = fopen(filename, "rb")) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("sha1: %s can't be opened\n"), filename);
+ } else {
+ sha_init_ctx(&context);
+ while((len = fread(buffer, 1, 1024, file))) {
+ sha_process_bytes(buffer, len, &context);
+ }
+ sha_finish_ctx(&context, digest);
+ fclose(file);
+
+ ret = (char*)malloc(41);
+ ret[0] = '\0';
+ for(i = 0; i < 20; i++) {
+ sprintf(ret+(i*2), "%02x", digest[i]);
+ }
+ _alpm_log(PM_LOG_DEBUG, _("sha1(%s) = %s"), filename, ret);
+ return(ret);
}
- sha_finish_ctx(&context, digest);
- fclose(file);
-#ifdef DEBUG
- SHAPrint(digest);
-#endif
- ret = (char*)malloc(41);
- ret[0] = '\0';
- for(i = 0; i < 20; i++) {
- sprintf(ret, "%s%02x", ret, digest[i]);
- }
- return(ret);
- }
- return(NULL);
+ return(NULL);
}
/* vim: set ts=2 sw=2 noet: */