Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=54fd409db1de6233a628f44dce60a6dba3ae86b2
commit 54fd409db1de6233a628f44dce60a6dba3ae86b2 Author: Michel Hermier <herm...@frugalware.org> Date: Wed May 15 12:07:05 2013 +0200 libflib: Hide md5 context implementation, no need for this to be in the public API. diff --git a/lib/libflib/fmd5.c b/lib/libflib/fmd5.c index a3045c2..406c912 100644 --- a/lib/libflib/fmd5.c +++ b/lib/libflib/fmd5.c @@ -27,6 +27,37 @@ documentation and/or software. #include "fmd5.h" +#include "fstdlib.h" + +/* POINTER defines a generic pointer type */ +typedef unsigned char *POINTER; + +/* UINT2 defines a two byte word */ +typedef unsigned short int UINT2; + +/* UINT4 defines a four byte word */ +typedef unsigned int UINT4; + + +/* MD5 context. */ +typedef struct MD5_CTX { + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + + +FMD5 *f_md5_new () { + FMD5 *md5 = f_malloc (sizeof (*md5)); + + f_md5_init (md5); + return md5; +} + +void f_md5_delete (FMD5 *md5) { + f_free (md5); +} + /* Constants for MD5Transform routine. */ diff --git a/lib/libflib/fmd5.h b/lib/libflib/fmd5.h index f12bada..7b67eca 100644 --- a/lib/libflib/fmd5.h +++ b/lib/libflib/fmd5.h @@ -23,25 +23,13 @@ These notices must be retained in any copies of any part of this documentation and/or software. */ -/* POINTER defines a generic pointer type */ -typedef unsigned char *POINTER; +typedef struct MD5_CTX FMD5; -/* UINT2 defines a two byte word */ -typedef unsigned short int UINT2; +FMD5 *f_md5_new (); +void f_md5_delete (FMD5 *md5); -/* UINT4 defines a four byte word */ -typedef unsigned int UINT4; - - -/* MD5 context. */ -typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} MD5_CTX; - -void f_md5_init (MD5_CTX *); -void f_md5_update (MD5_CTX *, unsigned char *, unsigned int); -void f_md5_fini (MD5_CTX *, unsigned char [16]); +void f_md5_init (FMD5 *); +void f_md5_update (FMD5 *, unsigned char *, unsigned int); +void f_md5_fini (FMD5 *, unsigned char [16]); /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/md5driver.c b/lib/libpacman/md5driver.c index 444d00d..b9e1992 100644 --- a/lib/libpacman/md5driver.c +++ b/lib/libpacman/md5driver.c @@ -41,21 +41,25 @@ documentation and/or software. char* _pacman_MDFile(char *filename) { FILE *file; - MD_CTX context; + FMD5 *md5; int len = 0; unsigned char buffer[1024], digest[16]; + if ((md5 = f_md5_new ()) == NULL) { + return NULL; + } + if((file = fopen(filename, "rb")) == NULL) { printf (_("%s can't be opened\n"), filename); } else { char *ret; int i, x; - f_md5_init (&context); + f_md5_init (md5); while((len = fread(buffer, 1, 1024, file))) { - f_md5_update (&context, buffer, len); + f_md5_update (md5, buffer, len); } - f_md5_fini (digest, &context); + f_md5_fini (md5, digest); fclose(file); /*printf("MD5 (%s) = ", filename); MDPrint(digest); @@ -70,6 +74,7 @@ char* _pacman_MDFile(char *filename) ret[32] = '\0'; return(ret); } + f_md5_delete (md5); return(NULL); } _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git