Skip to content

tests: improve coverage for s2n_stream_cipher_null #5268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions tests/unit/s2n_stream_cipher_null_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_blob_init(&in, array, 9));
struct s2n_blob out = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&out, array, 9));
EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(NULL, &in, &out));
struct s2n_session_key session_key = { 0 };
EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
};

/* Test that in size > out size fails */
Expand All @@ -40,7 +41,8 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_blob_init(&in, array, 9));
struct s2n_blob out = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&out, array, 8));
EXPECT_FAILURE(s2n_stream_cipher_null_endecrypt(NULL, &in, &out));
struct s2n_session_key session_key = { 0 };
EXPECT_FAILURE(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
};

/* Test that in is copied to out when they are different */
Expand All @@ -52,9 +54,34 @@ int main(int argc, char **argv)
struct s2n_blob out = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&out, out_array, 9));
EXPECT_BYTEARRAY_NOT_EQUAL(in_array, out_array, out.size);
EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(NULL, &in, &out));
struct s2n_session_key session_key = { 0 };
EXPECT_SUCCESS(s2n_stream_cipher_null_endecrypt(&session_key, &in, &out));
EXPECT_BYTEARRAY_EQUAL(in_array, out_array, out.size);
};

/* Test that null cipher is always available */
{
EXPECT_TRUE(s2n_stream_cipher_null_available());
};

/* Test that get_key always returns success */
{
struct s2n_blob in = { 0 };
struct s2n_session_key session_key = { 0 };
EXPECT_OK(s2n_stream_cipher_null_get_key(&session_key, &in));
};

/* Test that destroy_key always returns success */
{
struct s2n_session_key session_key = { 0 };
EXPECT_OK(s2n_stream_cipher_null_destroy_key(&session_key));
};

/* Test that init always returns success */
{
struct s2n_session_key session_key = { 0 };
EXPECT_OK(s2n_stream_cipher_null_init(&session_key));
};

END_TEST();
}
Loading