Skip to content

Commit 4615933

Browse files
committed
AI review comments
1 parent 0190731 commit 4615933

File tree

7 files changed

+59
-34
lines changed

7 files changed

+59
-34
lines changed

include/aws/s3/private/s3_checksum_context.h

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/**
55
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6-
* SPDX-License-Identifier: Apache-2.0.
6+
* SPDX-License-Identifier: Apache-2.0
77
*/
88

99
#include "aws/s3/s3_client.h"
@@ -43,19 +43,29 @@ struct aws_s3_upload_request_checksum_context {
4343
*
4444
* @param allocator Memory allocator
4545
* @param checksum_config Meta request level checksum configuration (can be NULL)
46-
* @param checksum_buffer User-provided checksum buffer (can be NULL)
4746
* @return New checksum context or NULL on error
4847
*/
4948
AWS_S3_API
5049
struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_context_new(
5150
struct aws_allocator *allocator,
5251
const struct aws_s3_meta_request_checksum_config_storage *checksum_config);
5352

53+
/**
54+
* Create a new upload request checksum context with an existing checksum value.
55+
* This is useful when resuming uploads or when the checksum is pre-calculated.
56+
* Returns with reference count of 1.
57+
*
58+
* @param allocator Memory allocator
59+
* @param checksum_config Meta request level checksum configuration (can be NULL)
60+
* @param existing_checksum Pre-calculated checksum value as a byte cursor
61+
* @return New checksum context or NULL on error (e.g., if checksum size doesn't match algorithm)
62+
*/
5463
AWS_S3_API
55-
struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_context_new_with_exist_checksum(
64+
struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_context_new_with_existing_checksum(
5665
struct aws_allocator *allocator,
5766
const struct aws_s3_meta_request_checksum_config_storage *checksum_config,
58-
struct aws_byte_cursor exist_checksum);
67+
struct aws_byte_cursor existing_checksum);
68+
5969
/**
6070
* Acquire a reference to the upload request checksum context.
6171
* Use this when transferring ownership to another function/structure.
@@ -79,43 +89,55 @@ struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_co
7989
struct aws_s3_upload_request_checksum_context *context);
8090

8191
/**
82-
* Check if checksum calculation is needed based on context state
92+
* Check if checksum calculation is needed based on context state.
93+
* Returns true if the context has a valid algorithm and the checksum has not been calculated yet.
94+
*
95+
* @param context The checksum context to check
96+
* @return true if checksum calculation is needed, false otherwise
8397
*/
8498
AWS_S3_API
8599
bool aws_s3_upload_request_checksum_context_should_calculate(
86100
const struct aws_s3_upload_request_checksum_context *context);
87101

88102
/**
89-
* Check if checksum should be added to HTTP headers
103+
* Check if checksum should be added to HTTP headers.
104+
* Returns true if the context has a valid algorithm and the location is set to header.
105+
*
106+
* @param context The checksum context to check
107+
* @return true if checksum should be added to headers, false otherwise
90108
*/
91109
AWS_S3_API
92110
bool aws_s3_upload_request_checksum_context_should_add_header(
93111
const struct aws_s3_upload_request_checksum_context *context);
94112

95113
/**
96-
* Check if checksum should be added as trailer (chunked encoding)
114+
* Check if checksum should be added as trailer (chunked encoding).
115+
* Returns true if the context has a valid algorithm and the location is set to trailer.
116+
*
117+
* @param context The checksum context to check
118+
* @return true if checksum should be added as trailer, false otherwise
97119
*/
98120
AWS_S3_API
99121
bool aws_s3_upload_request_checksum_context_should_add_trailer(
100122
const struct aws_s3_upload_request_checksum_context *context);
101123

102124
/**
103125
* Get the checksum buffer to use for output.
104-
* Returns the user buffer if provided, otherwise the internal buffer.
126+
* Returns the internal buffer for storing the calculated checksum.
127+
*
128+
* @param context The checksum context
129+
* @return Pointer to the checksum buffer, or NULL if context is invalid
105130
*/
106131
AWS_S3_API
107132
struct aws_byte_buf *aws_s3_upload_request_checksum_context_get_output_buffer(
108133
struct aws_s3_upload_request_checksum_context *context);
109134

110135
/**
111-
* Validate that the checksum buffer size matches the expected size for the algorithm
112-
*/
113-
AWS_S3_API
114-
int aws_s3_upload_request_checksum_context_validate_buffer_size(
115-
const struct aws_s3_upload_request_checksum_context *context);
116-
117-
/**
118-
* Get a cursor to the current checksum value (for use in headers/trailers)
136+
* Get a cursor to the current checksum value (for use in headers/trailers).
137+
* Returns an empty cursor if the checksum has not been calculated yet.
138+
*
139+
* @param context The checksum context
140+
* @return Byte cursor to the calculated checksum, or empty cursor if not available
119141
*/
120142
AWS_S3_API
121143
struct aws_byte_cursor aws_s3_upload_request_checksum_context_get_checksum_cursor(

include/aws/s3/private/s3_checksums.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ AWS_S3_API
192192
int aws_checksum_finalize(struct aws_s3_checksum *checksum, struct aws_byte_buf *output);
193193

194194
AWS_S3_API
195-
int aws_aws_s3_meta_request_checksum_config_storage_init(
195+
int aws_s3_meta_request_checksum_config_storage_init(
196196
struct aws_allocator *allocator,
197197
struct aws_s3_meta_request_checksum_config_storage *internal_config,
198198
const struct aws_s3_checksum_config *config,
199199
const struct aws_http_message *message,
200200
const void *log_id);
201201

202202
AWS_S3_API
203-
void aws_aws_s3_meta_request_checksum_config_storage_cleanup(
203+
void aws_s3_meta_request_checksum_config_storage_cleanup(
204204
struct aws_s3_meta_request_checksum_config_storage *internal_config);
205205

206206
#endif /* AWS_S3_CHECKSUMS_H */

source/s3_auto_ranged_put.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,16 @@ static int s_process_part_info_synced(const struct aws_s3_part_info *info, void
155155

156156
if ((checksum_cur != NULL) && (checksum_cur->len > 0)) {
157157
/* Create checksum context with pre-calculated checksum */
158-
part->checksum_context = aws_s3_upload_request_checksum_context_new_with_exist_checksum(
158+
part->checksum_context = aws_s3_upload_request_checksum_context_new_with_existing_checksum(
159159
auto_ranged_put->base.allocator, &auto_ranged_put->base.checksum_config, *checksum_cur);
160160
} else {
161161
part->checksum_context = aws_s3_upload_request_checksum_context_new(
162162
auto_ranged_put->base.allocator, &auto_ranged_put->base.checksum_config);
163163
}
164-
164+
if (!part->checksum_context) {
165+
aws_mem_release(meta_request->allocator, part);
166+
return AWS_OP_ERR;
167+
}
165168
/* Parts might be out of order or have gaps in them.
166169
* Resize array-list to be long enough to hold this part,
167170
* filling any intermediate slots with NULL. */
@@ -1095,14 +1098,14 @@ static void s_s3_prepare_upload_part_on_read_done(void *user_data) {
10951098
(void *)meta_request);
10961099
goto on_done;
10971100
}
1101+
struct aws_s3_upload_request_checksum_context *context = previously_uploaded_info->checksum_context;
10981102
/* if previously uploaded part had a checksum, compare it to what we just skipped */
1099-
if (previously_uploaded_info->checksum_context != NULL &&
1100-
previously_uploaded_info->checksum_context->checksum_calculated == true &&
1103+
if (context != NULL && context->checksum_calculated == true &&
11011104
s_verify_part_matches_checksum(
11021105
meta_request->allocator,
11031106
aws_byte_cursor_from_buf(&request->request_body),
11041107
meta_request->checksum_config.checksum_algorithm,
1105-
aws_byte_cursor_from_buf(&previously_uploaded_info->checksum_context->base64_checksum))) {
1108+
aws_byte_cursor_from_buf(&context->base64_checksum))) {
11061109
error_code = aws_last_error_or_unknown();
11071110
goto on_done;
11081111
}

source/s3_checksum_context.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,27 @@ struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_co
5959
return context;
6060
}
6161

62-
struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_context_new_with_exist_checksum(
62+
struct aws_s3_upload_request_checksum_context *aws_s3_upload_request_checksum_context_new_with_existing_checksum(
6363
struct aws_allocator *allocator,
6464
const struct aws_s3_meta_request_checksum_config_storage *checksum_config,
65-
struct aws_byte_cursor exist_checksum) {
65+
struct aws_byte_cursor existing_checksum) {
6666
struct aws_s3_upload_request_checksum_context *context =
6767
s_s3_upload_request_checksum_context_new_base(allocator, checksum_config);
6868
if (context) {
6969
/* Initial the buffer for checksum from the exist checksum */
70-
if (context->encoded_checksum_size != exist_checksum.len) {
70+
if (context->encoded_checksum_size != existing_checksum.len) {
7171
struct aws_byte_cursor algo_name = aws_get_checksum_algorithm_name(context->algorithm);
7272
AWS_LOGF_ERROR(
7373
AWS_LS_S3_GENERAL,
7474
"Encoded checksum size mismatch during creating the context for algorithm " PRInSTR
7575
": expected %zu bytes, got %zu bytes",
7676
AWS_BYTE_CURSOR_PRI(algo_name),
7777
context->encoded_checksum_size,
78-
exist_checksum.len);
78+
existing_checksum.len);
7979
aws_s3_upload_request_checksum_context_release(context);
8080
return NULL;
8181
}
82-
aws_byte_buf_init_copy_from_cursor(&context->base64_checksum, allocator, exist_checksum);
82+
aws_byte_buf_init_copy_from_cursor(&context->base64_checksum, allocator, existing_checksum);
8383
context->checksum_calculated = true;
8484
}
8585
return context;

source/s3_checksums.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static int s_init_and_verify_checksum_config_from_headers(
394394
return AWS_OP_SUCCESS;
395395
}
396396

397-
int aws_aws_s3_meta_request_checksum_config_storage_init(
397+
int aws_s3_meta_request_checksum_config_storage_init(
398398
struct aws_allocator *allocator,
399399
struct aws_s3_meta_request_checksum_config_storage *internal_config,
400400
const struct aws_s3_checksum_config *config,
@@ -488,7 +488,7 @@ int aws_aws_s3_meta_request_checksum_config_storage_init(
488488
return AWS_OP_SUCCESS;
489489
}
490490

491-
void aws_aws_s3_meta_request_checksum_config_storage_cleanup(
491+
void aws_s3_meta_request_checksum_config_storage_cleanup(
492492
struct aws_s3_meta_request_checksum_config_storage *internal_config) {
493493
if (internal_config->has_full_object_checksum) {
494494
aws_byte_buf_clean_up(&internal_config->full_object_checksum);

source/s3_meta_request.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int aws_s3_meta_request_init_base(
228228

229229
*((size_t *)&meta_request->part_size) = part_size;
230230
*((bool *)&meta_request->should_compute_content_md5) = should_compute_content_md5;
231-
if (aws_aws_s3_meta_request_checksum_config_storage_init(
231+
if (aws_s3_meta_request_checksum_config_storage_init(
232232
meta_request->allocator,
233233
&meta_request->checksum_config,
234234
options->checksum_config,
@@ -500,7 +500,7 @@ static void s_s3_meta_request_destroy(void *user_data) {
500500
AWS_LOGF_DEBUG(AWS_LS_S3_META_REQUEST, "id=%p Cleaning up meta request", (void *)meta_request);
501501

502502
/* Clean up our initial http message */
503-
aws_aws_s3_meta_request_checksum_config_storage_cleanup(&meta_request->checksum_config);
503+
aws_s3_meta_request_checksum_config_storage_cleanup(&meta_request->checksum_config);
504504
meta_request->request_body_async_stream = aws_async_input_stream_release(meta_request->request_body_async_stream);
505505
meta_request->initial_request_message = aws_http_message_release(meta_request->initial_request_message);
506506

tests/s3_checksum_context_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int s_test_upload_request_checksum_context_get_checksum_cursor(struct aws
6464

6565
/* Test get checksum cursor with context that has calculated checksum */
6666
struct aws_byte_cursor existing_checksum = aws_byte_cursor_from_c_str("dGVzdA==");
67-
context = aws_s3_upload_request_checksum_context_new_with_exist_checksum(allocator, &config, existing_checksum);
67+
context = aws_s3_upload_request_checksum_context_new_with_existing_checksum(allocator, &config, existing_checksum);
6868
ASSERT_NOT_NULL(context);
6969

7070
cursor = aws_s3_upload_request_checksum_context_get_checksum_cursor(context);
@@ -98,7 +98,7 @@ static int s_test_upload_request_checksum_context_error_cases(struct aws_allocat
9898
/* Test creation with mismatched checksum size */
9999
struct aws_byte_cursor wrong_size_checksum = aws_byte_cursor_from_c_str("short");
100100
struct aws_s3_upload_request_checksum_context *context =
101-
aws_s3_upload_request_checksum_context_new_with_exist_checksum(allocator, &config, wrong_size_checksum);
101+
aws_s3_upload_request_checksum_context_new_with_existing_checksum(allocator, &config, wrong_size_checksum);
102102
ASSERT_NULL(context);
103103

104104
/* Test helper functions with NULL context */

0 commit comments

Comments
 (0)