Remove static print buffer from pgpMpiStr(), return malloc'd data instead

- convert callers
- only rpmpgp.c internal needs, move it there and make static?
This commit is contained in:
Panu Matilainen 2008-04-07 13:37:56 +03:00
parent 41a32765bd
commit 9bb88f4088
2 changed files with 18 additions and 9 deletions

View File

@ -429,6 +429,7 @@ static int pgpPrtSigParams(pgpTag tag, uint8_t pubkey_algo, uint8_t sigtype,
size_t i;
SECItem dsaraw;
unsigned char dsabuf[2*DSA_SUBPRIME_LEN];
char *mpi;
dsaraw.type = 0;
dsaraw.data = dsabuf;
@ -486,7 +487,9 @@ static int pgpPrtSigParams(pgpTag tag, uint8_t pubkey_algo, uint8_t sigtype,
if (_print)
fprintf(stderr, "%7zd", i);
}
pgpPrtStr("", pgpMpiStr(p));
mpi = pgpMpiStr(p);
pgpPrtStr("", mpi);
free(mpi);
pgpPrtNL();
}
@ -663,6 +666,7 @@ static const uint8_t * pgpPrtPubkeyParams(uint8_t pubkey_algo,
size_t i;
for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
char * mpi;
if (pubkey_algo == PGPPUBKEYALGO_RSA) {
if (i >= 2) break;
if (_dig) {
@ -716,7 +720,9 @@ static const uint8_t * pgpPrtPubkeyParams(uint8_t pubkey_algo,
if (_print)
fprintf(stderr, "%7zd", i);
}
pgpPrtStr("", pgpMpiStr(p));
mpi = pgpMpiStr(p);
pgpPrtStr("", mpi);
free(mpi);
pgpPrtNL();
}
@ -767,6 +773,7 @@ static const uint8_t * pgpPrtSeckeyParams(uint8_t pubkey_algo,
#ifdef NOTYET /* XXX encrypted MPI's need to be handled. */
for (i = 0; p < &h[hlen]; i++, p += pgpMpiLen(p)) {
char *mpi;
if (pubkey_algo == PGPPUBKEYALGO_RSA) {
if (pgpSecretRSA[i] == NULL) break;
pgpPrtStr("", pgpSecretRSA[i]);
@ -780,7 +787,9 @@ static const uint8_t * pgpPrtSeckeyParams(uint8_t pubkey_algo,
if (_print)
fprintf(stderr, "%7d", i);
}
pgpPrtStr("", pgpMpiStr(p));
mpi = pgpMpiStr(p);
pgpPrtStr("", mpi);
free(mpi);
pgpPrtNL();
}
#else

View File

@ -13,6 +13,7 @@
#include <string.h>
#include <stdio.h>
#include <rpm/rpmints.h>
#include <rpm/rpmstring.h>
#ifdef __cplusplus
extern "C" {
@ -1038,17 +1039,16 @@ char * pgpHexStr(const uint8_t *p, size_t plen);
* Return hex formatted representation of a multiprecision integer.
* @todo Remove static buffer.
* @param p bytes
* @return hex formatted string
* @return hex formatted string (malloc'ed)
*/
static inline
const char * pgpMpiStr(const uint8_t *p)
char * pgpMpiStr(const uint8_t *p)
{
static char prbuf[8*BUFSIZ]; /* XXX ick */
char *t = prbuf;
char *str = NULL;
char *hex = pgpHexStr(p+2, pgpMpiLen(p)-2);
sprintf(t, "[%4u]: %s", pgpGrab(p, (size_t) 2), hex);
rasprintf(&str, "[%4u]: %s", pgpGrab(p, (size_t) 2), hex);
free(hex);
return prbuf;
return str;
}
/** \ingroup rpmpgp