diff --git a/include/rnp/rnp.h b/include/rnp/rnp.h index 926dfc9833..149264da6d 100644 --- a/include/rnp/rnp.h +++ b/include/rnp/rnp.h @@ -138,6 +138,13 @@ typedef uint32_t rnp_result_t; #define RNP_VERIFY_REQUIRE_ALL_SIGS (1U << 1) #define RNP_VERIFY_ALLOW_HIDDEN_RECIPIENT (1U << 2) +/** + * Key feature flags. + */ +#define RNP_KEY_FEATURE_MDC (1U << 0) +#define RNP_KEY_FEATURE_AEAD (1U << 1) +#define RNP_KEY_FEATURE_V5 (1U << 2) + /** * Return a constant string describing the result code */ @@ -1443,6 +1450,9 @@ RNP_API rnp_result_t rnp_signature_get_creation(rnp_signature_handle_t sig, uint RNP_API rnp_result_t rnp_signature_get_expiration(rnp_signature_handle_t sig, uint32_t * expires); +RNP_API rnp_result_t rnp_signature_get_features(rnp_signature_handle_t sig, + uint32_t * features); + /** Get signer's key id from the signature. * Note: if key id is not available from the signature then NULL value will * be stored to result. diff --git a/src/lib/rnp.cpp b/src/lib/rnp.cpp index 24c46f986d..4722ac7dad 100644 --- a/src/lib/rnp.cpp +++ b/src/lib/rnp.cpp @@ -6196,6 +6196,20 @@ try { } FFI_GUARD +rnp_result_t +rnp_signature_get_features(rnp_signature_handle_t handle, uint32_t *features) +try { + if (!handle || !features) { + return RNP_ERROR_NULL_POINTER; + } + if (!handle->sig) { + return RNP_ERROR_BAD_PARAMETERS; + } + *features = handle->sig->sig.key_get_features(); + return RNP_SUCCESS; +} +FFI_GUARD + rnp_result_t rnp_signature_get_keyid(rnp_signature_handle_t handle, char **result) try { diff --git a/src/librepgp/stream-sig.cpp b/src/librepgp/stream-sig.cpp index 6f3bc81fe1..e9948077bd 100644 --- a/src/librepgp/stream-sig.cpp +++ b/src/librepgp/stream-sig.cpp @@ -1005,6 +1005,13 @@ pgp_signature_t::set_revocation_reason(pgp_revocation_type_t code, const std::st } } +pgp_key_feature_t +pgp_signature_t::key_get_features() const +{ + const pgp_sig_subpkt_t *subpkt = get_subpkt(PGP_SIG_SUBPKT_FEATURES); + return (pgp_key_feature_t)(subpkt ? subpkt->data[0] : 0); +} + bool pgp_signature_t::key_has_features(pgp_key_feature_t flags) const { diff --git a/src/librepgp/stream-sig.h b/src/librepgp/stream-sig.h index 4f36c381f1..943efa96ae 100644 --- a/src/librepgp/stream-sig.h +++ b/src/librepgp/stream-sig.h @@ -274,6 +274,8 @@ typedef struct pgp_signature_t { */ void set_revocation_reason(pgp_revocation_type_t code, const std::string &reason); + pgp_key_feature_t key_get_features() const; + /** * @brief Check whether signer's key supports certain feature(s). Makes sense only for * self-signature, for more details see the RFC 4880bis, 5.2.3.25. If there is diff --git a/src/tests/ffi-key-sig.cpp b/src/tests/ffi-key-sig.cpp index 01bfdd262b..4814b3fa17 100644 --- a/src/tests/ffi-key-sig.cpp +++ b/src/tests/ffi-key-sig.cpp @@ -902,6 +902,9 @@ TEST_F(rnp_tests, test_ffi_sig_validity) uint32_t expires = 0; assert_rnp_success(rnp_signature_get_expiration(sig, &expires)); assert_int_equal(expires, 86400); + uint32_t features = 0; + assert_rnp_success(rnp_signature_get_features(sig, &features)); + assert_int_equal(features, 0); rnp_signature_handle_destroy(sig); rnp_uid_handle_destroy(uid); rnp_key_handle_destroy(key);