Skip to content

Commit

Permalink
Add rnp_signature_get_features
Browse files Browse the repository at this point in the history
  • Loading branch information
kaie authored and ni4 committed Feb 26, 2024
1 parent 72326b7 commit d5b2979
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/rnp/rnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/librepgp/stream-sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/librepgp/stream-sig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/tests/ffi-key-sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d5b2979

Please sign in to comment.