Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rnp_signature_get_features #2188

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/rnp/rnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ typedef uint32_t rnp_result_t;
*/
#define RNP_REVOKER_SENSITIVE (1U << 0)

/**
* 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 @@ -1721,6 +1728,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 @@ -6522,6 +6522,20 @@
}
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;

Check warning on line 6532 in src/lib/rnp.cpp

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6532

Added line #L6532 was not covered by tests
}
*features = handle->sig->sig.key_get_features();
return RNP_SUCCESS;
}
FFI_GUARD

Check warning on line 6537 in src/lib/rnp.cpp

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6537

Added line #L6537 was not covered by tests

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 @@ -1097,6 +1097,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 @@ -289,6 +289,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
5 changes: 5 additions & 0 deletions src/tests/ffi-key-sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,11 @@ 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_failure(rnp_signature_get_features(NULL, &features));
assert_rnp_failure(rnp_signature_get_features(sig, NULL));
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
Loading