From 0df336e34f379c9d4db2560039364fc5635a916d Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Tue, 17 Sep 2024 14:41:12 +0300 Subject: [PATCH] (WIP) FFI: Add API to retrieve raw subpacket data. --- include/rnp/rnp.h | 19 +++++++++++++++++ include/rnp/rnp_err.h | 1 + src/lib/ffi-priv-types.h | 12 +++++++++++ src/lib/rnp.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/include/rnp/rnp.h b/include/rnp/rnp.h index b364d401d4..cfbb5b9995 100644 --- a/include/rnp/rnp.h +++ b/include/rnp/rnp.h @@ -256,6 +256,7 @@ typedef struct rnp_op_encrypt_st * rnp_op_encrypt_t; typedef struct rnp_identifier_iterator_st *rnp_identifier_iterator_t; typedef struct rnp_uid_handle_st * rnp_uid_handle_t; typedef struct rnp_signature_handle_st * rnp_signature_handle_t; +typedef struct rnp_sig_subpacket_st * rnp_sig_subpacket_t; typedef struct rnp_recipient_handle_st * rnp_recipient_handle_t; typedef struct rnp_symenc_handle_st * rnp_symenc_handle_t; @@ -1893,6 +1894,24 @@ RNP_API rnp_result_t rnp_signature_get_hash_alg(rnp_signature_handle_t sig, char */ RNP_API rnp_result_t rnp_signature_get_creation(rnp_signature_handle_t sig, uint32_t *create); +RNP_API rnp_result_t rnp_signature_subpacket_first(rnp_signature_handle_t sig, + uint8_t type, + bool hashed, + rnp_sig_subpacket_t * subpkt); + +RNP_API rnp_result_t rnp_signature_subpacket_next(rnp_sig_subpacket_t *subpkt); + +RNP_API rnp_result_t rnp_signature_subpacket_info(rnp_sig_subpacket_t subpkt, + uint8_t * type, + bool * hashed, + bool * critical); + +RNP_API rnp_result_t rnp_signature_subpacket_data(rnp_sig_subpacket_t subpkt, + uint8_t ** data, + size_t * size); + +RNP_API rnp_result_t rnp_signature_subpacket_destroy(rnp_sig_subpacket_t subpkt); + /** Get the signature expiration time as number of seconds after creation time * * @param sig signature handle. diff --git a/include/rnp/rnp_err.h b/include/rnp/rnp_err.h index 49bef4f471..7cf36c0245 100644 --- a/include/rnp/rnp_err.h +++ b/include/rnp/rnp_err.h @@ -42,6 +42,7 @@ enum { RNP_ERROR_OUT_OF_MEMORY, RNP_ERROR_SHORT_BUFFER, RNP_ERROR_NULL_POINTER, + RNP_ERROR_NOT_FOUND, /* Storage */ RNP_ERROR_ACCESS = 0x11000000, diff --git a/src/lib/ffi-priv-types.h b/src/lib/ffi-priv-types.h index 97f012748f..04fcde13e1 100644 --- a/src/lib/ffi-priv-types.h +++ b/src/lib/ffi-priv-types.h @@ -67,6 +67,18 @@ struct rnp_signature_handle_st { bool new_sig; }; +struct rnp_sig_subpacket_st { + const pgp_signature_t &sig; + bool hashed; + uint8_t type; + size_t idx; + + rnp_sig_subpacket_st(const pgp_signature_t &asig) + : sig(asig), hashed(true), type(0), idx(0) + { + } +}; + struct rnp_recipient_handle_st { rnp_ffi_t ffi; pgp_key_id_t keyid; diff --git a/src/lib/rnp.cpp b/src/lib/rnp.cpp index b54640826a..b2589bc6ad 100644 --- a/src/lib/rnp.cpp +++ b/src/lib/rnp.cpp @@ -6650,6 +6650,52 @@ try { } FFI_GUARD +rnp_result_t +rnp_signature_subpacket_first(rnp_signature_handle_t sig, + uint8_t type, + bool hashed, + rnp_sig_subpacket_t * subpkt) +try { + if (!sig || !subpkt) { + return RNP_ERROR_NULL_POINTER; + } + return RNP_ERROR_NOT_IMPLEMENTED; +} +FFI_GUARD + +rnp_result_t +rnp_signature_subpacket_next(rnp_sig_subpacket_t *subpkt) +try { + if (!subpkt) { + return RNP_ERROR_NULL_POINTER; + } + return RNP_ERROR_NOT_IMPLEMENTED; +} +FFI_GUARD + +rnp_result_t +rnp_signature_subpacket_info(rnp_sig_subpacket_t subpkt, + uint8_t * type, + bool * hashed, + bool * critical) +try { + if (!subpkt) { + return RNP_ERROR_NULL_POINTER; + } + return RNP_ERROR_NOT_IMPLEMENTED; +} +FFI_GUARD + +rnp_result_t +rnp_signature_subpacket_data(rnp_sig_subpacket_t subpkt, uint8_t **data, size_t *size) +try { + if (!subpkt) { + return RNP_ERROR_NULL_POINTER; + } + return RNP_ERROR_NOT_IMPLEMENTED; +} +FFI_GUARD + rnp_result_t rnp_signature_get_expiration(rnp_signature_handle_t handle, uint32_t *expires) try {