From 31ea4d121379f050dfd1bf9cb0864d9c033ffa20 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 12 Mar 2026 15:19:56 +0100 Subject: [PATCH] tests: Negative tests for ssh_pki_ctx_options_set Signed-off-by: Jakub Jelen Reviewed-by: Eshan Kelkar --- tests/unittests/torture_pki_rsa.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/unittests/torture_pki_rsa.c b/tests/unittests/torture_pki_rsa.c index 2fd323d7..c405bb44 100644 --- a/tests/unittests/torture_pki_rsa.c +++ b/tests/unittests/torture_pki_rsa.c @@ -754,12 +754,11 @@ static void torture_pki_rsa_sha2(void **state) static void torture_pki_rsa_key_size(void **state) { - int rc; + int rc, bit_size; ssh_key key = NULL, pubkey = NULL; ssh_signature sign = NULL; ssh_session session=ssh_new(); unsigned int length = 4096; - int bit_size = 2048; ssh_pki_ctx ctx = NULL; (void)state; @@ -767,6 +766,17 @@ static void torture_pki_rsa_key_size(void **state) ctx = ssh_pki_ctx_new(); assert_non_null(ctx); + /* Invalid argument NULL */ + rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, NULL); + assert_ssh_return_code_equal(session, rc, SSH_ERROR); + + /* Too small size */ + bit_size = 768; + rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size); + assert_ssh_return_code_equal(session, rc, SSH_ERROR); + + /* Ok value */ + bit_size = 2048; rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size); assert_return_code(rc, errno);