Skip to content

Commit

Permalink
(WIP) FFI: Add API to retrieve raw subpacket data.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Oct 8, 2024
1 parent bc4c22f commit 0df336e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/rnp/rnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions include/rnp/rnp_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions src/lib/ffi-priv-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions src/lib/rnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6650,6 +6650,52 @@ try {
}
FFI_GUARD

rnp_result_t
rnp_signature_subpacket_first(rnp_signature_handle_t sig,

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6654

Added line #L6654 was not covered by tests
uint8_t type,
bool hashed,
rnp_sig_subpacket_t * subpkt)
try {
if (!sig || !subpkt) {
return RNP_ERROR_NULL_POINTER;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6659-L6660

Added lines #L6659 - L6660 were not covered by tests
}
return RNP_ERROR_NOT_IMPLEMENTED;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6662

Added line #L6662 was not covered by tests
}
FFI_GUARD

rnp_result_t
rnp_signature_subpacket_next(rnp_sig_subpacket_t *subpkt)

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6667

Added line #L6667 was not covered by tests
try {
if (!subpkt) {
return RNP_ERROR_NULL_POINTER;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6669-L6670

Added lines #L6669 - L6670 were not covered by tests
}
return RNP_ERROR_NOT_IMPLEMENTED;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6672

Added line #L6672 was not covered by tests
}
FFI_GUARD

rnp_result_t
rnp_signature_subpacket_info(rnp_sig_subpacket_t subpkt,

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6677

Added line #L6677 was not covered by tests
uint8_t * type,
bool * hashed,
bool * critical)
try {
if (!subpkt) {
return RNP_ERROR_NULL_POINTER;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6682-L6683

Added lines #L6682 - L6683 were not covered by tests
}
return RNP_ERROR_NOT_IMPLEMENTED;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6685

Added line #L6685 was not covered by tests
}
FFI_GUARD

rnp_result_t
rnp_signature_subpacket_data(rnp_sig_subpacket_t subpkt, uint8_t **data, size_t *size)

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6690

Added line #L6690 was not covered by tests
try {
if (!subpkt) {
return RNP_ERROR_NULL_POINTER;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6692-L6693

Added lines #L6692 - L6693 were not covered by tests
}
return RNP_ERROR_NOT_IMPLEMENTED;

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

View check run for this annotation

Codecov / codecov/patch

src/lib/rnp.cpp#L6695

Added line #L6695 was not covered by tests
}
FFI_GUARD

rnp_result_t
rnp_signature_get_expiration(rnp_signature_handle_t handle, uint32_t *expires)
try {
Expand Down

0 comments on commit 0df336e

Please sign in to comment.