diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-02-26 21:46:38 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-02-26 21:46:38 +0200 |
commit | 2579e086c2be79d2d3f7e0e8ee3c25c25edd9a7b (patch) | |
tree | 19952dd049677e13d8649f5f0a08765b90135b6c /rpmio | |
parent | 47a1e0515012d4aaf4f95fd71c4bc6de526e8d86 (diff) | |
download | rpm-2579e086c2be79d2d3f7e0e8ee3c25c25edd9a7b.tar.gz rpm-2579e086c2be79d2d3f7e0e8ee3c25c25edd9a7b.tar.bz2 rpm-2579e086c2be79d2d3f7e0e8ee3c25c25edd9a7b.zip |
Un-inline fd*Digest()
- avoid leaking nss + digest internals all over the place
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/digest.c | 85 | ||||
-rw-r--r-- | rpmio/digest.h | 1 | ||||
-rw-r--r-- | rpmio/rpmio_internal.h | 86 |
3 files changed, 90 insertions, 82 deletions
diff --git a/rpmio/digest.c b/rpmio/digest.c index c8739a759..e4ae2493d 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -166,3 +166,88 @@ DPRINTF((stderr, "*** Final(%p,%p,%p,%zd) hashctx %p digest %p\n", ctx, datap, l free(ctx); return 0; } + +void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags) +{ + FDDIGEST_t fddig = fd->digests + fd->ndigests; + if (fddig != (fd->digests + FDDIGEST_MAX)) { + fd->ndigests++; + fddig->hashalgo = hashalgo; + fdstat_enter(fd, FDSTAT_DIGEST); + fddig->hashctx = rpmDigestInit(hashalgo, flags); + fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); + } +} + +void fdUpdateDigests(FD_t fd, const unsigned char * buf, size_t buflen) +{ + int i; + + if (buf != NULL && buflen > 0) + for (i = fd->ndigests - 1; i >= 0; i--) { + FDDIGEST_t fddig = fd->digests + i; + if (fddig->hashctx == NULL) + continue; + fdstat_enter(fd, FDSTAT_DIGEST); + (void) rpmDigestUpdate(fddig->hashctx, buf, buflen); + fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) buflen); + } +} + +void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, + void ** datap, + size_t * lenp, + int asAscii) +{ + int imax = -1; + int i; + + for (i = fd->ndigests - 1; i >= 0; i--) { + FDDIGEST_t fddig = fd->digests + i; + if (fddig->hashctx == NULL) + continue; + if (i > imax) imax = i; + if (fddig->hashalgo != hashalgo) + continue; + fdstat_enter(fd, FDSTAT_DIGEST); + (void) rpmDigestFinal(fddig->hashctx, datap, lenp, asAscii); + fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); + fddig->hashctx = NULL; + break; + } + if (i < 0) { + if (datap) *datap = NULL; + if (lenp) *lenp = 0; + } + + fd->ndigests = imax; + if (i < imax) + fd->ndigests++; /* convert index to count */ +} + + +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; + } + } +} diff --git a/rpmio/digest.h b/rpmio/digest.h index 12fa4e322..21d1a1ab0 100644 --- a/rpmio/digest.h +++ b/rpmio/digest.h @@ -8,6 +8,7 @@ #include <rpm/rpmpgp.h> #include "rpmio/base64.h" +#include "rpmio/rpmio_internal.h" /** \ingroup rpmio diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index 57de0dd8b..b516f20f5 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -12,7 +12,6 @@ #include <rpm/rpmpgp.h> #include <rpm/rpmsw.h> -#include "rpmio/digest.h" /** \ingroup rpmio */ @@ -295,100 +294,23 @@ FD_t c2f(void * cookie) /** \ingroup rpmio * Attach digest to fd. */ -static inline -void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags) -{ - FDDIGEST_t fddig = fd->digests + fd->ndigests; - if (fddig != (fd->digests + FDDIGEST_MAX)) { - fd->ndigests++; - fddig->hashalgo = hashalgo; - fdstat_enter(fd, FDSTAT_DIGEST); - fddig->hashctx = rpmDigestInit(hashalgo, flags); - fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); - } -} +void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags); /** \ingroup rpmio * Update digest(s) attached to fd. */ -static inline -void fdUpdateDigests(FD_t fd, const unsigned char * buf, size_t buflen) -{ - int i; - - if (buf != NULL && buflen > 0) - for (i = fd->ndigests - 1; i >= 0; i--) { - FDDIGEST_t fddig = fd->digests + i; - if (fddig->hashctx == NULL) - continue; - fdstat_enter(fd, FDSTAT_DIGEST); - (void) rpmDigestUpdate(fddig->hashctx, buf, buflen); - fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) buflen); - } -} +void fdUpdateDigests(FD_t fd, const unsigned char * buf, size_t buflen); /** \ingroup rpmio */ -static inline void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, void ** datap, size_t * lenp, - int asAscii) -{ - int imax = -1; - int i; - - for (i = fd->ndigests - 1; i >= 0; i--) { - FDDIGEST_t fddig = fd->digests + i; - if (fddig->hashctx == NULL) - continue; - if (i > imax) imax = i; - if (fddig->hashalgo != hashalgo) - continue; - fdstat_enter(fd, FDSTAT_DIGEST); - (void) rpmDigestFinal(fddig->hashctx, datap, lenp, asAscii); - fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0); - fddig->hashctx = NULL; - break; - } - if (i < 0) { - if (datap) *datap = NULL; - if (lenp) *lenp = 0; - } - - fd->ndigests = imax; - if (i < imax) - fd->ndigests++; /* convert index to count */ -} + int asAscii); /* 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; - } - } -} +void fdStealDigest(FD_t fd, pgpDig dig); /** * Read an entire file into a buffer. |