| 1 | #ifndef AWS_AUTH_SIGNING_RESULT_H |
| 2 | #define AWS_AUTH_SIGNING_RESULT_H |
| 3 | |
| 4 | /** |
| 5 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | * SPDX-License-Identifier: Apache-2.0. |
| 7 | */ |
| 8 | |
| 9 | #include <aws/auth/auth.h> |
| 10 | |
| 11 | #include <aws/common/hash_table.h> |
| 12 | |
| 13 | AWS_PUSH_SANE_WARNING_LEVEL |
| 14 | |
| 15 | struct aws_array_list; |
| 16 | struct aws_byte_cursor; |
| 17 | struct aws_http_message; |
| 18 | struct aws_string; |
| 19 | |
| 20 | struct aws_signing_result_property { |
| 21 | struct aws_string *name; |
| 22 | struct aws_string *value; |
| 23 | }; |
| 24 | |
| 25 | /** |
| 26 | * A structure for tracking all the signer-requested changes to a signable. Interpreting |
| 27 | * these changes is signing-algorithm specific. |
| 28 | * |
| 29 | * A signing result consists of |
| 30 | * |
| 31 | * (1) Properties - A set of key-value pairs |
| 32 | * (2) Property Lists - A set of named key-value pair lists |
| 33 | * |
| 34 | * The hope is that these two generic structures are enough to model the changes required |
| 35 | * by any generic message-signing algorithm. |
| 36 | * |
| 37 | * Note that the key-value pairs of a signing_result are different types (but same intent) as |
| 38 | * the key-value pairs in the signable interface. This is because the signing result stands alone |
| 39 | * and owns its own copies of all values, whereas a signable can wrap an existing object and thus |
| 40 | * use non-owning references (like byte cursors) if appropriate to its implementation. |
| 41 | */ |
| 42 | struct aws_signing_result { |
| 43 | struct aws_allocator *allocator; |
| 44 | struct aws_hash_table properties; |
| 45 | struct aws_hash_table property_lists; |
| 46 | }; |
| 47 | |
| 48 | AWS_EXTERN_C_BEGIN |
| 49 | |
| 50 | /** |
| 51 | * Initialize a signing result to its starting state |
| 52 | * |
| 53 | * @param result signing result to initialize |
| 54 | * @param allocator allocator to use for all memory allocation |
| 55 | * |
| 56 | * @return AWS_OP_SUCCESS if initialization was successful, AWS_OP_ERR otherwise |
| 57 | */ |
| 58 | AWS_AUTH_API |
| 59 | int aws_signing_result_init(struct aws_signing_result *result, struct aws_allocator *allocator); |
| 60 | |
| 61 | /** |
| 62 | * Clean up all resources held by the signing result |
| 63 | * |
| 64 | * @param result signing result to clean up resources for |
| 65 | */ |
| 66 | AWS_AUTH_API |
| 67 | void aws_signing_result_clean_up(struct aws_signing_result *result); |
| 68 | |
| 69 | /** |
| 70 | * Sets the value of a property on a signing result |
| 71 | * |
| 72 | * @param result signing result to modify |
| 73 | * @param property_name name of the property to set |
| 74 | * @param property_value value that the property should assume |
| 75 | * |
| 76 | * @return AWS_OP_SUCCESS if the set was successful, AWS_OP_ERR otherwise |
| 77 | */ |
| 78 | AWS_AUTH_API |
| 79 | int aws_signing_result_set_property( |
| 80 | struct aws_signing_result *result, |
| 81 | const struct aws_string *property_name, |
| 82 | const struct aws_byte_cursor *property_value); |
| 83 | |
| 84 | /** |
| 85 | * Gets the value of a property on a signing result |
| 86 | * |
| 87 | * @param result signing result to query from |
| 88 | * @param property_name name of the property to query the value of |
| 89 | * @param out_property_value output parameter for the property value |
| 90 | * |
| 91 | * @return AWS_OP_SUCCESS if the get was successful, AWS_OP_ERR otherwise |
| 92 | */ |
| 93 | AWS_AUTH_API |
| 94 | int aws_signing_result_get_property( |
| 95 | const struct aws_signing_result *result, |
| 96 | const struct aws_string *property_name, |
| 97 | struct aws_string **out_property_value); |
| 98 | |
| 99 | /** |
| 100 | * Adds a key-value pair to a named property list. If the named list does not yet exist, it will be created as |
| 101 | * an empty list before the pair is added. No uniqueness checks are made against existing pairs. |
| 102 | * |
| 103 | * @param result signing result to modify |
| 104 | * @param list_name name of the list to add the property key-value pair to |
| 105 | * @param property_name key value of the key-value pair to append |
| 106 | * @param property_value property value of the key-value pair to append |
| 107 | * |
| 108 | * @return AWS_OP_SUCCESS if the operation was successful, AWS_OP_ERR otherwise |
| 109 | */ |
| 110 | AWS_AUTH_API |
| 111 | int aws_signing_result_append_property_list( |
| 112 | struct aws_signing_result *result, |
| 113 | const struct aws_string *list_name, |
| 114 | const struct aws_byte_cursor *property_name, |
| 115 | const struct aws_byte_cursor *property_value); |
| 116 | |
| 117 | /** |
| 118 | * Gets a named property list on the signing result. If the list does not exist, *out_list will be set to null |
| 119 | * |
| 120 | * @param result signing result to query |
| 121 | * @param list_name name of the list of key-value pairs to get |
| 122 | * @param out_list output parameter for the list of key-value pairs |
| 123 | * |
| 124 | */ |
| 125 | AWS_AUTH_API |
| 126 | void aws_signing_result_get_property_list( |
| 127 | const struct aws_signing_result *result, |
| 128 | const struct aws_string *list_name, |
| 129 | struct aws_array_list **out_list); |
| 130 | |
| 131 | /** |
| 132 | * Looks for a property within a named property list on the signing result. If the list does not exist, or the property |
| 133 | * does not exist within the list, *out_value will be set to NULL. |
| 134 | * |
| 135 | * @param result signing result to query |
| 136 | * @param list_name name of the list of key-value pairs to search through for the property |
| 137 | * @param property_name name of the property to search for within the list |
| 138 | * @param out_value output parameter for the property value, if found |
| 139 | * |
| 140 | */ |
| 141 | AWS_AUTH_API |
| 142 | void aws_signing_result_get_property_value_in_property_list( |
| 143 | const struct aws_signing_result *result, |
| 144 | const struct aws_string *list_name, |
| 145 | const struct aws_string *property_name, |
| 146 | struct aws_string **out_value); |
| 147 | |
| 148 | /* |
| 149 | * Specific implementation that applies a signing result to a mutable http request |
| 150 | * |
| 151 | * @param request http request to apply the signing result to |
| 152 | * @param allocator memory allocator to use for all memory allocation |
| 153 | * @param result signing result to apply to the request |
| 154 | * |
| 155 | * @return AWS_OP_SUCCESS if the application operation was successful, AWS_OP_ERR otherwise |
| 156 | */ |
| 157 | AWS_AUTH_API |
| 158 | int aws_apply_signing_result_to_http_request( |
| 159 | struct aws_http_message *request, |
| 160 | struct aws_allocator *allocator, |
| 161 | const struct aws_signing_result *result); |
| 162 | |
| 163 | AWS_AUTH_API extern const struct aws_string *g_aws_signing_authorization_header_name; |
| 164 | AWS_AUTH_API extern const struct aws_string *g_aws_signing_authorization_query_param_name; |
| 165 | |
| 166 | AWS_EXTERN_C_END |
| 167 | AWS_POP_SANE_WARNING_LEVEL |
| 168 | |
| 169 | #endif /* AWS_AUTH_SIGNING_RESULT_H */ |