Skip to content

Commit 7998a34

Browse files
committed
FFI: Add function rnp_key_signature_set_trust_level().
1 parent 3f9165d commit 7998a34

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

include/rnp/rnp.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,20 @@ RNP_API rnp_result_t rnp_key_signature_set_revoker(rnp_signature_handle_t sig,
17631763
rnp_key_handle_t revoker,
17641764
uint32_t flags);
17651765

1766+
/**
1767+
* @brief Set the signature trust level and amount. See OpenPGP specification for the details
1768+
* on their interpretation ('Trust Signature' signature subpacket). Makes sense only for
1769+
* other key's certification.
1770+
*
1771+
* @param sig editable key signature handle, i.e. created with rnp_key_*_signature_create().
1772+
* @param level trust level
1773+
* @param amount trust amount
1774+
* @return RNP_SUCCESS or error code if failed.
1775+
*/
1776+
RNP_API rnp_result_t rnp_key_signature_set_trust_level(rnp_signature_handle_t sig,
1777+
uint8_t level,
1778+
uint8_t amount);
1779+
17661780
/**
17671781
* @brief Finalize populating and sign signature, created with one of the
17681782
* rnp_key_*_signature_create functions, and add it to the corresponding key.

src/lib/rnp.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6421,6 +6421,20 @@ try {
64216421
}
64226422
FFI_GUARD
64236423

6424+
rnp_result_t
6425+
rnp_key_signature_set_trust_level(rnp_signature_handle_t sig, uint8_t level, uint8_t amount)
6426+
try {
6427+
if (!sig) {
6428+
return RNP_ERROR_NULL_POINTER;
6429+
}
6430+
if (!sig->new_sig) {
6431+
return RNP_ERROR_BAD_PARAMETERS;
6432+
}
6433+
sig->sig->sig.set_trust(level, amount);
6434+
return RNP_SUCCESS;
6435+
}
6436+
FFI_GUARD
6437+
64246438
rnp_result_t
64256439
rnp_key_signature_sign(rnp_signature_handle_t sig)
64266440
try {

src/tests/ffi-key-sig.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ TEST_F(rnp_tests, test_ffi_create_key_certification_signature)
20692069
assert_rnp_success(rnp_key_get_uid_handle_at(key, 0, &uid));
20702070
rnp_key_handle_t signer = NULL;
20712071
assert_rnp_success(rnp_locate_key(ffi, "userid", "ecc-25519", &signer));
2072-
/* Create other key certification with default type*/
2072+
/* Create other key certification with default type */
20732073
rnp_signature_handle_t newsig = NULL;
20742074
assert_rnp_success(rnp_key_certification_create(signer, uid, NULL, &newsig));
20752075
const char *hash = "SHA384";
@@ -2083,6 +2083,8 @@ TEST_F(rnp_tests, test_ffi_create_key_certification_signature)
20832083
rnp_key_certification_create(signer, uid, RNP_CERTIFICATION_CASUAL, &newsig));
20842084
const char *hash2 = "SHA512";
20852085
assert_rnp_success(rnp_key_signature_set_hash(newsig, hash2));
2086+
assert_rnp_failure(rnp_key_signature_set_trust_level(NULL, 1, 120));
2087+
assert_rnp_success(rnp_key_signature_set_trust_level(newsig, 1, 120));
20862088
assert_rnp_success(rnp_key_signature_sign(newsig));
20872089
rnp_signature_handle_destroy(newsig);
20882090
/* Check certification parameters */
@@ -2093,11 +2095,26 @@ TEST_F(rnp_tests, test_ffi_create_key_certification_signature)
20932095
assert_rnp_success(rnp_signature_is_valid(newsig, 0));
20942096
assert_true(check_sig_hash(newsig, hash));
20952097
assert_true(check_sig_type(newsig, "certification (generic)"));
2098+
uint8_t level = 255;
2099+
uint8_t amount = 255;
2100+
assert_rnp_failure(rnp_signature_get_trust_level(NULL, NULL, NULL));
2101+
assert_rnp_success(rnp_signature_get_trust_level(newsig, NULL, NULL));
2102+
assert_rnp_success(rnp_signature_get_trust_level(newsig, &level, NULL));
2103+
assert_int_equal(level, 0);
2104+
assert_rnp_success(rnp_signature_get_trust_level(newsig, NULL, &amount));
2105+
assert_int_equal(amount, 0);
2106+
level = amount = 255;
2107+
assert_rnp_success(rnp_signature_get_trust_level(newsig, &level, &amount));
2108+
assert_int_equal(level, 0);
2109+
assert_int_equal(amount, 0);
20962110
rnp_signature_handle_destroy(newsig);
20972111
assert_rnp_success(rnp_uid_get_signature_at(uid, 2, &newsig));
20982112
assert_rnp_success(rnp_signature_is_valid(newsig, 0));
20992113
assert_true(check_sig_hash(newsig, hash2));
21002114
assert_true(check_sig_type(newsig, "certification (casual)"));
2115+
assert_rnp_success(rnp_signature_get_trust_level(newsig, &level, &amount));
2116+
assert_int_equal(level, 1);
2117+
assert_int_equal(amount, 120);
21012118
rnp_signature_handle_destroy(newsig);
21022119
rnp_uid_handle_destroy(uid);
21032120
rnp_key_handle_destroy(signer);

0 commit comments

Comments
 (0)