void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int flags)
{
- if (fd->ndigests < FDDIGEST_MAX) {
- fd->digests[fd->ndigests] = rpmDigestInit(hashalgo, flags);
- fd->ndigests++;
- fdstat_enter(fd, FDSTAT_DIGEST);
- fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0);
+ if (fd->digests == NULL) {
+ fd->digests = rpmDigestBundleNew();
}
+ fdstat_enter(fd, FDSTAT_DIGEST);
+ rpmDigestBundleAdd(fd->digests, 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--) {
- DIGEST_CTX ctx = fd->digests[i];
- if (ctx == NULL)
- continue;
+ if (fd && fd->digests) {
fdstat_enter(fd, FDSTAT_DIGEST);
- (void) rpmDigestUpdate(ctx, buf, buflen);
+ rpmDigestBundleUpdate(fd->digests, buf, buflen);
fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) buflen);
}
}
size_t * lenp,
int asAscii)
{
- int imax = -1;
- int i;
-
- for (i = fd->ndigests - 1; i >= 0; i--) {
- DIGEST_CTX ctx = fd->digests[i];
- if (ctx == NULL)
- continue;
- if (i > imax) imax = i;
- if (ctx->algo != hashalgo)
- continue;
+ if (fd && fd->digests) {
fdstat_enter(fd, FDSTAT_DIGEST);
- (void) rpmDigestFinal(ctx, datap, lenp, asAscii);
+ rpmDigestBundleFinal(fd->digests, hashalgo, datap, lenp, asAscii);
fdstat_exit(fd, FDSTAT_DIGEST, (ssize_t) 0);
- fd->digests[i] = 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--) {
- DIGEST_CTX ctx = fd->digests[i];
- if (ctx == NULL)
- continue;
- switch (ctx->algo) {
- case PGPHASHALGO_MD5:
-assert(dig->md5ctx == NULL);
- dig->md5ctx = ctx;
- fd->digests[i] = NULL;
- break;
- case PGPHASHALGO_SHA1:
- case PGPHASHALGO_SHA256:
- case PGPHASHALGO_SHA384:
- case PGPHASHALGO_SHA512:
-assert(dig->sha1ctx == NULL);
- dig->sha1ctx = ctx;
- fd->digests[i] = NULL;
- break;
- default:
- break;
- }
+ if (fd && fd->digests) {
+ rpmDigestBundle bundle = fd->digests;
+ for (int i = bundle->index_max; i >= bundle->index_min; i--) {
+ DIGEST_CTX ctx = bundle->digests[i];
+ if (ctx == NULL)
+ continue;
+ switch (ctx->algo) {
+ case PGPHASHALGO_MD5:
+ assert(dig->md5ctx == NULL);
+ dig->md5ctx = ctx;
+ bundle->digests[i] = NULL;
+ break;
+ case PGPHASHALGO_SHA1:
+ case PGPHASHALGO_SHA256:
+ case PGPHASHALGO_SHA384:
+ case PGPHASHALGO_SHA512:
+ assert(dig->sha1ctx == NULL);
+ dig->sha1ctx = ctx;
+ bundle->digests[i] = NULL;
+ break;
+ default:
+ break;
+ }
+ }
}
}
*/
FD_t fdFree( FD_t fd, const char *msg)
{
- int i;
-
if (fd == NULL)
DBGREFS(0, (stderr, "--> fd %p -- %d %s\n", fd, FDNREFS(fd), msg));
FDSANE(fd);
if (--fd->nrefs > 0)
return fd;
fd->stats = _free(fd->stats);
- for (i = fd->ndigests - 1; i >= 0; i--) {
- DIGEST_CTX *ctxp = fd->digests + i;
- if (*ctxp == NULL)
- continue;
- (void) rpmDigestFinal(*ctxp, NULL, NULL, 0);
- *ctxp = NULL;
+ if (fd->digests) {
+ fd->digests = rpmDigestBundleFree(fd->digests);
}
- fd->ndigests = 0;
free(fd);
}
return NULL;
fd->syserrno = 0;
fd->errcookie = NULL;
fd->stats = xcalloc(1, sizeof(*fd->stats));
-
- fd->ndigests = 0;
- memset(fd->digests, 0, sizeof(fd->digests));
+ fd->digests = NULL;
fd->fd_cpioPos = 0;
rc = read(fdFileno(fd), buf, (count > fd->bytesRemain ? fd->bytesRemain : count));
fdstat_exit(fd, FDSTAT_READ, rc);
- if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
+ if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
DBGIO(fd, (stderr, "==>\tfdRead(%p,%p,%ld) rc %ld %s\n", cookie, buf, (long)count, (long)rc, fdbg(fd)));
if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
- if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
+ if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
if (count == 0) return 0;
}
} else if (rc >= 0) {
fdstat_exit(fd, FDSTAT_READ, rc);
- if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
+ if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
}
return rc;
}
if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
- if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
+ if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
gzfile = gzdFileno(fd);
if (gzfile == NULL) return -2; /* XXX can't happen */
fd->errcookie = bzerror(bzfile, &zerror);
} else if (rc >= 0) {
fdstat_exit(fd, FDSTAT_READ, rc);
- if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
+ if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
}
return rc;
}
if (fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
- if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
+ if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
bzfile = bzdFileno(fd);
fdstat_enter(fd, FDSTAT_WRITE);
fd->errcookie = "Lzma: decoding error";
} else if (rc >= 0) {
fdstat_exit(fd, FDSTAT_READ, rc);
- if (fd->ndigests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
+ if (fd->digests && rc > 0) fdUpdateDigests(fd, (void *)buf, rc);
}
return rc;
}
if (fd == NULL || fd->bytesRemain == 0) return 0; /* XXX simulate EOF */
- if (fd->ndigests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
+ if (fd->digests && count > 0) fdUpdateDigests(fd, (void *)buf, count);
lzfile = lzdFileno(fd);