Give access to key capabilities

This commit is contained in:
Werner Koch 2001-03-15 13:09:41 +00:00
parent 10b3a86f83
commit 5b561c2f11
8 changed files with 126 additions and 8 deletions

View File

@ -1,3 +1,20 @@
2001-03-15 Werner Koch <wk@gnupg.org>
* 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 <wk@gnupg.org>
* w32-io.c (destroy_reader,destroy_writer): Fixed syntax error.
Thanks to Jan Oliver Wagner.
2001-03-13 Werner Koch <wk@gnupg.org>
* context.h: Add invalid and revoke flags to user_id structure.

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;

View File

@ -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
@ -247,7 +275,10 @@ keylist_colon_handler ( GpgmeCtx ctx, char *line )
break;
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;
}

View File

@ -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;
}

View File

@ -24,6 +24,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h>

View File

@ -54,10 +54,17 @@ doit ( GpgmeCtx ctx, const char *pattern )
else
fputs("<!-- Ooops: gpgme_key_get_as_xml failed -->\n", stdout );
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0 );
printf ("<!-- keyid=%s -->\n", s );
s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0 );
printf ("<!-- algo=%s -->\n", s );
for (i=0; ; i++ ) {
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, i );
if (!s)
break;
printf ("<!-- keyid.%d=%s -->\n", i, s );
s = gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, i );
printf ("<!-- algo.%d=%s -->\n", i, s );
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEY_CAPS, NULL, i );
printf ("<!-- caps.%d=%s -->\n", i, s );
}
for (i=0; ; i++ ) {
s = gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, NULL, i );
if (!s)
@ -69,6 +76,15 @@ doit ( GpgmeCtx ctx, const char *pattern )
printf ("<!-- comment.%d=%s -->\n", i, s );
}
fputs ("<!-- usable for:", stdout );
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_ENCRYPT, NULL, 0 ))
fputs (" encryption", stdout);
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_SIGN, NULL, 0 ))
fputs (" signing", stdout);
if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_CAN_CERTIFY, NULL, 0 ))
fputs (" certification", stdout);
fputs (" -->\n", stdout );
printf ("<!-- End key object (%p) -->\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 );