From: Werner Koch Date: Thu, 15 Mar 2001 13:09:41 +0000 (+0000) Subject: Give access to key capabilities X-Git-Tag: gpgme-1.2.0@1385~1327 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=697c724b271f5abb645ffdb5712c1f756b966364;p=gpgme.git Give access to key capabilities --- diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 9f1f83b..45607f9 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,20 @@ +2001-03-15 Werner Koch + + * rungpg.c: Included time.h. + + * key.h: New keyflags for capabilities. + * keylist.c (set_mainkey_capability, set_subkey_capability): New. + (keylist_colon_handler): Parse them. + * gpgme.h: New attribute values for capabilties. + * key.c (gpgme_key_get_string_attr): Return them. + (capabilities_to_string): New. + (gpgme_key_get_ulong_attr): Return the global caps. + +2001-03-14 Werner Koch + + * w32-io.c (destroy_reader,destroy_writer): Fixed syntax error. + Thanks to Jan Oliver Wagner. + 2001-03-13 Werner Koch * context.h: Add invalid and revoke flags to user_id structure. diff --git a/trunk/gpgme/gpgme.h b/trunk/gpgme/gpgme.h index 562af19..f1744f0 100644 --- a/trunk/gpgme/gpgme.h +++ b/trunk/gpgme/gpgme.h @@ -133,7 +133,11 @@ typedef enum { GPGME_ATTR_KEY_REVOKED = 16, GPGME_ATTR_KEY_INVALID = 17, GPGME_ATTR_UID_REVOKED = 18, - GPGME_ATTR_UID_INVALID = 19 + GPGME_ATTR_UID_INVALID = 19, + GPGME_ATTR_KEY_CAPS = 20, + GPGME_ATTR_CAN_ENCRYPT = 21, + GPGME_ATTR_CAN_SIGN = 22, + GPGME_ATTR_CAN_CERTIFY = 23 } GpgmeAttr; typedef enum { diff --git a/trunk/gpgme/key.c b/trunk/gpgme/key.c index 35a5404..6f8f03b 100644 --- a/trunk/gpgme/key.c +++ b/trunk/gpgme/key.c @@ -455,6 +455,24 @@ gpgme_key_get_as_xml ( GpgmeKey key ) } +static const char * +capabilities_to_string (struct subkey_s *k) +{ + static char *strings[8] = { + "", + "c", + "s", + "sc", + "e", + "ec", + "es", + "esc" + }; + return strings[ (!!k->flags.can_encrypt << 2) + | (!!k->flags.can_sign << 1) + | (!!k->flags.can_certify ) ]; +} + const char * gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, const void *reserved, int idx ) @@ -536,11 +554,20 @@ gpgme_key_get_string_attr ( GpgmeKey key, GpgmeAttr what, case GPGME_ATTR_KEY_INVALID: case GPGME_ATTR_UID_REVOKED: case GPGME_ATTR_UID_INVALID: + case GPGME_ATTR_CAN_ENCRYPT: + case GPGME_ATTR_CAN_SIGN: + case GPGME_ATTR_CAN_CERTIFY: break; case GPGME_ATTR_IS_SECRET: if (key->secret) val = "1"; break; + case GPGME_ATTR_KEY_CAPS: + for (k=&key->keys; k && idx; k=k->next, idx-- ) + ; + if (k) + val = capabilities_to_string (k); + break; } return val; } @@ -613,6 +640,15 @@ gpgme_key_get_ulong_attr ( GpgmeKey key, GpgmeAttr what, if (u) val = u->invalid; break; + case GPGME_ATTR_CAN_ENCRYPT: + val = key->gloflags.can_encrypt; + break; + case GPGME_ATTR_CAN_SIGN: + val = key->gloflags.can_sign; + break; + case GPGME_ATTR_CAN_CERTIFY: + val = key->gloflags.can_encrypt; + break; default: break; } diff --git a/trunk/gpgme/key.h b/trunk/gpgme/key.h index 83d46ed..5e9d4c6 100644 --- a/trunk/gpgme/key.h +++ b/trunk/gpgme/key.h @@ -33,6 +33,9 @@ struct subkey_s { unsigned int expired:1 ; unsigned int disabled:1 ; unsigned int invalid:1 ; + unsigned int can_encrypt:1; + unsigned int can_sign:1; + unsigned int can_certify:1; } flags; unsigned int key_algo; unsigned int key_len; @@ -47,6 +50,9 @@ struct gpgme_key_s { unsigned int expired:1 ; unsigned int disabled:1 ; unsigned int invalid:1 ; + unsigned int can_encrypt:1; + unsigned int can_sign:1; + unsigned int can_certify:1; } gloflags; unsigned int ref_count; unsigned int secret:1; diff --git a/trunk/gpgme/keylist.c b/trunk/gpgme/keylist.c index a42cde8..19eaa2a 100644 --- a/trunk/gpgme/keylist.c +++ b/trunk/gpgme/keylist.c @@ -135,6 +135,34 @@ set_subkey_trust_info ( struct subkey_s *k, const char *s ) } } +static void +set_mainkey_capability ( GpgmeKey key, const char *s ) +{ + for (; *s ; s++ ) { + switch (*s) { + case 'e': key->keys.flags.can_encrypt = 1; break; + case 's': key->keys.flags.can_sign = 1; break; + case 'c': key->keys.flags.can_certify = 1; break; + case 'E': key->gloflags.can_encrypt = 1; break; + case 'S': key->gloflags.can_sign = 1; break; + case 'C': key->gloflags.can_certify = 1; break; + } + } +} + +static void +set_subkey_capability ( struct subkey_s *k, const char *s ) +{ + for (; *s; s++ ) { + switch (*s) { + case 'e': k->flags.can_encrypt = 1; break; + case 's': k->flags.can_sign = 1; break; + case 'c': k->flags.can_certify = 1; break; + } + } +} + + /* Note: we are allowed to modify line */ static void @@ -245,9 +273,12 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) break; case 10: /* not used due to --fixed-list-mode option */ break; - case 11: /* signature class */ + case 11: /* signature class */ break; - case 12: + case 12: /* capabilities */ + set_mainkey_capability (key, p ); + break; + case 13: pend = NULL; /* we can stop here */ break; } @@ -284,7 +315,10 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line ) break; case 11: /* signature class */ break; - case 12: + case 12: /* capability */ + set_subkey_capability ( sk, p ); + break; + case 13: pend = NULL; /* we can stop here */ break; } diff --git a/trunk/gpgme/posix-util.c b/trunk/gpgme/posix-util.c index 3c0c692..38fb2f0 100644 --- a/trunk/gpgme/posix-util.c +++ b/trunk/gpgme/posix-util.c @@ -33,6 +33,9 @@ const char * _gpgme_get_gpg_path (void) { + /* #warning Forced to development version + return "/home/wk/work/gnupg-stable/g10/gpg"; + */ return GPG_PATH; } diff --git a/trunk/gpgme/rungpg.c b/trunk/gpgme/rungpg.c index 404f7fe..bed8aac 100644 --- a/trunk/gpgme/rungpg.c +++ b/trunk/gpgme/rungpg.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/trunk/tests/t-keylist.c b/trunk/tests/t-keylist.c index fb7b79d..317990c 100644 --- a/trunk/tests/t-keylist.c +++ b/trunk/tests/t-keylist.c @@ -54,10 +54,17 @@ doit ( GpgmeCtx ctx, const char *pattern ) else fputs("\n", stdout ); - s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0 ); - printf ("\n", s ); - s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0 ); - printf ("\n", s ); + + for (i=0; ; i++ ) { + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i ); + if (!s) + break; + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i ); + printf ("\n", i, s ); + s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i ); + printf ("\n", i, s ); + } for (i=0; ; i++ ) { s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i ); if (!s) @@ -68,6 +75,15 @@ doit ( GpgmeCtx ctx, const char *pattern ) s = gpgme_key_get_string_attr (key, GPGME_ATTR_COMMENT, NULL, i ); printf ("\n", i, s ); } + + fputs ("\n", stdout ); printf ("\n", key ); gpgme_key_release (key); @@ -97,6 +113,7 @@ main (int argc, char **argv ) err = gpgme_new (&ctx); fail_if_err (err); + gpgme_set_keylist_mode (ctx, 1); /* no validity calculation */ do { fprintf (stderr, "** pattern=`%s'\n", pattern ); doit ( ctx, pattern );