Skip to content

Commit

Permalink
Split empty buf and null buf checks into separate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
desvxx committed Aug 28, 2024
1 parent 1fb7993 commit f9b4840
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/tests/ffi-enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,14 @@ TEST_F(rnp_tests, test_ffi_encrypt_set_cipher)
rnp_ffi_destroy(ffi);
}

TEST_F(rnp_tests, test_ffi_encrypt_set_cipher_empty_buffer)
TEST_F(rnp_tests, test_ffi_encrypt_empty_buffer)
{
/* setup FFI */
rnp_ffi_t ffi = NULL;
assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG"));
/* create input + output */
rnp_input_t input = NULL;
const char *plaintext = "";
assert_rnp_success(rnp_input_from_memory(&input, NULL, 0, false));
assert_rnp_success(rnp_input_destroy(input));
assert_rnp_success(
rnp_input_from_memory(&input, (const uint8_t *) plaintext, strlen(plaintext), false));
rnp_output_t output = NULL;
Expand Down Expand Up @@ -552,6 +550,41 @@ TEST_F(rnp_tests, test_ffi_encrypt_set_cipher_empty_buffer)
rnp_ffi_destroy(ffi);
}

TEST_F(rnp_tests, test_ffi_encrypt_null_buffer)
{
/* setup FFI */
rnp_ffi_t ffi = NULL;
assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG"));
/* create input + output */
rnp_input_t input = NULL;
assert_rnp_success(rnp_input_from_memory(&input, NULL, 0, false));
rnp_output_t output = NULL;
assert_rnp_success(rnp_output_to_path(&output, "encrypted"));
/* create encrypt operation */
rnp_op_encrypt_t op = NULL;
assert_rnp_success(rnp_op_encrypt_create(&op, ffi, input, output));
assert_rnp_success(rnp_op_encrypt_add_password(op, "password1", NULL, 0, "AES192"));
/* execute the operation */
assert_rnp_success(rnp_op_encrypt_execute(op));
assert_true(rnp_file_exists("encrypted"));
/* cleanup */
assert_rnp_success(rnp_input_destroy(input));
assert_rnp_success(rnp_output_destroy(output));
assert_rnp_success(rnp_op_encrypt_destroy(op));
/* decrypt with password1 */
assert_rnp_success(rnp_input_from_path(&input, "encrypted"));
assert_rnp_success(rnp_output_to_path(&output, "decrypted"));
assert_rnp_success(
rnp_ffi_set_pass_provider(ffi, ffi_string_password_provider, (void *) "password1"));
rnp_input_destroy(input);
rnp_output_destroy(output);
assert_string_equal(file_to_str("decrypted").c_str(), "");
unlink("decrypted");
unlink("encrypted");

rnp_ffi_destroy(ffi);
}

TEST_F(rnp_tests, test_ffi_encrypt_pk)
{
rnp_ffi_t ffi = NULL;
Expand Down

0 comments on commit f9b4840

Please sign in to comment.