summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2007-11-16 17:18:55 +0200
committerPanu Matilainen <pmatilai@redhat.com>2007-11-16 17:18:55 +0200
commit3587db8c4e5f72cf00d2722d06f9d7face2d072a (patch)
treef9139197a7a4b8e48392a966aace6f3008cba7e0
parent157759299d796bad84a58b5a50586883e086b1ec (diff)
downloadrpm-3587db8c4e5f72cf00d2722d06f9d7face2d072a.tar.gz
rpm-3587db8c4e5f72cf00d2722d06f9d7face2d072a.tar.bz2
rpm-3587db8c4e5f72cf00d2722d06f9d7face2d072a.zip
Eliminate copy-paste fd digest stealing, stuff into rpmio_internal
-rw-r--r--lib/package.c22
-rw-r--r--lib/rpmchecksig.c25
-rw-r--r--rpmio/rpmio_internal.h29
3 files changed, 31 insertions, 45 deletions
diff --git a/lib/package.c b/lib/package.c
index aa309db86..edbf9e930 100644
--- a/lib/package.c
+++ b/lib/package.c
@@ -689,7 +689,6 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp)
rpmVSFlags vsflags;
rpmRC rc = RPMRC_FAIL; /* assume failure */
int xx;
- int i;
if (hdrp) *hdrp = NULL;
@@ -906,26 +905,7 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp)
goto exit;
}
- /* XXX Steal the digest-in-progress from the file handle. */
- for (i = fd->ndigests - 1; i >= 0; i--) {
- FDDIGEST_t fddig = fd->digests + i;
- if (fddig->hashctx != NULL)
- switch (fddig->hashalgo) {
- case PGPHASHALGO_MD5:
- dig->md5ctx = fddig->hashctx;
- fddig->hashctx = NULL;
- break;
- case PGPHASHALGO_SHA1:
- case PGPHASHALGO_SHA256:
- case PGPHASHALGO_SHA384:
- case PGPHASHALGO_SHA512:
- dig->sha1ctx = fddig->hashctx;
- fddig->hashctx = NULL;
- break;
- default:
- break;
- }
- }
+ fdStealDigest(fd, dig);
break;
}
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
index 3b6ba1984..ebcc7bde5 100644
--- a/lib/rpmchecksig.c
+++ b/lib/rpmchecksig.c
@@ -469,7 +469,6 @@ static int readFile(FD_t fd, const char * fn, pgpDig dig)
unsigned char buf[4*BUFSIZ];
ssize_t count;
int rc = 1;
- int i;
dig->nbytes = 0;
@@ -511,29 +510,7 @@ static int readFile(FD_t fd, const char * fn, pgpDig dig)
rpmlog(RPMERR_FREAD, _("%s: Fread failed: %s\n"), fn, Fstrerror(fd));
goto exit;
}
-
- /* XXX Steal the digest-in-progress from the file handle. */
- for (i = fd->ndigests - 1; i >= 0; i--) {
- FDDIGEST_t fddig = fd->digests + i;
- if (fddig->hashctx != NULL)
- switch (fddig->hashalgo) {
- case PGPHASHALGO_MD5:
-assert(dig->md5ctx == NULL);
- dig->md5ctx = fddig->hashctx;
- fddig->hashctx = NULL;
- break;
- case PGPHASHALGO_SHA1:
- case PGPHASHALGO_SHA256:
- case PGPHASHALGO_SHA384:
- case PGPHASHALGO_SHA512:
-assert(dig->sha1ctx == NULL);
- dig->sha1ctx = fddig->hashctx;
- fddig->hashctx = NULL;
- break;
- default:
- break;
- }
- }
+ fdStealDigest(fd, dig);
rc = 0;
diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h
index 2ddff69af..8047b824e 100644
--- a/rpmio/rpmio_internal.h
+++ b/rpmio/rpmio_internal.h
@@ -588,6 +588,35 @@ void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo,
fd->ndigests++; /* convert index to count */
}
+
+/* XXX Steal the digest-in-progress from the file handle. */
+static inline
+void fdStealDigest(FD_t fd, pgpDig dig)
+{
+ int i;
+ for (i = fd->ndigests - 1; i >= 0; i--) {
+ FDDIGEST_t fddig = fd->digests + i;
+ if (fddig->hashctx != NULL)
+ switch (fddig->hashalgo) {
+ case PGPHASHALGO_MD5:
+assert(dig->md5ctx == NULL);
+ dig->md5ctx = fddig->hashctx;
+ fddig->hashctx = NULL;
+ break;
+ case PGPHASHALGO_SHA1:
+ case PGPHASHALGO_SHA256:
+ case PGPHASHALGO_SHA384:
+ case PGPHASHALGO_SHA512:
+assert(dig->sha1ctx == NULL);
+ dig->sha1ctx = fddig->hashctx;
+ fddig->hashctx = NULL;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
/**
* Read an entire file into a buffer.
* @param fn file name to read