diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2008-06-16 17:01:29 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2008-07-01 11:09:15 +0300 |
commit | c2efff14861624a7c8d4d32ef6b681f642804e13 (patch) | |
tree | 6262b20f9ab2f6f7dc59aef7742cdb980da78032 /rpmio/rpmpgp.c | |
parent | 1f425eb2908a293f19cdad92f81ce5b74ab520c9 (diff) | |
download | librpm-tizen-c2efff14861624a7c8d4d32ef6b681f642804e13.tar.gz librpm-tizen-c2efff14861624a7c8d4d32ef6b681f642804e13.tar.bz2 librpm-tizen-c2efff14861624a7c8d4d32ef6b681f642804e13.zip |
Make every pgp function not needed by other parts of rpm static
Diffstat (limited to 'rpmio/rpmpgp.c')
-rw-r--r-- | rpmio/rpmpgp.c | 165 |
1 files changed, 158 insertions, 7 deletions
diff --git a/rpmio/rpmpgp.c b/rpmio/rpmpgp.c index 8db097e6e..50cc5c1b1 100644 --- a/rpmio/rpmpgp.c +++ b/rpmio/rpmpgp.c @@ -202,6 +202,22 @@ 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) +{ + do { + if (vs->val == val) + break; + } while ((++vs)->val != -1); + return vs->str; +} + static void pgpPrtHex(const char *pre, const uint8_t *p, size_t plen) { char *hex = NULL; @@ -213,7 +229,7 @@ static void pgpPrtHex(const char *pre, const uint8_t *p, size_t plen) free(hex); } -void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val) +static void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val) { if (!_print) return; if (pre && *pre) @@ -221,6 +237,60 @@ void pgpPrtVal(const char * pre, pgpValTbl vs, uint8_t val) fprintf(stderr, "%s(%u)", pgpValStr(vs, val), (unsigned)val); } +/** \ingroup rpmpgp + * Return no. of bits in a multiprecision integer. + * @param p pointer to multiprecision integer + * @return no. of bits + */ +static +unsigned int pgpMpiBits(const uint8_t *p) +{ + return ((p[0] << 8) | p[1]); +} + +/** \ingroup rpmpgp + * Return no. of bytes in a multiprecision integer. + * @param p pointer to multiprecision integer + * @return no. of bytes + */ +static +size_t pgpMpiLen(const uint8_t *p) +{ + return (2 + ((pgpMpiBits(p)+7)>>3)); +} + +/** \ingroup rpmpgp + * Return hex formatted representation of a multiprecision integer. + * @param p bytes + * @return hex formatted string (malloc'ed) + */ +static inline +char * pgpMpiStr(const uint8_t *p) +{ + char *str = NULL; + char *hex = pgpHexStr(p+2, pgpMpiLen(p)-2); + rasprintf(&str, "[%4u]: %s", pgpGrab(p, (size_t) 2), hex); + free(hex); + return str; +} + +/** \ingroup rpmpgp + * Return value of an OpenPGP string. + * @param vs table of (string,value) pairs + * @param s string token to lookup + * @param se end-of-string address + * @return byte value + */ +static inline +int pgpValTok(pgpValTbl vs, const char * s, const char * se) +{ + do { + size_t vlen = strlen(vs->str); + if (vlen <= (se-s) && !strncmp(s, vs->str, vlen)) + break; + } while ((++vs)->val != -1); + return vs->val; +} /** * @return 0 on success */ @@ -315,7 +385,88 @@ static SECKEYPublicKey *pgpNewDSAKey(void) return pgpNewPublicKey(dsaKey); } -int pgpPrtSubType(const uint8_t *h, size_t hlen, pgpSigType sigtype) +/** \ingroup rpmpgp + * Is buffer at beginning of an OpenPGP packet? + * @param p buffer + * @return 1 if an OpenPGP packet, 0 otherwise + */ +static inline +int pgpIsPkt(const uint8_t * p) +{ + unsigned int val = *p++; + pgpTag tag; + int rc; + + /* XXX can't deal with these. */ + if (!(val & 0x80)) + return 0; + + if (val & 0x40) + tag = (pgpTag)(val & 0x3f); + else + tag = (pgpTag)((val >> 2) & 0xf); + + switch (tag) { + case PGPTAG_MARKER: + case PGPTAG_SYMMETRIC_SESSION_KEY: + case PGPTAG_ONEPASS_SIGNATURE: + case PGPTAG_PUBLIC_KEY: + case PGPTAG_SECRET_KEY: + case PGPTAG_PUBLIC_SESSION_KEY: + case PGPTAG_SIGNATURE: + case PGPTAG_COMMENT: + case PGPTAG_COMMENT_OLD: + case PGPTAG_LITERAL_DATA: + case PGPTAG_COMPRESSED_DATA: + case PGPTAG_SYMMETRIC_DATA: + rc = 1; + break; + case PGPTAG_PUBLIC_SUBKEY: + case PGPTAG_SECRET_SUBKEY: + case PGPTAG_USER_ID: + case PGPTAG_RESERVED: + case PGPTAG_TRUST: + case PGPTAG_PHOTOID: + case PGPTAG_ENCRYPTED_MDC: + case PGPTAG_MDC: + case PGPTAG_PRIVATE_60: + case PGPTAG_PRIVATE_62: + case PGPTAG_CONTROL: + default: + rc = 0; + break; + } + + return rc; +} + +#define CRC24_INIT 0xb704ce +#define CRC24_POLY 0x1864cfb + +/** \ingroup rpmpgp + * Return CRC of a buffer. + * @param octets bytes + * @param len no. of bytes + * @return crc of buffer + */ +static inline +unsigned int pgpCRC(const uint8_t *octets, size_t len) +{ + unsigned int crc = CRC24_INIT; + size_t i; + + while (len--) { + crc ^= (*octets++) << 16; + for (i = 0; i < 8; i++) { + crc <<= 1; + if (crc & 0x1000000) + crc ^= CRC24_POLY; + } + } + return crc & 0xffffff; +} + +static int pgpPrtSubType(const uint8_t *h, size_t hlen, pgpSigType sigtype) { const uint8_t *p = h; size_t plen, i; @@ -496,7 +647,7 @@ static int pgpPrtSigParams(pgpTag tag, uint8_t pubkey_algo, uint8_t sigtype, return 0; } -int pgpPrtSig(pgpTag tag, const uint8_t *h, size_t hlen) +static int pgpPrtSig(pgpTag tag, const uint8_t *h, size_t hlen) { uint8_t version = h[0]; uint8_t * p; @@ -804,7 +955,7 @@ static const uint8_t * pgpPrtSeckeyParams(uint8_t pubkey_algo, return p; } -int pgpPrtKey(pgpTag tag, const uint8_t *h, size_t hlen) +static int pgpPrtKey(pgpTag tag, const uint8_t *h, size_t hlen) { uint8_t version = *h; const uint8_t * p; @@ -863,7 +1014,7 @@ int pgpPrtKey(pgpTag tag, const uint8_t *h, size_t hlen) return rc; } -int pgpPrtUserID(pgpTag tag, const uint8_t *h, size_t hlen) +static int pgpPrtUserID(pgpTag tag, const uint8_t *h, size_t hlen) { pgpPrtVal("", pgpTagTbl, tag); if (_print) @@ -877,7 +1028,7 @@ int pgpPrtUserID(pgpTag tag, const uint8_t *h, size_t hlen) return 0; } -int pgpPrtComment(pgpTag tag, const uint8_t *h, size_t hlen) +static int pgpPrtComment(pgpTag tag, const uint8_t *h, size_t hlen) { size_t i = hlen; @@ -985,7 +1136,7 @@ int pgpExtractPubkeyFingerprint(const char * b64pkt, pgpKeyID_t keyid) return sizeof(keyid); /* no. of bytes of pubkey signid */ } -int pgpPrtPkt(const uint8_t *pkt, size_t pleft) +static int pgpPrtPkt(const uint8_t *pkt, size_t pleft) { unsigned int val = *pkt; size_t pktlen; |