]> granicus.if.org Git - mutt/commitdiff
Removing some duplicate code from gnupgparse.c and
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Jun 1998 11:18:51 +0000 (11:18 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Jun 1998 11:18:51 +0000 (11:18 +0000)
pgppubring.c.

gnupgparse.c
pgp.h
pgppubring.c

index 6f928e883b4d147fb70f1d484849b98e40074e50..a82093ed3fff70f1298888a24fe45c6927276fab 100644 (file)
 #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 e96b2fb6dde64db89ea94fcace966ac8f7b39da5..06d3be9aa07bd70d263e26c996bc4050fadd723f 100644 (file)
--- 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)
 
index 16bf68b22d3849b53c80257c693b6a8c675962f2..cbd53c1ceec17e773e294421fc144c3d456b8833 100644 (file)
@@ -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);