| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include "aws/s3/private/s3_checksums.h" |
| 6 |
#include <aws/testing/aws_test_harness.h> |
| 7 |
|
| 8 |
typedef struct aws_s3_checksum *aws_checksum_new_fn( |
| 9 |
struct aws_allocator *allocator, |
| 10 |
enum aws_s3_checksum_algorithm algorithm); |
| 11 |
|
| 12 |
static inline int s_verify_checksum_test_case( |
| 13 |
struct aws_allocator *allocator, |
| 14 |
struct aws_byte_cursor *input, |
| 15 |
struct aws_byte_cursor *expected, |
| 16 |
aws_checksum_new_fn *new_fn, |
| 17 |
enum aws_s3_checksum_algorithm algorithm) { |
| 18 |
|
| 19 |
aws_s3_library_init(allocator); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
for (size_t i = 1; i < input->len; ++i) { |
| 24 |
uint8_t output[128] = {0}; |
| 25 |
struct aws_byte_buf output_buf = aws_byte_buf_from_array(output, expected->len); |
| 26 |
output_buf.len = 0; |
| 27 |
|
| 28 |
struct aws_s3_checksum *checksum = new_fn(allocator, algorithm); |
| 29 |
ASSERT_NOT_NULL(checksum); |
| 30 |
|
| 31 |
struct aws_byte_cursor input_cpy = *input; |
| 32 |
|
| 33 |
while (input_cpy.len) { |
| 34 |
size_t max_advance = input_cpy.len > i ? i : input_cpy.len; |
| 35 |
struct aws_byte_cursor segment = aws_byte_cursor_from_array(input_cpy.ptr, max_advance); |
| 36 |
ASSERT_SUCCESS(aws_checksum_update(checksum, &segment)); |
| 37 |
aws_byte_cursor_advance(&input_cpy, max_advance); |
| 38 |
} |
| 39 |
|
| 40 |
ASSERT_SUCCESS(aws_checksum_finalize(checksum, &output_buf)); |
| 41 |
ASSERT_BIN_ARRAYS_EQUALS(expected->ptr, expected->len, output_buf.buffer, output_buf.len); |
| 42 |
|
| 43 |
aws_checksum_destroy(checksum); |
| 44 |
} |
| 45 |
|
| 46 |
aws_s3_library_clean_up(); |
| 47 |
|
| 48 |
return AWS_OP_SUCCESS; |
| 49 |
} |