in source/kms.c [361:391]
static int s_aws_byte_buf_from_base64_json(
struct aws_allocator *allocator,
struct json_object *obj,
struct aws_byte_buf *byte_buf) {
AWS_PRECONDITION(aws_allocator_is_valid(allocator));
AWS_PRECONDITION(obj);
AWS_PRECONDITION(byte_buf);
const char *str = json_object_get_string(obj);
if (str == NULL) {
return AWS_OP_ERR;
}
size_t needed_capacity = 0;
struct aws_byte_cursor cursor = aws_byte_cursor_from_c_str(str);
if (aws_base64_compute_decoded_len(&cursor, &needed_capacity) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
if (aws_byte_buf_init(byte_buf, allocator, needed_capacity) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
if (aws_base64_decode(&cursor, byte_buf) != AWS_OP_SUCCESS) {
aws_byte_buf_clean_up_secure(byte_buf);
return AWS_OP_ERR;
}
return AWS_OP_SUCCESS;
}