Eliminate several copy-paste hex converters, use pgpHexStr() instead
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 7 Apr 2008 11:04:00 +0000 (14:04 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 7 Apr 2008 11:04:00 +0000 (14:04 +0300)
lib/query.c
python/rpmfi-py.c
rpmdb/header.c
rpmdb/header_internal.c
rpmdb/header_internal.h
rpmdb/rpmdb.c
rpmio/digest.c

index 2ef0a3a..20068af 100644 (file)
@@ -186,7 +186,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
        rpmfileState fstate;
        rpm_off_t fsize;
        const char * fn;
-       char fmd5[32+1];
+       char *fmd5;
        const char * fuser;
        const char * fgroup;
        const char * flink;
@@ -199,17 +199,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
        fstate = rpmfiFState(fi);
        fsize = rpmfiFSize(fi);
        fn = rpmfiFN(fi);
-       {   static char const hex[] = "0123456789abcdef";
-           unsigned const char * s = rpmfiMD5(fi);
-           char * p = fmd5;
-           int j;
-           for (j = 0; j < 16; j++) {
-               unsigned k = *s++;
-               *p++ = hex[ (k >> 4) & 0xf ];
-               *p++ = hex[ (k     ) & 0xf ];
-           }
-           *p = '\0';
-       }
+       fmd5 = pgpHexStr(rpmfiMD5(fi), rpmDigestLength(PGPHASHALGO_MD5));
        fuser = rpmfiFUser(fi);
        fgroup = rpmfiFGroup(fi);
        flink = rpmfiFLink(fi);
@@ -308,6 +298,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
            }
        }
        flushBuffer(&t, &te, 0);
+       free(fmd5);
     }
            
     rc = 0;
index 15c6d30..8f870e4 100644 (file)
@@ -5,6 +5,7 @@
 #include "system.h"
 
 #include <rpm/rpmtag.h>
+#include <rpm/rpmpgp.h>
 
 #include "header-py.h"
 #include "rpmfi-py.h"
@@ -194,19 +195,11 @@ rpmfi_iternext(rpmfiObject * s)
        int VFlags = rpmfiVFlags(s->fi);
        const char * FUser = rpmfiFUser(s->fi);
        const char * FGroup = rpmfiFGroup(s->fi);
-       const unsigned char * MD5 = rpmfiMD5(s->fi), *s = MD5;
-       char FMD5[2*16+1], *t = FMD5;
-       static const char hex[] = "0123456789abcdef";
-       int gotMD5, i;
-
-       gotMD5 = 0;
-       if (s)
-       for (i = 0; i < 16; i++) {
-           gotMD5 |= *s;
-           *t++ = hex[ (*s >> 4) & 0xf ];
-           *t++ = hex[ (*s++   ) & 0xf ];
-       }
-       *t = '\0';
+       const unsigned char * MD5 = rpmfiMD5(s->fi);
+       char *FMD5 = NULL;
+
+       if (MD5)
+           FMD5 = pgpHexStr(MD5, rpmDigestLength(PGPHASHALGO_MD5));
 
        result = PyTuple_New(13);
        if (FN == NULL) {
@@ -233,7 +226,7 @@ rpmfi_iternext(rpmfiObject * s)
            PyTuple_SET_ITEM(result, 11, Py_None);
        } else
            PyTuple_SET_ITEM(result, 11, Py_BuildValue("s", FGroup));
-       if (!gotMD5) {
+       if (!FMD5) {
            Py_INCREF(Py_None);
            PyTuple_SET_ITEM(result, 12, Py_None);
        } else
index 37f05fe..320a659 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <rpm/rpmtag.h>
 #include <rpm/rpmstring.h>
+#include <rpm/rpmpgp.h>
 #include "rpmdb/header_internal.h"
 
 #include "debug.h"
@@ -2587,7 +2588,7 @@ static char * formatValue(headerSprintfArgs hsa, sprintfTag tag, int element)
        if (val) {
            need = strlen(val);
        } else {
-           val = bin2hex(data, count);
+           val = pgpHexStr(data, count);
            need = strlen(val) + tag->pad;
        }
        break;
index b438bdd..1af4bc0 100644 (file)
@@ -168,21 +168,3 @@ void headerDump(Header h, FILE *f, int flags,
     }
 }
 
-char * bin2hex(const char *data, size_t size)
-{
-    static char const hex[] = "0123456789abcdef";
-    const char * s = data;
-    char * t, * val;
-    val = t = xmalloc(size * 2 + 1);
-    while (size-- > 0) {
-       unsigned int i;
-       i = *s++;
-       *t++ = hex[ (i >> 4) & 0xf ];
-       *t++ = hex[ (i     ) & 0xf ];
-    }
-    *t = '\0';
-
-    return val;
-}
-    
-    
index 4e8cf87..f789fbb 100644 (file)
@@ -171,13 +171,6 @@ void headerDump(Header h, FILE *f, int flags,
                const struct headerTagTableEntry_s * tags);
 #define HEADER_DUMP_INLINE   1
 
-/** \ingroup header
- * Convert binary blob to printable hex string 
- * @param[in] data             binary data
- * @param[in] count            size of data in bytes
- */
-char * bin2hex(const char *data, size_t count);
-
 #ifdef __cplusplus
 }   
 #endif
index fcaf7f1..d00cdfa 100644 (file)
@@ -1910,7 +1910,7 @@ static int mireSkip (const rpmdbMatchIterator mi)
                break;
            case RPM_BIN_TYPE:
                {
-               char * str = bin2hex((const char*) u.ptr, c);
+               char * str = pgpHexStr((const unsigned char*) u.ptr, c);
                rc = miregexec(mire, str);
                if ((!rc && !mire->notmatch) || (rc && mire->notmatch))
                    anymatch++;
index 5becb6e..c360919 100644 (file)
@@ -123,8 +123,6 @@ int
 rpmDigestFinal(DIGEST_CTX ctx, void ** datap, size_t *lenp, int asAscii)
 {
     unsigned char * digest;
-    char * t;
-    size_t i;
     size_t digestlen;
 
     if (ctx == NULL)
@@ -147,14 +145,7 @@ DPRINTF((stderr, "*** Final(%p,%p,%p,%zd) hashctx %p digest %p\n", ctx, datap, l
        if (lenp) *lenp = (2*digestlen) + 1;
        if (datap) {
            const uint8_t * s = (const uint8_t *) digest;
-           static const char const hex[] = "0123456789abcdef";
-
-           *datap = t = xmalloc((2*digestlen) + 1);
-           for (i = 0 ; i < digestlen; i++) {
-               *t++ = hex[ (unsigned)((*s >> 4) & 0x0f) ];
-               *t++ = hex[ (unsigned)((*s++   ) & 0x0f) ];
-           }
-           *t = '\0';
+           *datap = pgpHexStr(s, digestlen);
        }
     }
     if (digest) {