summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-04-07 14:04:00 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-04-07 14:04:00 +0300
commit5ef8b53108f41220602febbd2e10f3b76ab32b82 (patch)
treee87fe0e88f7004114cd3156b3221ece87d077c14
parenta41079c692aa75e5e995aaf1e5c355edad5552d9 (diff)
downloadrpm-5ef8b53108f41220602febbd2e10f3b76ab32b82.tar.gz
rpm-5ef8b53108f41220602febbd2e10f3b76ab32b82.tar.bz2
rpm-5ef8b53108f41220602febbd2e10f3b76ab32b82.zip
Eliminate several copy-paste hex converters, use pgpHexStr() instead
-rw-r--r--lib/query.c15
-rw-r--r--python/rpmfi-py.c21
-rw-r--r--rpmdb/header.c3
-rw-r--r--rpmdb/header_internal.c18
-rw-r--r--rpmdb/header_internal.h7
-rw-r--r--rpmdb/rpmdb.c2
-rw-r--r--rpmio/digest.c11
7 files changed, 14 insertions, 63 deletions
diff --git a/lib/query.c b/lib/query.c
index 2ef0a3a78..20068af69 100644
--- a/lib/query.c
+++ b/lib/query.c
@@ -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;
diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c
index 15c6d3002..8f870e44d 100644
--- a/python/rpmfi-py.c
+++ b/python/rpmfi-py.c
@@ -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
diff --git a/rpmdb/header.c b/rpmdb/header.c
index 37f05fe98..320a65977 100644
--- a/rpmdb/header.c
+++ b/rpmdb/header.c
@@ -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;
diff --git a/rpmdb/header_internal.c b/rpmdb/header_internal.c
index b438bdd49..1af4bc0ab 100644
--- a/rpmdb/header_internal.c
+++ b/rpmdb/header_internal.c
@@ -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;
-}
-
-
diff --git a/rpmdb/header_internal.h b/rpmdb/header_internal.h
index 4e8cf87f5..f789fbbbe 100644
--- a/rpmdb/header_internal.h
+++ b/rpmdb/header_internal.h
@@ -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
diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c
index fcaf7f10e..d00cdfa3a 100644
--- a/rpmdb/rpmdb.c
+++ b/rpmdb/rpmdb.c
@@ -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++;
diff --git a/rpmio/digest.c b/rpmio/digest.c
index 5becb6e39..c360919d4 100644
--- a/rpmio/digest.c
+++ b/rpmio/digest.c
@@ -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) {