Add public pgpValString() function + enum for the various types

- The equivalent used to be possible in 4.4.x era as the value tables
  were all exported, but this way we need to export far less
  and the implementation details stay internal.
This commit is contained in:
Panu Matilainen 2010-05-19 15:32:54 +03:00
parent 072815887f
commit 2be413810c
2 changed files with 46 additions and 8 deletions

View File

@ -207,14 +207,7 @@ static void pgpPrtStr(const char *pre, const char *s)
fprintf(stderr, " %s", s);
}
/** \ingroup rpmpgp
* Return string representation of am OpenPGP value.
* @param vs table of (string,value) pairs
* @param val byte value to lookup
* @return string value of byte
*/
static inline
const char * pgpValStr(pgpValTbl vs, uint8_t val)
static const char * pgpValStr(pgpValTbl vs, uint8_t val)
{
do {
if (vs->val == val)
@ -223,6 +216,31 @@ const char * pgpValStr(pgpValTbl vs, uint8_t val)
return vs->str;
}
static pgpValTbl pgpValTable(pgpValType type)
{
switch (type) {
case PGPVAL_TAG: return pgpTagTbl;
case PGPVAL_ARMORBLOCK: return pgpArmorTbl;
case PGPVAL_ARMORKEY: return pgpArmorKeyTbl;
case PGPVAL_SIGTYPE: return pgpSigTypeTbl;
case PGPVAL_SUBTYPE: return pgpSubTypeTbl;
case PGPVAL_PUBKEYALGO: return pgpPubkeyTbl;
case PGPVAL_SYMKEYALGO: return pgpSymkeyTbl;
case PGPVAL_COMPRESSALGO: return pgpCompressionTbl;
case PGPVAL_HASHALGO: return pgpHashTbl;
case PGPVAL_SERVERPREFS: return pgpKeyServerPrefsTbl;
default:
break;
}
return NULL;
}
const char * pgpValString(pgpValType type, uint8_t val)
{
pgpValTbl tbl = pgpValTable(type);
return (tbl != NULL) ? pgpValStr(tbl, val) : NULL;
}
static void pgpPrtHex(const char *pre, const uint8_t *p, size_t plen)
{
char *hex = NULL;

View File

@ -913,6 +913,19 @@ typedef enum pgpArmorKey_e {
PGPARMORKEY_CHARSET = 5 /*!< Charset: */
} pgpArmorKey;
typedef enum pgpValType_e {
PGPVAL_TAG = 1,
PGPVAL_ARMORBLOCK = 2,
PGPVAL_ARMORKEY = 3,
PGPVAL_SIGTYPE = 4,
PGPVAL_SUBTYPE = 5,
PGPVAL_PUBKEYALGO = 6,
PGPVAL_SYMKEYALGO = 7,
PGPVAL_COMPRESSALGO = 8,
PGPVAL_HASHALGO = 9,
PGPVAL_SERVERPREFS = 10,
} pgpValType;
/** \ingroup rpmpgp
* Bit(s) to control digest operation.
*/
@ -920,6 +933,13 @@ typedef enum rpmDigestFlags_e {
RPMDIGEST_NONE = 0
} rpmDigestFlags;
/** \ingroup rpmpgp
* Return string representation of am OpenPGP value.
* @param type type of value
* @param val byte value to lookup
* @return string value of byte
*/
const char * pgpValString(pgpValType type, uint8_t val);
/** \ingroup rpmpgp
* Return (native-endian) integer from big-endian representation.