| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/auth/signable.h> |
| 7 |
#include <aws/common/string.h> |
| 8 |
#include <aws/io/stream.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
struct aws_signable_chunk_impl { |
| 14 |
struct aws_input_stream *chunk_data; |
| 15 |
struct aws_string *previous_signature; |
| 16 |
}; |
| 17 |
|
| 18 |
static int s_aws_signable_chunk_get_property( |
| 19 |
const struct aws_signable *signable, |
| 20 |
const struct aws_string *name, |
| 21 |
struct aws_byte_cursor *out_value) { |
| 22 |
|
| 23 |
struct aws_signable_chunk_impl *impl = signable->impl; |
| 24 |
|
| 25 |
AWS_ZERO_STRUCT(*out_value); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
if (aws_string_eq(name, g_aws_previous_signature_property_name)) { |
| 31 |
*out_value = aws_byte_cursor_from_string(impl->previous_signature); |
| 32 |
} else { |
| 33 |
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); |
| 34 |
} |
| 35 |
|
| 36 |
return AWS_OP_SUCCESS; |
| 37 |
} |
| 38 |
|
| 39 |
static int s_aws_signable_chunk_get_property_list( |
| 40 |
const struct aws_signable *signable, |
| 41 |
const struct aws_string *name, |
| 42 |
struct aws_array_list **out_list) { |
| 43 |
(void)signable; |
| 44 |
(void)name; |
| 45 |
(void)out_list; |
| 46 |
|
| 47 |
return aws_raise_error(AWS_ERROR_UNSUPPORTED_OPERATION); |
| 48 |
} |
| 49 |
|
| 50 |
static int s_aws_signable_chunk_get_payload_stream( |
| 51 |
const struct aws_signable *signable, |
| 52 |
struct aws_input_stream **out_input_stream) { |
| 53 |
|
| 54 |
struct aws_signable_chunk_impl *impl = signable->impl; |
| 55 |
*out_input_stream = impl->chunk_data; |
| 56 |
|
| 57 |
return AWS_OP_SUCCESS; |
| 58 |
} |
| 59 |
|
| 60 |
static void s_aws_signable_chunk_destroy(struct aws_signable *signable) { |
| 61 |
if (signable == NULL) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
struct aws_signable_chunk_impl *impl = signable->impl; |
| 66 |
if (impl == NULL) { |
| 67 |
return; |
| 68 |
} |
| 69 |
aws_input_stream_release(impl->chunk_data); |
| 70 |
aws_string_destroy(impl->previous_signature); |
| 71 |
|
| 72 |
aws_mem_release(signable->allocator, signable); |
| 73 |
} |
| 74 |
|
| 75 |
static struct aws_signable_vtable s_signable_chunk_vtable = { |
| 76 |
.get_property = s_aws_signable_chunk_get_property, |
| 77 |
.get_property_list = s_aws_signable_chunk_get_property_list, |
| 78 |
.get_payload_stream = s_aws_signable_chunk_get_payload_stream, |
| 79 |
.destroy = s_aws_signable_chunk_destroy, |
| 80 |
}; |
| 81 |
|
| 82 |
struct aws_signable *aws_signable_new_chunk( |
| 83 |
struct aws_allocator *allocator, |
| 84 |
struct aws_input_stream *chunk_data, |
| 85 |
struct aws_byte_cursor previous_signature) { |
| 86 |
|
| 87 |
struct aws_signable *signable = NULL; |
| 88 |
struct aws_signable_chunk_impl *impl = NULL; |
| 89 |
aws_mem_acquire_many( |
| 90 |
allocator, 2, &signable, sizeof(struct aws_signable), &impl, sizeof(struct aws_signable_chunk_impl)); |
| 91 |
|
| 92 |
if (signable == NULL || impl == NULL) { |
| 93 |
return NULL; |
| 94 |
} |
| 95 |
|
| 96 |
AWS_ZERO_STRUCT(*signable); |
| 97 |
AWS_ZERO_STRUCT(*impl); |
| 98 |
|
| 99 |
signable->allocator = allocator; |
| 100 |
signable->vtable = &s_signable_chunk_vtable; |
| 101 |
signable->impl = impl; |
| 102 |
|
| 103 |
impl->chunk_data = aws_input_stream_acquire(chunk_data); |
| 104 |
impl->previous_signature = aws_string_new_from_array(allocator, previous_signature.ptr, previous_signature.len); |
| 105 |
if (impl->previous_signature == NULL) { |
| 106 |
goto on_error; |
| 107 |
} |
| 108 |
|
| 109 |
return signable; |
| 110 |
|
| 111 |
on_error: |
| 112 |
|
| 113 |
aws_signable_destroy(signable); |
| 114 |
|
| 115 |
return NULL; |
| 116 |
} |