in source/kms.c [308:350]
static int s_aws_byte_buf_to_base64_json(
struct aws_allocator *allocator,
struct json_object *obj,
const char *const key,
const struct aws_byte_buf *byte_buf) {
AWS_PRECONDITION(aws_allocator_is_valid(allocator));
AWS_PRECONDITION(obj);
AWS_PRECONDITION(aws_c_string_is_valid(key));
AWS_PRECONDITION(aws_byte_buf_is_valid(byte_buf));
size_t needed_capacity = 0;
if (aws_base64_compute_encoded_len(byte_buf->len, &needed_capacity) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
struct aws_byte_buf buf;
if (aws_byte_buf_init(&buf, allocator, needed_capacity + 1) != AWS_OP_SUCCESS) {
return AWS_OP_ERR;
}
struct aws_byte_cursor cursor = aws_byte_cursor_from_buf(byte_buf);
if (aws_base64_encode(&cursor, &buf) != AWS_OP_SUCCESS) {
goto clean_up;
}
if (aws_byte_buf_append_null_terminator(&buf) != AWS_OP_SUCCESS) {
goto clean_up;
}
if (s_string_to_json(obj, key, (const char *)buf.buffer) != AWS_OP_SUCCESS) {
goto clean_up;
}
aws_byte_buf_clean_up_secure(&buf);
return AWS_OP_SUCCESS;
clean_up:
aws_byte_buf_clean_up_secure(&buf);
return AWS_OP_ERR;
}