From: Thomas Roessler Date: Tue, 16 Jun 1998 11:18:51 +0000 (+0000) Subject: Removing some duplicate code from gnupgparse.c and X-Git-Tag: mutt-0-92-11i~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2db1975e94f9bff331f2dde78ea2837b28a3b816;p=mutt Removing some duplicate code from gnupgparse.c and pgppubring.c. --- diff --git a/gnupgparse.c b/gnupgparse.c index 6f928e88..a82093ed 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -26,60 +26,6 @@ #include "mutt.h" #include "pgp.h" -static const char * -pkalgbytype(unsigned char type) -{ - switch(type) - { - case 1: - case 2: - case 3: return "RSA"; - case 16: /* encrypt only */ - case 20: return "ElG"; - case 17: return "DSA"; - default: return "unk"; - } -} - -static short canencrypt(unsigned char type) -{ - switch(type) - { - case 1: - case 2: - case 16: - case 20: - return 1; - default: - return 0; - } -} - -static short cansign(unsigned char type) -{ - switch(type) - { - case 1: - case 3: - case 16: /* hmmm: this one can only sign if used in a v3 packet */ - case 17: - case 20: - return 1; - default: - return 0; - } -} -/* return values: - * - * 1 = sign only - * 2 = encrypt only - * 3 = both - */ - -static short get_abilities(unsigned char type) -{ - return (canencrypt(type) << 1) | cansign(type); -} /**************** * Read the GNUPG keys. For now we read the complete keyring by @@ -98,8 +44,7 @@ static short get_abilities(unsigned char type) * - signature class */ -static KEYINFO * -parse_pub_line( char *buf, int *is_subkey ) +static KEYINFO *parse_pub_line( char *buf, int *is_subkey ) { KEYINFO *k=NULL; PGPUID *uid = NULL; @@ -146,8 +91,8 @@ parse_pub_line( char *buf, int *is_subkey ) k->keylen = atoi(p); /* fixme: add validation checks */ break; case 4: /* pubkey algo */ - k->algorithm = pkalgbytype(atoi(p)); - k->flags |= get_abilities(atoi(p)); + k->algorithm = pgp_pkalgbytype(atoi(p)); + k->flags |= pgp_get_abilities(atoi(p)); break; case 5: /* 16 hex digits with the long keyid. */ /* We really should do a check here */ @@ -206,8 +151,7 @@ static pid_t gpg_invoke_list_keys(struct pgp_vinfo *pgp, pgpinfd, pgpoutfd, pgperrfd); } -static KEYINFO * -read_ring(struct pgp_vinfo *pgp, int secret ) +static KEYINFO *read_ring(struct pgp_vinfo *pgp, int secret ) { FILE *fp; pid_t thepid; diff --git a/pgp.h b/pgp.h index e96b2fb6..06d3be9a 100644 --- a/pgp.h +++ b/pgp.h @@ -187,6 +187,11 @@ void pgp_extract_keys_from_messages(HEADER *hdr); void pgp_signed_handler (BODY *, STATE *); void pgp_void_passphrase (void); +short pgp_canencrypt(unsigned char); +short pgp_cansign(unsigned char); +short pgp_get_abilities(unsigned char); +const char *pgp_pkalgbytype(unsigned char); + #define pgp_secring(a) pgp_getring(a, 0) #define pgp_pubring(a) pgp_getring(a, 1) diff --git a/pgppubring.c b/pgppubring.c index 16bf68b2..cbd53c1c 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -72,7 +72,7 @@ const char *pgp_packet_name[] = { "Comment Packet" }; -static const char *pkalgbytype(unsigned char type) +const char *pgp_pkalgbytype(unsigned char type) { switch(type) { @@ -133,7 +133,7 @@ static const char *hashalgbytype(unsigned char type) #endif -static short canencrypt(unsigned char type) +short pgp_canencrypt(unsigned char type) { switch(type) { @@ -147,12 +147,13 @@ static short canencrypt(unsigned char type) } } -static short cansign(unsigned char type) +short pgp_cansign(unsigned char type) { switch(type) { case 1: case 3: + case 16: case 17: case 20: return 1; @@ -168,9 +169,9 @@ static short cansign(unsigned char type) * 3 = both */ -static short get_abilities(unsigned char type) +short pgp_get_abilities(unsigned char type) { - return (canencrypt(type) << 1) | cansign(type); + return (pgp_canencrypt(type) << 1) | pgp_cansign(type); } static int read_material(size_t material, size_t *used, FILE *fp) @@ -392,8 +393,8 @@ static KEYINFO *pgp_parse_pgp2_key(unsigned char *buff, size_t l) alg = buff[j++]; - p->algorithm = pkalgbytype(alg); - p->flags |= get_abilities(alg); + p->algorithm = pgp_pkalgbytype(alg); + p->flags |= pgp_get_abilities(alg); expl = 0; for(i = 0; i < 2; i++) @@ -488,8 +489,8 @@ static KEYINFO *pgp_parse_pgp3_key(unsigned char *buff, size_t l) alg = buff[j++]; - p->algorithm = pkalgbytype(alg); - p->flags |= get_abilities(alg); + p->algorithm = pgp_pkalgbytype(alg); + p->flags |= pgp_get_abilities(alg); if (alg == 17) skip_bignum(buff, l, j, &j, 3);