Skip to content

Commit

Permalink
FFI: Add function rnp_signature_get_revocation_rason().
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Jan 5, 2024
1 parent cd23a3a commit bb61d58
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/rnp/rnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,21 @@ RNP_API rnp_result_t rnp_signature_get_signer(rnp_signature_handle_t sig,
*/
RNP_API rnp_result_t rnp_signature_get_revoker(rnp_signature_handle_t sig, char **revoker);

/**
* @brief Get revocation reason data, if it is available in the signature.
*
* @param sig signature handle, cannot be NULL.
* @param code string with revocation code will be stored here, if not NULL. See description of
* function rnp_key_revoke() for possible values. If information is not available,
* empty string will be stored here.
* @param reason revocation reason will be stored here, if available. Otherwise empty string
* will be stored here. May be NULL if this information is not needed.
* @return RNP_SUCCESS or error code if failed.
*/
RNP_API rnp_result_t rnp_signature_get_revocation_reason(rnp_signature_handle_t sig,
char ** code,
char ** reason);

/**
* @brief Get signature validity, revalidating it if didn't before.
*
Expand Down
31 changes: 31 additions & 0 deletions src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6519,6 +6519,37 @@ try {
}
FFI_GUARD

rnp_result_t
rnp_signature_get_revocation_reason(rnp_signature_handle_t sig, char **code, char **reason)
{
if (!sig) {
return RNP_ERROR_NULL_POINTER;
}
std::string rcode;
std::string rreason;
if (sig->sig->sig.has_revocation_reason()) {
rcode = id_str_pair::lookup(revocation_code_map, sig->sig->sig.revocation_code(), "");
rreason = sig->sig->sig.revocation_reason();
}
if (code) {
rnp_result_t ret = ret_str_value("", code);
if (ret) {
return ret;
}
}
if (reason) {
rnp_result_t ret = ret_str_value("", reason);
if (ret) {
if (code) {
free(*code);
*code = NULL;
}
return ret;
}
}
return RNP_SUCCESS;
}

rnp_result_t
rnp_signature_is_valid(rnp_signature_handle_t sig, uint32_t flags)
try {
Expand Down
6 changes: 6 additions & 0 deletions src/librepgp/stream-sig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ pgp_signature_t::revocation_code() const
return subpkt ? subpkt->fields.revocation_reason.code : PGP_REVOCATION_NO_REASON;
}

bool
pgp_signature_t::has_revocation_reason() const
{
return get_subpkt(PGP_SIG_SUBPKT_REVOCATION_REASON);
}

void
pgp_signature_t::set_revocation_reason(pgp_revocation_type_t code, const std::string &reason)
{
Expand Down
5 changes: 5 additions & 0 deletions src/librepgp/stream-sig.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ typedef struct pgp_signature_t {
*/
pgp_revocation_type_t revocation_code() const;

/**
* @brief Check whether signature has revocation reason and code subpacket.
*/
bool has_revocation_reason() const;

/** @brief Set the revocation reason and code for key/subkey revocation signature. See the
* RFC 4880, 5.2.3.24 for the detailed explanation.
*/
Expand Down

0 comments on commit bb61d58

Please sign in to comment.