More preliminaries for non-md5 file checksums

- add rpmfiDigest() method (similar to one in rpm5.org) for retrieving
  file digest, algorithm and digest size
- make rpmfiMD5() just a special case of rpmfiDigest()
This commit is contained in:
Panu Matilainen 2008-05-29 15:04:46 +03:00
parent 479b74bebe
commit 95e65d98ea
3 changed files with 30 additions and 3 deletions

View File

@ -173,13 +173,27 @@ rpmfileState rpmfiFState(rpmfi fi)
const unsigned char * rpmfiMD5(rpmfi fi)
{
unsigned char * MD5 = NULL;
const unsigned char *digest;
pgpHashAlgo algo = 0;
digest = rpmfiDigest(fi, &algo, NULL);
return (algo == PGPHASHALGO_MD5) ? digest : NULL;
}
const unsigned char * rpmfiDigest(rpmfi fi, pgpHashAlgo *algo, size_t *len)
{
const unsigned char *digest = NULL;
if (fi != NULL && fi->i >= 0 && fi->i < fi->fc) {
size_t diglen = rpmDigestLength(fi->digestalgo);
if (fi->digests != NULL)
MD5 = fi->digests + (16 * fi->i);
digest = fi->digests + (diglen * fi->i);
if (len)
*len = diglen;
if (algo)
*algo = fi->digestalgo;
}
return MD5;
return digest;
}
const char * rpmfiFLink(rpmfi fi)
@ -1242,6 +1256,8 @@ if (fi->actions == NULL)
xx = hge(h, RPMTAG_FILELINKTOS, NULL, (rpm_data_t *) &fi->flinks, NULL);
xx = hge(h, RPMTAG_FILELANGS, NULL, (rpm_data_t *) &fi->flangs, NULL);
/* digest algorithm hardwired to MD5 for now */
fi->digestalgo = PGPHASHALGO_MD5;
fi->fdigests = NULL;
xx = hge(h, RPMTAG_FILEMD5S, NULL, (rpm_data_t *) &fi->fdigests, NULL);

View File

@ -8,6 +8,7 @@
#include <rpm/rpmtypes.h>
#include <rpm/rpmvf.h>
#include <rpm/rpmpgp.h>
#ifdef __cplusplus
extern "C" {
@ -205,6 +206,15 @@ rpm_mode_t rpmfiFMode(rpmfi fi);
*/
rpmfileState rpmfiFState(rpmfi fi);
/** \ingroup rpmfi
* Return current file (binary) digest of file info set.
* @param fi file info set
* @retval algo digest hash algoritm used (pass NULL to ignore)
* @retval diglen digest hash length (pass NULL to ignore)
* @return current file digest, NULL on invalid
*/
const unsigned char * rpmfiDigest(rpmfi fi, pgpHashAlgo *algo, size_t *diglen);
/** \ingroup rpmfi
* Return current file (binary) md5 digest from file info set.
* @param fi file info set

View File

@ -96,6 +96,7 @@ struct rpmfi_s {
const char ** odnl; /*!< Original dirname(s) (from header) */
int32_t * odil; /*!< Original dirindex(s) (from header) */
pgpHashAlgo digestalgo; /*!< File checksum algorithm */
unsigned char * digests; /*!< File checksums in binary. */
char * pretrans;