diff options
author | jbj <devnull@localhost> | 2001-10-19 22:47:40 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2001-10-19 22:47:40 +0000 |
commit | d589b29c7fd3fa9c77f4ba6810fe8654cf67e2a1 (patch) | |
tree | c4808ca07db1c37d9d0d007c692b641be83a7114 | |
parent | e2dfa4f2d4f643ff2c47adfc8ae6b4b700c62b8b (diff) | |
download | librpm-tizen-d589b29c7fd3fa9c77f4ba6810fe8654cf67e2a1.tar.gz librpm-tizen-d589b29c7fd3fa9c77f4ba6810fe8654cf67e2a1.tar.bz2 librpm-tizen-d589b29c7fd3fa9c77f4ba6810fe8654cf67e2a1.zip |
Permit multiple, simultaneous, digests on a single FD_t.
CVS patchset: 5125
CVS date: 2001/10/19 22:47:40
-rw-r--r-- | build/pack.c | 2 | ||||
-rw-r--r-- | lib/fsm.c | 2 | ||||
-rw-r--r-- | lib/misc.c | 2 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 57 | ||||
-rw-r--r-- | po/rpm.pot | 66 | ||||
-rw-r--r-- | rpmio/rpmio.c | 30 | ||||
-rw-r--r-- | rpmio/rpmio_internal.h | 122 | ||||
-rw-r--r-- | rpmio/rpmpgp.h | 8 | ||||
-rw-r--r-- | rpmio/tdigest.c | 4 |
9 files changed, 156 insertions, 137 deletions
diff --git a/build/pack.c b/build/pack.c index d784e203b..b1edc6580 100644 --- a/build/pack.c +++ b/build/pack.c @@ -520,7 +520,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, rpmError(RPMERR_NOSPACE, _("Unable to write final header\n")); } (void) Fflush(fd); - fdFiniDigest(fd, (void **)&sha1, NULL, 1); + fdFiniDigest(fd, PGPHASHALGO_SHA1, (void **)&sha1, NULL, 1); (void) Fclose(fd); fd = NULL; @@ -720,7 +720,7 @@ static int expandRegular(/*@special@*/ FSM_t fsm) const char * md5sum = NULL; (void) Fflush(fsm->wfd); - fdFiniDigest(fsm->wfd, (void **)&md5sum, NULL, 1); + fdFiniDigest(fsm->wfd, PGPHASHALGO_MD5, (void **)&md5sum, NULL, 1); if (md5sum == NULL) { rc = CPIOERR_MD5SUM_MISMATCH; diff --git a/lib/misc.c b/lib/misc.c index efa31c603..635b18715 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -37,7 +37,7 @@ int domd5(const char * fn, unsigned char * digest, int asAscii) while ((rc = Fread(buf, sizeof(buf[0]), sizeof(buf), fd)) > 0) {}; - fdFiniDigest(fd, (void **)&md5sum, &md5len, asAscii); + fdFiniDigest(fd, PGPHASHALGO_MD5, (void **)&md5sum, &md5len, asAscii); if (Ferror(fd)) rc = 1; diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 9f0c226d3..eb6d4bc50 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -14,9 +14,10 @@ #include "misc.h" /* XXX for makeTempFile() */ #include "debug.h" -/*@access Header@*/ /* XXX compared with NULL */ -/*@access FD_t@*/ /* XXX compared with NULL */ -/*@access rpmDigest@*/ +/*@access Header @*/ /* XXX compared with NULL */ +/*@access FD_t @*/ /* XXX compared with NULL */ +/*@access DIGEST_CTX @*/ /* XXX compared with NULL */ +/*@access rpmDigest @*/ static int manageFile(FD_t *fdp, const char **fnp, int flags, /*@unused@*/ int rc) @@ -251,9 +252,17 @@ rpmDigest freeDig(/*@only@*/ /*@null@*/ rpmDigest dig) /*@modifies dig @*/ { if (dig != NULL) { - dig->md5ctx = _free(dig->md5ctx); + /*@-branchstate@*/ + if (dig->md5ctx != NULL) + (void) rpmDigestFinal(dig->md5ctx, NULL, NULL, 0); + /*@=branchstate@*/ + dig->md5ctx = NULL; dig->md5 = _free(dig->md5); - dig->sha1ctx = _free(dig->sha1ctx); + /*@-branchstate@*/ + if (dig->sha1ctx != NULL) + (void) rpmDigestFinal(dig->sha1ctx, NULL, NULL, 0); + /*@=branchstate@*/ + dig->sha1ctx = NULL; dig->sha1 = _free(dig->sha1); dig->hash_data = _free(dig->hash_data); @@ -287,25 +296,27 @@ static int readFile(FD_t *sfdp, const char **sfnp, rpmDigest dig) /*@modifies *sfdp, *sfnp, *dig, rpmGlobalMacroContext, fileSystem, internalState @*/ { - unsigned char buffer[BUFSIZ]; + byte buffer[4*BUFSIZ]; ssize_t count; int rc = 1; - int xx; + int i, xx; if (manageFile(sfdp, sfnp, O_RDONLY, 0)) goto exit; /*@-type@*/ /* FIX: cast? */ fdInitDigest(*sfdp, PGPHASHALGO_MD5, 0); - dig->sha1ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE); + fdInitDigest(*sfdp, PGPHASHALGO_SHA1, 0); /*@=type@*/ dig->nbytes = 0; while ((count = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), *sfdp)) > 0) { +#ifdef DYING /*@-type@*/ /* FIX: cast? */ xx = rpmDigestUpdate(dig->sha1ctx, buffer, count); /*@=type@*/ +#endif dig->nbytes += count; } @@ -316,10 +327,30 @@ static int readFile(FD_t *sfdp, const char **sfnp, rpmDigest dig) dig->nbytes += count; /*@-type@*/ /* FIX: cast? */ - dig->md5ctx = _free(dig->md5ctx); - dig->md5ctx = (*sfdp)->digest; + for (i = (*sfdp)->ndigests - 1; i >= 0; i--) { + FDDIGEST_t fddig = (*sfdp)->digests + i; + if (fddig->hashctx == NULL) + continue; + if (fddig->hashalgo == PGPHASHALGO_MD5) { + /*@-branchstate@*/ + if (dig->md5ctx != NULL) + (void) rpmDigestFinal(dig->md5ctx, NULL, NULL, 0); + /*@=branchstate@*/ + dig->md5ctx = fddig->hashctx; + fddig->hashctx = NULL; + continue; + } + if (fddig->hashalgo == PGPHASHALGO_SHA1) { + /*@-branchstate@*/ + if (dig->sha1ctx != NULL) + (void) rpmDigestFinal(dig->sha1ctx, NULL, NULL, 0); + /*@=branchstate@*/ + dig->sha1ctx = fddig->hashctx; + fddig->hashctx = NULL; + continue; + } + } /*@=type@*/ - (*sfdp)->digest = NULL; rc = 0; @@ -421,6 +452,7 @@ if (rpmIsDebug()) fprintf(stderr, "========================= Package RSA Signature\n"); xx = pgpPrtPkts(ptr, count, dig, rpmIsDebug()); /*@-type@*/ /* FIX: cast? */ + /*@-nullpass@*/ /* FIX: dig->md5ctx may be null */ { DIGEST_CTX ctx = rpmDigestDup(dig->md5ctx); xx = rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); @@ -428,6 +460,7 @@ fprintf(stderr, "========================= Package RSA Signature\n"); /* XXX compare leading 16 bits of digest for quick check. */ } + /*@=nullpass@*/ /*@=type@*/ /* XXX retrieve by keyid from signature. */ if (pgppk == NULL) { @@ -466,11 +499,13 @@ if (rpmIsDebug()) fprintf(stderr, "========================= Package DSA Signature\n"); xx = pgpPrtPkts(ptr, count, dig, rpmIsDebug()); /*@-type@*/ /* FIX: cast? */ + /*@-nullpass@*/ /* FIX: dig->sha1ctx may be null */ { DIGEST_CTX ctx = rpmDigestDup(dig->sha1ctx); xx = rpmDigestUpdate(ctx, &dig->sig.v3.sigtype, dig->sig.v3.hashlen); xx = rpmDigestFinal(ctx, (void **)&dig->sha1, &dig->sha1len, 1); mp32nzero(&dig->hm); mp32nsethex(&dig->hm, dig->sha1); } + /*@=nullpass@*/ /*@=type@*/ /* XXX retrieve by keyid from signature. */ if (gpgpk == NULL) { diff --git a/po/rpm.pot b/po/rpm.pot index d1ac61a5b..5b84c68aa 100644 --- a/po/rpm.pot +++ b/po/rpm.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-10-19 15:08-0400\n" +"POT-Creation-Date: 2001-10-19 18:20-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -3027,86 +3027,86 @@ msgstr "" msgid "package %s is not installed\n" msgstr "" -#: lib/rpmchecksig.c:46 +#: lib/rpmchecksig.c:47 #, c-format msgid "%s: open failed: %s\n" msgstr "" -#: lib/rpmchecksig.c:58 +#: lib/rpmchecksig.c:59 msgid "makeTempFile failed\n" msgstr "" -#: lib/rpmchecksig.c:100 +#: lib/rpmchecksig.c:101 #, c-format msgid "%s: Fwrite failed: %s\n" msgstr "" -#: lib/rpmchecksig.c:106 lib/rpmchecksig.c:313 +#: lib/rpmchecksig.c:107 lib/rpmchecksig.c:324 #, c-format msgid "%s: Fread failed: %s\n" msgstr "" -#: lib/rpmchecksig.c:143 lib/rpmchecksig.c:368 +#: lib/rpmchecksig.c:144 lib/rpmchecksig.c:399 #, c-format msgid "%s: readLead failed\n" msgstr "" -#: lib/rpmchecksig.c:148 +#: lib/rpmchecksig.c:149 #, c-format msgid "%s: Can't sign v1.0 RPM\n" msgstr "" -#: lib/rpmchecksig.c:152 +#: lib/rpmchecksig.c:153 #, c-format msgid "%s: Can't re-sign v2.0 RPM\n" msgstr "" -#: lib/rpmchecksig.c:161 lib/rpmchecksig.c:384 +#: lib/rpmchecksig.c:162 lib/rpmchecksig.c:415 #, c-format msgid "%s: rpmReadSignature failed\n" msgstr "" -#: lib/rpmchecksig.c:165 lib/rpmchecksig.c:389 +#: lib/rpmchecksig.c:166 lib/rpmchecksig.c:420 #, c-format msgid "%s: No signature available\n" msgstr "" -#: lib/rpmchecksig.c:198 +#: lib/rpmchecksig.c:199 #, c-format msgid "%s: writeLead failed: %s\n" msgstr "" -#: lib/rpmchecksig.c:204 +#: lib/rpmchecksig.c:205 #, c-format msgid "%s: rpmWriteSignature failed: %s\n" msgstr "" -#: lib/rpmchecksig.c:374 +#: lib/rpmchecksig.c:405 #, c-format msgid "%s: No signature available (v1.0 RPM)\n" msgstr "" -#: lib/rpmchecksig.c:604 +#: lib/rpmchecksig.c:639 msgid "NOT OK" msgstr "" -#: lib/rpmchecksig.c:605 lib/rpmchecksig.c:619 +#: lib/rpmchecksig.c:640 lib/rpmchecksig.c:654 msgid " (MISSING KEYS:" msgstr "" -#: lib/rpmchecksig.c:607 lib/rpmchecksig.c:621 +#: lib/rpmchecksig.c:642 lib/rpmchecksig.c:656 msgid ") " msgstr "" -#: lib/rpmchecksig.c:608 lib/rpmchecksig.c:622 +#: lib/rpmchecksig.c:643 lib/rpmchecksig.c:657 msgid " (UNTRUSTED KEYS:" msgstr "" -#: lib/rpmchecksig.c:610 lib/rpmchecksig.c:624 +#: lib/rpmchecksig.c:645 lib/rpmchecksig.c:659 msgid ")" msgstr "" -#: lib/rpmchecksig.c:618 +#: lib/rpmchecksig.c:653 msgid "OK" msgstr "" @@ -3832,59 +3832,59 @@ msgstr "" msgid "File %s is smaller than %u bytes\n" msgstr "" -#: rpmio/rpmio.c:644 +#: rpmio/rpmio.c:656 msgid "Success" msgstr "" -#: rpmio/rpmio.c:647 +#: rpmio/rpmio.c:659 msgid "Bad server response" msgstr "" -#: rpmio/rpmio.c:650 +#: rpmio/rpmio.c:662 msgid "Server I/O error" msgstr "" -#: rpmio/rpmio.c:653 +#: rpmio/rpmio.c:665 msgid "Server timeout" msgstr "" -#: rpmio/rpmio.c:656 +#: rpmio/rpmio.c:668 msgid "Unable to lookup server host address" msgstr "" -#: rpmio/rpmio.c:659 +#: rpmio/rpmio.c:671 msgid "Unable to lookup server host name" msgstr "" -#: rpmio/rpmio.c:662 +#: rpmio/rpmio.c:674 msgid "Failed to connect to server" msgstr "" -#: rpmio/rpmio.c:665 +#: rpmio/rpmio.c:677 msgid "Failed to establish data connection to server" msgstr "" -#: rpmio/rpmio.c:668 +#: rpmio/rpmio.c:680 msgid "I/O error to local file" msgstr "" -#: rpmio/rpmio.c:671 +#: rpmio/rpmio.c:683 msgid "Error setting remote server to passive mode" msgstr "" -#: rpmio/rpmio.c:674 +#: rpmio/rpmio.c:686 msgid "File not found on server" msgstr "" -#: rpmio/rpmio.c:677 +#: rpmio/rpmio.c:689 msgid "Abort in progress" msgstr "" -#: rpmio/rpmio.c:681 +#: rpmio/rpmio.c:693 msgid "Unknown or unexpected error" msgstr "" -#: rpmio/rpmio.c:1353 +#: rpmio/rpmio.c:1365 #, c-format msgid "logging into %s as %s, pw %s\n" msgstr "" diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c index 169641972..a23793940 100644 --- a/rpmio/rpmio.c +++ b/rpmio/rpmio.c @@ -302,6 +302,8 @@ static inline /*@null@*/ FD_t XfdFree( /*@killref@*/ FD_t fd, const char *msg, const char *file, unsigned line) /*@modifies fd @*/ { + int i; + if (fd == NULL) DBGREFS(0, (stderr, "--> fd %p -- %d %s at %s:%u\n", fd, FDNREFS(fd), msg, file, line)); FDSANE(fd); @@ -310,7 +312,14 @@ DBGREFS(fd, (stderr, "--> fd %p -- %d %s at %s:%u %s\n", fd, fd->nrefs, msg, fi if (--fd->nrefs > 0) /*@-refcounttrans -retalias@*/ return fd; /*@=refcounttrans =retalias@*/ fd->stats = _free(fd->stats); - fd->digest = _free(fd->digest); + for (i = fd->ndigests - 1; i >= 0; i--) { + FDDIGEST_t fddig = fd->digests + i; + if (fddig->hashctx == NULL) + continue; + (void) rpmDigestFinal(fddig->hashctx, NULL, NULL, 0); + fddig->hashctx = NULL; + } + fd->ndigests = 0; /*@-refcounttrans@*/ free(fd); /*@=refcounttrans@*/ } return NULL; @@ -321,7 +330,7 @@ static inline /*@null@*/ FD_t XfdNew(const char * msg, const char * file, unsigned line) /*@*/ { - FD_t fd = xmalloc(sizeof(*fd)); + FD_t fd = xcalloc(1, sizeof(*fd)); if (fd == NULL) /* XXX xmalloc never returns NULL */ return NULL; fd->nrefs = 0; @@ -345,7 +354,10 @@ static inline /*@null@*/ FD_t XfdNew(const char * msg, fd->syserrno = 0; fd->errcookie = NULL; fd->stats = xcalloc(1, sizeof(*fd->stats)); - fd->digest = NULL; + + fd->ndigests = 0; + memset(fd->digests, 0, sizeof(fd->digests)); + (void) gettimeofday(&fd->stats->create, NULL); fd->stats->begin = fd->stats->create; /* structure assignment */ @@ -370,7 +382,7 @@ ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count) rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count)); fdstat_exit(fd, FDSTAT_READ, rc); - if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->ndigests && rc > 0) fdUpdateDigests(fd, buf, rc); /*@-modfilesys@*/ DBGIO(fd, (stderr, "==>\tfdRead(%p,%p,%ld) rc %ld %s\n", cookie, buf, (long)count, (long)rc, fdbg(fd))); @@ -389,7 +401,7 @@ ssize_t fdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); + if (fd->ndigests && count > 0) fdUpdateDigests(fd, buf, count); if (fd->wr_chunked) { char chunksize[20]; @@ -2194,7 +2206,7 @@ DBGIO(fd, (stderr, "==>\tgzdRead(%p,%p,%u) rc %lx %s\n", cookie, buf, (unsigned) } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); /*@-compdef@*/ - if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->ndigests && rc > 0) fdUpdateDigests(fd, buf, rc); /*@=compdef@*/ } return rc; @@ -2211,7 +2223,7 @@ static ssize_t gzdWrite(void * cookie, const char * buf, size_t count) if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); + if (fd->ndigests && count > 0) fdUpdateDigests(fd, buf, count); gzfile = gzdFileno(fd); if (gzfile == NULL) return -2; /* XXX can't happen */ @@ -2433,7 +2445,7 @@ static ssize_t bzdRead(void * cookie, /*@out@*/ char * buf, size_t count) } else if (rc >= 0) { fdstat_exit(fd, FDSTAT_READ, rc); /*@-compdef@*/ - if (fd->digest && rc > 0) (void) rpmDigestUpdate(fd->digest, buf, rc); + if (fd->ndigests && rc > 0) fdUpdateDigests(fd, buf, rc); /*@=compdef@*/ } return rc; @@ -2452,7 +2464,7 @@ static ssize_t bzdWrite(void * cookie, const char * buf, size_t count) if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */ - if (fd->digest && count > 0) (void) rpmDigestUpdate(fd->digest, buf, count); + if (fd->ndigests && count > 0) fdUpdateDigests(fd, buf, count); bzfile = bzdFileno(fd); fdstat_enter(fd, FDSTAT_WRITE); diff --git a/rpmio/rpmio_internal.h b/rpmio/rpmio_internal.h index 7fc3db883..362185901 100644 --- a/rpmio/rpmio_internal.h +++ b/rpmio/rpmio_internal.h @@ -51,18 +51,14 @@ typedef /*@abstract@*/ struct { */ typedef enum rpmDigestFlags_e { RPMDIGEST_NONE = 0, -#ifdef DYING - RPMDIGEST_MD5 = (1 << 0), /*!< MD5 digest. */ - RPMDIGEST_SHA1 = (1 << 1) /*!< SHA1 digest. */ - RPMDIGEST_REVERSE = (1 << 16), /*!< Should bytes be reversed? */ - RPMDIGEST_BCSWAP = (1 << 17), /*!< Should bit count be reversed? */ -#define RPMDIGEST_MASK 0xffff -#endif } rpmDigestFlags; -/** +/** \ingroup rpmio */ -typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX; +typedef struct _FDDIGEST_s { + pgpHashAlgo hashalgo; + DIGEST_CTX hashctx; +} * FDDIGEST_t; /** \ingroup rpmio * Duplicate a digest context. @@ -134,7 +130,10 @@ struct _FD_s { /*@observer@*/ const void *errcookie; /* gzdio/bzdio/ufdio: */ FDSTAT_t stats; /* I/O statistics */ -/*@owned@*/ /*@null@*/ DIGEST_CTX digest; /* Digest private data */ + + int ndigests; +#define FDDIGEST_MAX 4 + struct _FDDIGEST_s digests[FDDIGEST_MAX]; int ftpFileDoneNeeded; /* ufdio: (FTP) */ unsigned int firstFree; /* fadio: */ @@ -450,101 +449,70 @@ FD_t c2f(/*@null@*/ void * cookie) } /** \ingroup rpmio + * Attach digest to fd. */ /*@unused@*/ static inline void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags) /*@modifies fd @*/ { - fd->digest = rpmDigestInit(hashalgo, flags); -} - -/** \ingroup rpmio - */ -/*@unused@*/ static inline -void fdFiniDigest(FD_t fd, - /*@null@*/ /*@out@*/ void ** datap, - /*@null@*/ /*@out@*/ size_t * lenp, - int asAscii) - /*@modifies fd, *datap, *lenp @*/ -{ - if (fd->digest == NULL) { - if (datap) *datap = NULL; - if (lenp) *lenp = 0; - return; + FDDIGEST_t fddig = fd->digests + fd->ndigests; + if (fddig != (fd->digests + FDDIGEST_MAX)) { + fd->ndigests++; + fddig->hashalgo = hashalgo; + fddig->hashctx = rpmDigestInit(hashalgo, flags); } - /*@-mayaliasunique@*/ - (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); - /*@=mayaliasunique@*/ - fd->digest = NULL; } -#ifdef DYING /** \ingroup rpmio + * Update digest(s) attached to fd. */ /*@unused@*/ static inline -void fdInitMD5(FD_t fd, int flags) +void fdUpdateDigests(FD_t fd, const byte * buf, ssize_t buflen) /*@modifies fd @*/ { -#ifdef DYING - if (flags) flags = RPMDIGEST_REVERSE; - flags |= RPMDIGEST_MD5; -#endif - fd->digest = rpmDigestInit(PGPHASHALGO_MD5, flags); -} - -/** \ingroup rpmio - */ -/*@unused@*/ static inline -void fdInitSHA1(FD_t fd, int flags) - /*@modifies fd @*/ -{ -#ifdef DYING - if (flags) flags = RPMDIGEST_REVERSE; - flags |= RPMDIGEST_SHA1; -#endif - fd->digest = rpmDigestInit(PGPHASHALGO_SHA1, flags); -} - -/** \ingroup rpmio - */ -/*@unused@*/ static inline -void fdFiniMD5(FD_t fd, - /*@null@*/ /*@out@*/ void ** datap, - /*@null@*/ /*@out@*/ size_t * lenp, - int asAscii) - /*@modifies fd, *datap, *lenp @*/ -{ - if (fd->digest == NULL) { - if (datap) *datap = NULL; - if (lenp) *lenp = 0; - return; + 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; + (void) rpmDigestUpdate(fddig->hashctx, buf, buflen); } - /*@-mayaliasunique@*/ - (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); - /*@=mayaliasunique@*/ - fd->digest = NULL; } /** \ingroup rpmio */ /*@unused@*/ static inline -void fdFiniSHA1(FD_t fd, +void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, /*@null@*/ /*@out@*/ void ** datap, /*@null@*/ /*@out@*/ size_t * lenp, int asAscii) /*@modifies fd, *datap, *lenp @*/ { - if (fd->digest == NULL) { + 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; + (void) rpmDigestFinal(fddig->hashctx, datap, lenp, asAscii); + fddig->hashctx = NULL; + break; + } + if (i < 0) { if (datap) *datap = NULL; if (lenp) *lenp = 0; return; - } - /*@-mayaliasunique@*/ - (void) rpmDigestFinal(fd->digest, datap, lenp, asAscii); - /*@=mayaliasunique@*/ - fd->digest = NULL; + } else if (i == imax) + fd->ndigests = imax - 1; + else + fd->ndigests = imax; } -#endif /*@-shadow@*/ /** \ingroup rpmio diff --git a/rpmio/rpmpgp.h b/rpmio/rpmpgp.h index 7231cce42..7f89daaff 100644 --- a/rpmio/rpmpgp.h +++ b/rpmio/rpmpgp.h @@ -16,6 +16,10 @@ #include "dsa.h" #include "mp32.h" +/** + */ +typedef /*@abstract@*/ struct DIGEST_CTX_s * DIGEST_CTX; + /*@-typeuse -fielduse@*/ /** */ @@ -860,11 +864,11 @@ typedef struct pgpSig_s { size_t nbytes; /*!< No. bytes of plain text. */ -/*@only@*/ /*@null@*/ void * sha1ctx; /*!< (dsa) sha1 hash context. */ +/*@only@*/ /*@null@*/ DIGEST_CTX sha1ctx;/*!< (dsa) sha1 hash context. */ /*@only@*/ /*@null@*/ void * sha1; /*!< (dsa) V3 signature hash. */ size_t sha1len; /*!< (dsa) V3 signature hash length. */ -/*@only@*/ /*@null@*/ void * md5ctx; /*!< (rsa) md5 hash context. */ +/*@only@*/ /*@null@*/ DIGEST_CTX md5ctx;/*!< (rsa) md5 hash context. */ /*@only@*/ /*@null@*/ void * md5; /*!< (rsa) V3 signature hash. */ size_t md5len; /*!< (rsa) V3 signature hash length. */ diff --git a/rpmio/tdigest.c b/rpmio/tdigest.c index da850ce08..9b2428f12 100644 --- a/rpmio/tdigest.c +++ b/rpmio/tdigest.c @@ -155,11 +155,11 @@ main(int argc, const char *argv[]) (void) Fwrite(buf, 1, nb, ofd); } - fdFiniDigest(ifd, (void **)&idigest, NULL, asAscii); + fdFiniDigest(ifd, hashalgo, (void **)&idigest, NULL, asAscii); Fclose(ifd); Fflush(ofd); - fdFiniDigest(ofd, (void **)&odigest, NULL, asAscii); + fdFiniDigest(ofd, hashalgo, (void **)&odigest, NULL, asAscii); Fclose(ofd); rpmDigestFinal(ctx, (void **)&digest, &digestlen, asAscii); |