diff options
Diffstat (limited to 'lib/openpgp/privkey.c')
-rw-r--r-- | lib/openpgp/privkey.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/openpgp/privkey.c b/lib/openpgp/privkey.c index 8870ef6707..bd04b21969 100644 --- a/lib/openpgp/privkey.c +++ b/lib/openpgp/privkey.c @@ -253,7 +253,8 @@ gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key, unsigned int *bits) { cdk_packet_t pkt; - int algo; + int algo = 0, ret; + uint8_t keyid[GNUTLS_OPENPGP_KEYID_SIZE]; if (!key) { @@ -261,13 +262,24 @@ gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key, return GNUTLS_PK_UNKNOWN; } - algo = 0; - pkt = cdk_kbnode_find_packet (key->knode, CDK_PKT_SECRET_KEY); - if (pkt) + ret = gnutls_openpgp_privkey_get_preferred_key_id (key, keyid); + if (ret == 0) { - if (bits) - *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); - algo = _gnutls_openpgp_get_algo (pkt->pkt.secret_key->pk->pubkey_algo); + int idx; + + idx = gnutls_openpgp_privkey_get_subkey_idx (key, keyid); + algo = + gnutls_openpgp_privkey_get_subkey_pk_algorithm (key, idx, NULL); + } + else + { + pkt = cdk_kbnode_find_packet (key->knode, CDK_PKT_SECRET_KEY); + if (pkt) + { + if (bits) + *bits = cdk_pk_get_nbits (pkt->pkt.secret_key->pk); + algo = _gnutls_openpgp_get_algo (pkt->pkt.secret_key->pk->pubkey_algo); + } } return algo; |