-
Notifications
You must be signed in to change notification settings - Fork 60
Refactor stream-dump to C++. #2345
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
void | ||
DumpContextDst::dump_signature_subpacket(const pkt::sigsub::Raw &subpkt) |
Check warning
Code scanning / CodeQL
Poorly documented large function Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 hour ago
To address the issue, we will add comments to document the purpose and behavior of the DumpContextDst::dump_signature_subpacket
function. Specifically, we will:
- Add a high-level comment above the function to describe its overall purpose and how it fits into the larger system.
- Add inline comments within the function to explain the logic of each case in the switch statement, particularly the nuances of handling different subpacket types.
- Ensure that the comments are concise but informative, focusing on the "why" behind the code rather than the "what," which is often self-evident.
These changes will improve the function's readability and maintainability without altering its functionality.
-
Copy modified lines R634-R644 -
Copy modified line R648 -
Copy modified line R651 -
Copy modified line R654 -
Copy modified line R660 -
Copy modified line R666
@@ -633,2 +633,13 @@ | ||
|
||
/** | ||
* DumpContextDst::dump_signature_subpacket | ||
* ---------------------------------------- | ||
* This function processes and outputs information about a signature subpacket. | ||
* It identifies the subpacket type, extracts relevant data, and formats it for | ||
* output using the destination context (`dst`). The function supports various | ||
* subpacket types, such as creation time, expiration time, and exportable | ||
* certification, and handles each type accordingly. | ||
* | ||
* @param subpkt The raw signature subpacket to process. | ||
*/ | ||
void | ||
@@ -636,6 +647,9 @@ | ||
{ | ||
// Lookup the subpacket type name for display purposes | ||
auto sname = id_str_pair::lookup(sig_subpkt_type_map, subpkt.raw_type(), "Unknown"); | ||
|
||
// Handle the subpacket based on its type | ||
switch (subpkt.type()) { | ||
case pkt::sigsub::Type::CreationTime: { | ||
// Process a subpacket containing the creation time of the signature | ||
auto &sub = dynamic_cast<const pkt::sigsub::CreationTime &>(subpkt); | ||
@@ -645,2 +659,3 @@ | ||
case pkt::sigsub::Type::ExpirationTime: { | ||
// Process a subpacket containing the expiration time of the signature | ||
auto &sub = dynamic_cast<const pkt::sigsub::ExpirationTime &>(subpkt); | ||
@@ -650,2 +665,3 @@ | ||
case pkt::sigsub::Type::ExportableCert: { | ||
// Process a subpacket indicating whether the certification is exportable | ||
auto &sub = dynamic_cast<const pkt::sigsub::ExportableCert &>(subpkt); |
static rnp_result_t | ||
stream_dump_packets_raw(rnp_dump_ctx_t *ctx, pgp_source_t *src, pgp_dest_t *dst) | ||
rnp_result_t | ||
DumpContextDst::dump_raw_packets() |
Check warning
Code scanning / CodeQL
Poorly documented large function Warning
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 hour ago
To fix the issue, we will add comments to the DumpContextDst::dump_raw_packets
function to document its purpose, logic, and key steps. This includes:
- Adding a function-level comment to describe the overall purpose of the function.
- Adding inline comments to explain significant blocks of code, such as the handling of nested layers, the main loop, and error conditions.
- Ensuring that the comments are concise and relevant, without overwhelming the code.
-
Copy modified lines R1448-R1454 -
Copy modified line R1456 -
Copy modified line R1461 -
Copy modified line R1468 -
Copy modified line R1470 -
Copy modified lines R1586-R1587
@@ -1447,6 +1447,11 @@ | ||
{ | ||
char msg[1024 + PGP_MAX_HEADER_SIZE] = {0}; | ||
char smsg[128] = {0}; | ||
rnp_result_t ret = RNP_ERROR_GENERIC; | ||
// This function processes and dumps raw OpenPGP packets from the source stream. | ||
// It handles nested packet layers, ensuring that the maximum nesting level is not exceeded. | ||
// The function returns RNP_SUCCESS on successful processing or an appropriate error code. | ||
|
||
char msg[1024 + PGP_MAX_HEADER_SIZE] = {0}; // Buffer for packet messages | ||
char smsg[128] = {0}; // Buffer for short messages | ||
rnp_result_t ret = RNP_ERROR_GENERIC; // Default return value | ||
|
||
// Check if the source stream has reached the end | ||
if (src.eof()) { | ||
@@ -1455,3 +1460,3 @@ | ||
|
||
/* do not allow endless recursion */ | ||
// Prevent infinite recursion by limiting the nesting level of OpenPGP packets | ||
if (++layers > MAXIMUM_NESTING_LEVEL) { | ||
@@ -1462,3 +1467,5 @@ | ||
|
||
// Main loop to process packets until the end of the source stream | ||
while (!src.eof()) { | ||
// Read and process each packet (details omitted for brevity) | ||
pgp_packet_hdr_t hdr{}; | ||
@@ -1578,2 +1585,4 @@ | ||
} | ||
|
||
// Return success after processing all packets | ||
return RNP_SUCCESS; |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2345 +/- ##
==========================================
+ Coverage 85.39% 85.43% +0.04%
==========================================
Files 125 126 +1
Lines 22740 22719 -21
==========================================
- Hits 19418 19410 -8
+ Misses 3322 3309 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d08c6d5
to
d0b60c2
Compare
d0b60c2
to
d0d0bd2
Compare
@@ -264,56 +264,48 @@ | |||
indent_dst_close(pgp_dest_t *dst, bool discard) | |||
{ | |||
pgp_dest_indent_param_t *param = (pgp_dest_indent_param_t *) dst->param; | |||
if (!param) { | |||
return; | |||
if (param) { |
Check notice
Code scanning / CodeQL
Guarded Free Note
As title says