bool aws_cryptosdk_frame_is_valid()

in source/framefmt.c [224:247]


bool aws_cryptosdk_frame_is_valid(const struct aws_cryptosdk_frame *const frame) {
    if (frame == NULL) {
        return false;
    }

    bool frame_type_valid = aws_cryptosdk_frame_has_valid_type(frame);

    bool iv_byte_buf_valid  = aws_byte_buf_is_valid(&frame->iv);
    bool iv_byte_buf_static = frame->iv.allocator == NULL;

    bool authtag_byte_buf_valid  = aws_byte_buf_is_valid(&frame->authtag);
    bool authtag_byte_buf_static = frame->authtag.allocator == NULL;

    bool ciphertext_byte_buf_valid = aws_byte_buf_is_valid(&frame->ciphertext);
    /* This happens when input plaintext size is 0 */
    bool ciphertext_valid_zero =
        frame->ciphertext.len == 0 && frame->ciphertext.buffer && frame->ciphertext.capacity == 0;
    bool ciphertext_valid  = ciphertext_byte_buf_valid || ciphertext_valid_zero;
    bool ciphertext_static = frame->ciphertext.allocator == NULL;

    return (
        authtag_byte_buf_static && authtag_byte_buf_valid && ciphertext_static && ciphertext_valid &&
        frame_type_valid && iv_byte_buf_static && iv_byte_buf_valid);
}