From 6d21256c9220df05bf92a695a787dde13fe44ca7 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 21 Mar 2023 08:36:33 +0100 Subject: [PATCH] core,cpp: Add new key flags to gpgme_subkey_t * src/gpgme.h.in (struct _gpgme_subkey): Add bit flags can_renc, can_timestamp, adn is_group_owned. Reduce size of _unused. * src/keylist.c (set_subkey_capability): Set them. * tests/run-keylist.c (main): Print them. * lang/cpp/src/key.h (Subkey::canRenc): New. (Subkey::canTimestamp): New. (Subkey::isGroupOwned): New. * lang/cpp/src/key.cpp: Implement new methods. (Subkey::isQualified): Print them. (std::ostream &operator<<): Print them. -- GnuPG-bug-id: 6395 --- NEWS | 9 +++++++++ lang/cpp/src/key.cpp | 18 ++++++++++++++++++ lang/cpp/src/key.h | 3 +++ src/gpgme.h.in | 11 ++++++++++- src/keylist.c | 12 ++++++++++++ tests/run-keylist.c | 9 ++++++--- 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 56c5a7ec..bcabe2ce 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,15 @@ Noteworthy changes in version 1.20.0 (unreleased) ------------------------------------------------- + * Interface changes relative to the 1.19.0 release: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + gpgme_subkey_t EXTENDED: New field 'can_renc'. + gpgme_subkey_t EXTENDED: New field 'can_timestamp'. + gpgme_subkey_t EXTENDED: New field 'is_group_owned'. + cpp: Subkey::canRenc NEW. + cpp: Subkey::canTimestamp NEW. + cpp: Subkey::isGroupOwned NEW. + Release-info: https://dev.gnupg.org/Tnnnn diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 293c9e5b..b7a55aec 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -515,6 +515,21 @@ bool Subkey::canAuthenticate() const return subkey && subkey->can_authenticate; } +bool Subkey::canRenc() const +{ + return subkey && subkey->can_renc; +} + +bool Subkey::canTimestamp() const +{ + return subkey && subkey->can_timestamp; +} + +bool Subkey::isGroupOwned() const +{ + return subkey && subkey->is_group_owned; +} + bool Subkey::isQualified() const { return subkey && subkey->is_qualified; @@ -1261,7 +1276,10 @@ std::ostream &operator<<(std::ostream &os, const Subkey &subkey) << "\n canEncrypt: " << subkey.canEncrypt() << "\n canCertify: " << subkey.canCertify() << "\n canAuth: " << subkey.canAuthenticate() + << "\n canRenc: " << subkey.canRenc() + << "\n canTimestanp: " << subkey.canTimestamp() << "\n isSecret: " << subkey.isSecret() + << "\n isGroupOwned: " << subkey.isGroupOwned() << "\n isQualified: " << subkey.isQualified() << "\n isDeVs: " << subkey.isDeVs() << "\n isCardKey: " << subkey.isCardKey() diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 09f1879f..787cb43e 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -270,6 +270,9 @@ public: bool canSign() const; bool canCertify() const; bool canAuthenticate() const; + bool canRenc() const; + bool canTimestamp() const; + bool isGroupOwned() const; bool isQualified() const; bool isDeVs() const; bool isCardKey() const; diff --git a/src/gpgme.h.in b/src/gpgme.h.in index 3ea07a81..1d3c1445 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -575,8 +575,17 @@ struct _gpgme_subkey /* True if the key is compliant to the de-vs mode. */ unsigned int is_de_vs : 1; + /* True if the key can be used for restricted encryption (ADSK). */ + unsigned int can_renc : 1; + + /* True if the key can be used for timestamping. */ + unsigned int can_timestamp : 1; + + /* True if the private key is possessed by more than one person. */ + unsigned int is_group_owned : 1; + /* Internal to GPGME, do not use. */ - unsigned int _unused : 20; + unsigned int _unused : 17; /* Public key algorithm supported by this subkey. */ gpgme_pubkey_algo_t pubkey_algo; diff --git a/src/keylist.c b/src/keylist.c index 1c01bd42..23b97087 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -287,6 +287,18 @@ set_subkey_capability (gpgme_subkey_t subkey, const char *src) subkey->can_authenticate = 1; break; + case 'r': + subkey->can_renc = 1; + break; + + case 't': + subkey->can_timestamp = 1; + break; + + case 'g': + subkey->is_group_owned = 1; + break; + case 'q': subkey->is_qualified = 1; break; diff --git a/tests/run-keylist.c b/tests/run-keylist.c index 929cb1d8..c662e902 100644 --- a/tests/run-keylist.c +++ b/tests/run-keylist.c @@ -309,19 +309,22 @@ main (int argc, char **argv) printf ("grip %2d: %s\n", nsub, subkey->keygrip); if (subkey->curve) printf ("curve %2d: %s\n", nsub, subkey->curve); - printf ("caps %2d: %s%s%s%s\n", + printf ("caps %2d: %s%s%s%s%s%s\n", nsub, subkey->can_encrypt? "e":"", subkey->can_sign? "s":"", subkey->can_certify? "c":"", - subkey->can_authenticate? "a":""); - printf ("flags %2d:%s%s%s%s%s%s%s%s\n", + subkey->can_authenticate? "a":"", + subkey->can_renc? "r":"", + subkey->can_timestamp? "t":""); + printf ("flags %2d:%s%s%s%s%s%s%s%s%s\n", nsub, subkey->secret? " secret":"", subkey->revoked? " revoked":"", subkey->expired? " expired":"", subkey->disabled? " disabled":"", subkey->invalid? " invalid":"", + subkey->is_group_owned? " group":"", subkey->is_qualified? " qualified":"", subkey->is_de_vs? " de-vs":"", subkey->is_cardkey? " cardkey":"");