diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2003-12-21 09:47:34 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2003-12-21 09:47:34 +0000 |
commit | 2fdcd35de21b6d2a81a74580f368863f6c483ad1 (patch) | |
tree | 63a0e4a3b93259e18f9bbab8d3e1c89503350d67 /libextra | |
parent | 47568619a72f494719e468cc39a4b254954ea134 (diff) | |
download | gnutls-2fdcd35de21b6d2a81a74580f368863f6c483ad1.tar.gz |
Added gnutls_openpgp_key_get_key_usage(), and removed several compatibility
functions.
Diffstat (limited to 'libextra')
-rw-r--r-- | libextra/gnutls_openpgp.c | 13 | ||||
-rw-r--r-- | libextra/openpgp/openpgp.c | 53 | ||||
-rw-r--r-- | libextra/openpgp/verify.c | 2 | ||||
-rw-r--r-- | libextra/openpgp/xml.c | 2 |
4 files changed, 53 insertions, 17 deletions
diff --git a/libextra/gnutls_openpgp.c b/libextra/gnutls_openpgp.c index a4cba3e0db..86c2daffe3 100644 --- a/libextra/gnutls_openpgp.c +++ b/libextra/gnutls_openpgp.c @@ -217,11 +217,10 @@ kbx_data_to_keyring( int type, int enc, const char *data, } -CDK_PACKET* -search_packet( const gnutls_datum *buf, int pkttype ) +cdk_packet_t search_packet( const gnutls_datum *buf, int pkttype ) { static cdk_kbnode_t knode = NULL; - CDK_PACKET *pkt; + cdk_packet_t pkt; if( !buf && !pkttype ) { cdk_kbnode_release( knode ); @@ -296,7 +295,7 @@ _gnutls_openpgp_raw_privkey_to_gkey( gnutls_privkey *pkey, const gnutls_datum *raw_key) { cdk_kbnode_t snode; - CDK_PACKET *pkt; + cdk_packet_t pkt; cdk_stream_t out; cdk_pkt_seckey_t sk = NULL; int pke_algo, i, j; @@ -378,7 +377,7 @@ int _gnutls_openpgp_raw_key_to_gcert( gnutls_cert *cert, const gnutls_datum *raw ) { cdk_kbnode_t knode = NULL; - CDK_PACKET *pkt = NULL; + cdk_packet_t pkt = NULL; int rc; if( !cert ) { @@ -525,7 +524,7 @@ gnutls_certificate_set_openpgp_key_mem( gnutls_certificate_credentials res, { gnutls_datum raw; cdk_kbnode_t knode = NULL, ctx = NULL, p; - CDK_PACKET *pkt; + cdk_packet_t pkt; int i = 0; int rc = 0; cdk_stream_t inp = NULL; @@ -710,7 +709,7 @@ int gnutls_openpgp_count_key_names( const gnutls_datum *cert ) { cdk_kbnode_t knode, p, ctx = NULL; - CDK_PACKET *pkt; + cdk_packet_t pkt; int nuids = 0; if( cert == NULL ) { diff --git a/libextra/openpgp/openpgp.c b/libextra/openpgp/openpgp.c index 3eec67b817..22a28a9461 100644 --- a/libextra/openpgp/openpgp.c +++ b/libextra/openpgp/openpgp.c @@ -206,7 +206,7 @@ int gnutls_openpgp_key_get_fingerprint( gnutls_openpgp_key key, void *fpr, size_t *fprlen ) { - CDK_PACKET *pkt; + cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; if( !fpr || !fprlen ) { @@ -234,7 +234,7 @@ int _gnutls_openpgp_count_key_names( gnutls_openpgp_key key) { cdk_kbnode_t p, ctx = NULL; - CDK_PACKET *pkt; + cdk_packet_t pkt; int nuids = 0; if( key == NULL ) { @@ -270,7 +270,7 @@ gnutls_openpgp_key_get_name( gnutls_openpgp_key key, char *buf, size_t *sizeof_buf) { cdk_kbnode_t ctx = NULL, p; - CDK_PACKET *pkt = NULL; + cdk_packet_t pkt = NULL; cdk_pkt_userid_t uid = NULL; int pos = 0; size_t size = 0; @@ -343,7 +343,7 @@ leave: int gnutls_openpgp_key_get_pk_algorithm( gnutls_openpgp_key key, unsigned int *bits) { - CDK_PACKET *pkt; + cdk_packet_t pkt; int algo = 0; if( !key ) @@ -375,7 +375,7 @@ gnutls_openpgp_key_get_pk_algorithm( gnutls_openpgp_key key, unsigned int *bits) int gnutls_openpgp_key_get_version( gnutls_openpgp_key key) { - CDK_PACKET *pkt; + cdk_packet_t pkt; int version = 0; if( !key) @@ -398,7 +398,7 @@ gnutls_openpgp_key_get_version( gnutls_openpgp_key key) time_t gnutls_openpgp_key_get_creation_time( gnutls_openpgp_key key) { - CDK_PACKET *pkt; + cdk_packet_t pkt; time_t timestamp = 0; if( !key) @@ -422,7 +422,7 @@ gnutls_openpgp_key_get_creation_time( gnutls_openpgp_key key) time_t gnutls_openpgp_key_get_expiration_time( gnutls_openpgp_key key) { - CDK_PACKET *pkt; + cdk_packet_t pkt; time_t expiredate = 0; if( !key) @@ -446,7 +446,7 @@ int gnutls_openpgp_key_get_id( gnutls_openpgp_key key, unsigned char keyid[8]) { - CDK_PACKET *pkt; + cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; unsigned long kid[2]; @@ -513,4 +513,41 @@ int gnutls_openpgp_key_check_hostname(gnutls_openpgp_key key, return 0; } +/** + * gnutls_openpgp_key_get_key_usage - This function returns the key's usage + * @key: should contain a gnutls_openpgp_key structure + * @key_usage: where the key usage bits will be stored + * + * This function will return certificate's key usage, by checking the + * key algorithm. The key usage value will ORed values of the: + * GNUTLS_KEY_DIGITAL_SIGNATURE, GNUTLS_KEY_KEY_ENCIPHERMENT. + * + * A negative value may be returned in case of parsing error. + * + **/ +int gnutls_openpgp_key_get_key_usage(gnutls_openpgp_key key, unsigned int *key_usage) +{ +cdk_packet_t pkt; +int algo = 0; + + if( !key ) + return GNUTLS_E_INVALID_REQUEST; + + *key_usage = 0; + + pkt = cdk_kbnode_find_packet( key->knode, CDK_PKT_PUBLIC_KEY); + if( pkt && pkt->pkttype == CDK_PKT_PUBLIC_KEY ) { + algo = pkt->pkt.public_key->pubkey_algo; + + if( is_DSA(algo) || algo == GCRY_PK_RSA_S ) + *key_usage |= KEY_DIGITAL_SIGNATURE; + else if( algo == GCRY_PK_RSA_E ) + *key_usage |= KEY_KEY_ENCIPHERMENT; + else if( algo == GCRY_PK_RSA ) + *key_usage |= KEY_DIGITAL_SIGNATURE | KEY_KEY_ENCIPHERMENT; + } + + return 0; +} + #endif diff --git a/libextra/openpgp/verify.c b/libextra/openpgp/verify.c index 764fe761a1..481c558222 100644 --- a/libextra/openpgp/verify.c +++ b/libextra/openpgp/verify.c @@ -34,7 +34,7 @@ static int openpgp_get_key_trust( gnutls_openpgp_trustdb trustdb, gnutls_openpgp_key key, unsigned int *r_trustval ) { - CDK_PACKET *pkt; + cdk_packet_t pkt; cdk_pkt_pubkey_t pk = NULL; int flags = 0, ot = 0; int rc = 0; diff --git a/libextra/openpgp/xml.c b/libextra/openpgp/xml.c index 0f835dbbde..aacad0830d 100644 --- a/libextra/openpgp/xml.c +++ b/libextra/openpgp/xml.c @@ -338,7 +338,7 @@ gnutls_openpgp_key_to_xml( gnutls_openpgp_key key, gnutls_datum *xmlkey, int ext ) { cdk_kbnode_t node, ctx = NULL; - CDK_PACKET *pkt; + cdk_packet_t pkt; char name[MAX_CN]; size_t name_len; const char *s; |