tests: Prefer assert_non_null over assert_true
This also replaces some occurrences of assert_true with assert_null. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
89f58decb6
Коммит
603b6d7222
@ -126,12 +126,12 @@ static void torture_knownhosts_port(void **state) {
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
file = fopen(known_hosts_file, "r");
|
||||
assert_true(file != NULL);
|
||||
assert_non_null(file);
|
||||
p = fgets(buffer, sizeof(buffer), file);
|
||||
assert_false(p == NULL);
|
||||
fclose(file);
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
assert_true(strstr(buffer,"[127.0.0.10]:1234 ") != NULL);
|
||||
assert_non_null(strstr(buffer,"[127.0.0.10]:1234 "));
|
||||
|
||||
ssh_disconnect(session);
|
||||
ssh_free(session);
|
||||
@ -291,7 +291,7 @@ static void torture_knownhosts_conflict(void **state) {
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
file = fopen(known_hosts_file, "w");
|
||||
assert_true(file != NULL);
|
||||
assert_non_null(file);
|
||||
fprintf(file, "127.0.0.10 ssh-rsa %s\n", BADRSA);
|
||||
fprintf(file, "127.0.0.10 ssh-ed25519 %s\n", BADED25519);
|
||||
fclose(file);
|
||||
|
@ -191,14 +191,14 @@ static void torture_ssh_buffer_get_format(void **state) {
|
||||
assert_true(d == 0xbadc0de);
|
||||
assert_true(q == 0x13243546acbdcedf);
|
||||
|
||||
assert_true(s != NULL);
|
||||
assert_non_null(s);
|
||||
assert_int_equal(ssh_string_len(s), 6);
|
||||
assert_memory_equal(ssh_string_data(s), "libssh", 6);
|
||||
|
||||
assert_true(s1 != NULL);
|
||||
assert_non_null(s1);
|
||||
assert_string_equal(s1, "rocks");
|
||||
|
||||
assert_true(s2 != NULL);
|
||||
assert_non_null(s2);
|
||||
assert_memory_equal(s2, "So much", 7);
|
||||
|
||||
len = ssh_buffer_get_len(buffer);
|
||||
@ -228,9 +228,9 @@ static void torture_ssh_buffer_get_format_error(void **state) {
|
||||
rc = ssh_buffer_unpack(buffer, "bwdqSsPb",&b,&w,&d,&q,&s,&s1,(size_t)7,&s2,&b);
|
||||
assert_int_equal(rc, SSH_ERROR);
|
||||
|
||||
assert_true(s==NULL);
|
||||
assert_true(s1 == NULL);
|
||||
assert_true(s2 == NULL);
|
||||
assert_null(s);
|
||||
assert_null(s1);
|
||||
assert_null(s2);
|
||||
}
|
||||
|
||||
static void torture_buffer_pack_badformat(void **state){
|
||||
|
@ -17,7 +17,7 @@ static int setup_rsa_key(void **state)
|
||||
const char *q;
|
||||
|
||||
b64_key = strdup(torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
||||
assert_true(b64_key != NULL);
|
||||
assert_non_null(b64_key);
|
||||
|
||||
q = p = b64_key;
|
||||
while (p != NULL && *p != '\0' && *p != ' ') p++;
|
||||
|
@ -170,7 +170,7 @@ static void torture_pubkey_generate_from_privkey(void **state) {
|
||||
rc = ssh_try_publickey_from_file(session, LIBSSH_RSA_TESTKEY, &pubkey_orig,
|
||||
&type_orig);
|
||||
assert_true(rc == 0);
|
||||
assert_true(pubkey_orig != NULL);
|
||||
assert_non_null(pubkey_orig);
|
||||
|
||||
rc = torture_read_one_line(LIBSSH_RSA_TESTKEY ".pub", pubkey_line_orig,
|
||||
sizeof(pubkey_line_orig));
|
||||
@ -180,17 +180,17 @@ static void torture_pubkey_generate_from_privkey(void **state) {
|
||||
unlink(LIBSSH_RSA_TESTKEY ".pub");
|
||||
|
||||
privkey = privatekey_from_file(session, LIBSSH_RSA_TESTKEY, 0, NULL);
|
||||
assert_true(privkey != NULL);
|
||||
assert_non_null(privkey);
|
||||
|
||||
pubkey = publickey_from_privatekey(privkey);
|
||||
assert_true(pubkey != NULL);
|
||||
assert_non_null(pubkey);
|
||||
type_new = privkey->type;
|
||||
privatekey_free(privkey);
|
||||
|
||||
pubkey_new = publickey_to_string(pubkey);
|
||||
publickey_free(pubkey);
|
||||
|
||||
assert_true(pubkey_new != NULL);
|
||||
assert_non_null(pubkey_new);
|
||||
|
||||
assert_true(ssh_string_len(pubkey_orig) == ssh_string_len(pubkey_new));
|
||||
assert_memory_equal(ssh_string_data(pubkey_orig),
|
||||
@ -228,7 +228,7 @@ static void torture_privatekey_from_file(void **state) {
|
||||
ssh_private_key key = NULL;
|
||||
|
||||
key = privatekey_from_file(session, LIBSSH_RSA_TESTKEY, SSH_KEYTYPE_RSA, NULL);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -236,7 +236,7 @@ static void torture_privatekey_from_file(void **state) {
|
||||
|
||||
#ifdef HAVE_DSA
|
||||
key = privatekey_from_file(session, LIBSSH_DSA_TESTKEY, SSH_KEYTYPE_DSS, NULL);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -245,7 +245,7 @@ static void torture_privatekey_from_file(void **state) {
|
||||
|
||||
/* Test the automatic type discovery */
|
||||
key = privatekey_from_file(session, LIBSSH_RSA_TESTKEY, 0, NULL);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -253,7 +253,7 @@ static void torture_privatekey_from_file(void **state) {
|
||||
|
||||
#ifdef HAVE_DSA
|
||||
key = privatekey_from_file(session, LIBSSH_DSA_TESTKEY, 0, NULL);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -269,7 +269,7 @@ static void torture_privatekey_from_file_passphrase(void **state) {
|
||||
ssh_private_key key = NULL;
|
||||
|
||||
key = privatekey_from_file(session, LIBSSH_RSA_TESTKEY, SSH_KEYTYPE_RSA, TORTURE_TESTKEY_PASSWORD);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -277,7 +277,7 @@ static void torture_privatekey_from_file_passphrase(void **state) {
|
||||
|
||||
#ifdef HAVE_DSA
|
||||
key = privatekey_from_file(session, LIBSSH_DSA_TESTKEY, SSH_KEYTYPE_DSS, TORTURE_TESTKEY_PASSWORD);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -286,7 +286,7 @@ static void torture_privatekey_from_file_passphrase(void **state) {
|
||||
|
||||
/* Test the automatic type discovery */
|
||||
key = privatekey_from_file(session, LIBSSH_RSA_TESTKEY, 0, TORTURE_TESTKEY_PASSWORD);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
@ -294,7 +294,7 @@ static void torture_privatekey_from_file_passphrase(void **state) {
|
||||
|
||||
#ifdef HAVE_DSA
|
||||
key = privatekey_from_file(session, LIBSSH_DSA_TESTKEY, 0, TORTURE_TESTKEY_PASSWORD);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
if (key != NULL) {
|
||||
privatekey_free(key);
|
||||
key = NULL;
|
||||
|
@ -13,9 +13,9 @@ static void torture_ssh_list_new(void **state) {
|
||||
|
||||
xlist = ssh_list_new();
|
||||
|
||||
assert_true(xlist != NULL);
|
||||
assert_true(xlist->root == NULL);
|
||||
assert_true(xlist->end == NULL);
|
||||
assert_non_null(xlist);
|
||||
assert_null(xlist->root);
|
||||
assert_null(xlist->end);
|
||||
|
||||
assert_int_equal(ssh_list_count(xlist), 0);
|
||||
|
||||
@ -29,7 +29,7 @@ static void torture_ssh_list_append(void **state) {
|
||||
(void) state;
|
||||
|
||||
xlist = ssh_list_new();
|
||||
assert_true(xlist != NULL);
|
||||
assert_non_null(xlist);
|
||||
|
||||
rc = ssh_list_append(xlist, "item1");
|
||||
assert_true(rc == 0);
|
||||
@ -60,7 +60,7 @@ static void torture_ssh_list_prepend(void **state) {
|
||||
(void) state;
|
||||
|
||||
xlist = ssh_list_new();
|
||||
assert_true(xlist != NULL);
|
||||
assert_non_null(xlist);
|
||||
|
||||
rc = ssh_list_prepend(xlist, "item1");
|
||||
assert_true(rc == 0);
|
||||
|
@ -58,11 +58,11 @@ static void torture_basename(void **state) {
|
||||
(void) state;
|
||||
|
||||
path=ssh_basename(TORTURE_TEST_DIR "/test");
|
||||
assert_true(path != NULL);
|
||||
assert_non_null(path);
|
||||
assert_string_equal(path, "test");
|
||||
SAFE_FREE(path);
|
||||
path=ssh_basename(TORTURE_TEST_DIR "/test/");
|
||||
assert_true(path != NULL);
|
||||
assert_non_null(path);
|
||||
assert_string_equal(path, "test");
|
||||
SAFE_FREE(path);
|
||||
}
|
||||
@ -73,11 +73,11 @@ static void torture_dirname(void **state) {
|
||||
(void) state;
|
||||
|
||||
path=ssh_dirname(TORTURE_TEST_DIR "/test");
|
||||
assert_true(path != NULL);
|
||||
assert_non_null(path);
|
||||
assert_string_equal(path, TORTURE_TEST_DIR );
|
||||
SAFE_FREE(path);
|
||||
path=ssh_dirname(TORTURE_TEST_DIR "/test/");
|
||||
assert_true(path != NULL);
|
||||
assert_non_null(path);
|
||||
assert_string_equal(path, TORTURE_TEST_DIR);
|
||||
SAFE_FREE(path);
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ static void torture_options_set_knownhosts(void **state)
|
||||
/* ssh_options_apply() should set the path to correct value */
|
||||
rc = ssh_options_apply(session);
|
||||
assert_ssh_return_code(session, rc);
|
||||
assert_true(session->opts.knownhosts != NULL);
|
||||
assert_non_null(session->opts.knownhosts);
|
||||
}
|
||||
|
||||
static void torture_options_get_knownhosts(void **state)
|
||||
|
@ -29,10 +29,10 @@ static void torture_pki_keytype(void **state) {
|
||||
assert_true(type == SSH_KEYTYPE_UNKNOWN);
|
||||
|
||||
type_c = ssh_key_type_to_char(SSH_KEYTYPE_UNKNOWN);
|
||||
assert_true(type_c == NULL);
|
||||
assert_null(type_c);
|
||||
|
||||
type_c = ssh_key_type_to_char(42);
|
||||
assert_true(type_c == NULL);
|
||||
assert_null(type_c);
|
||||
}
|
||||
|
||||
static void torture_pki_signature(void **state)
|
||||
@ -42,7 +42,7 @@ static void torture_pki_signature(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
sig = ssh_signature_new();
|
||||
assert_true(sig != NULL);
|
||||
assert_non_null(sig);
|
||||
|
||||
ssh_signature_free(sig);
|
||||
}
|
||||
@ -134,7 +134,7 @@ static void torture_pki_verify_mismatch(void **state)
|
||||
}
|
||||
rc = ssh_pki_generate(sig_type, key_sizes[sig_type], &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
assert_int_equal(key->type, sig_type);
|
||||
assert_string_equal(key->type_c, key_types[sig_type]);
|
||||
|
||||
@ -149,7 +149,7 @@ static void torture_pki_verify_mismatch(void **state)
|
||||
|
||||
/* Create a valid signature using this key */
|
||||
sign = pki_do_sign_hash(key, HASH, hash_length, hash);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
assert_int_equal(sign->type, key->type);
|
||||
if (hash == SSH_DIGEST_AUTO) {
|
||||
assert_string_equal(sign->type_c, key->type_c);
|
||||
@ -196,7 +196,7 @@ static void torture_pki_verify_mismatch(void **state)
|
||||
|
||||
rc = ssh_pki_generate(key_type, key_sizes[key_type], &verify_key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(verify_key != NULL);
|
||||
assert_non_null(verify_key);
|
||||
|
||||
/* Should gracefully fail, but not crash */
|
||||
rc = pki_signature_verify(session,
|
||||
@ -220,10 +220,10 @@ static void torture_pki_verify_mismatch(void **state)
|
||||
sig_type,
|
||||
import_sig->hash_type);
|
||||
if (sig_type != key_type) {
|
||||
assert_true(new_sig == NULL);
|
||||
assert_null(new_sig);
|
||||
} else {
|
||||
/* Importing with the same key type should work */
|
||||
assert_true(new_sig != NULL);
|
||||
assert_non_null(new_sig);
|
||||
assert_int_equal(new_sig->type, key->type);
|
||||
if (key_type == SSH_KEYTYPE_RSA && new_sig->hash_type != SSH_DIGEST_AUTO) {
|
||||
assert_string_equal(new_sig->type_c, hash_signatures[new_sig->hash_type]);
|
||||
|
@ -335,7 +335,7 @@ torture_pki_dsa_import_openssh_privkey_base64_passphrase(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
keystring = torture_get_openssh_testkey(SSH_KEYTYPE_DSS, 0, 1);
|
||||
assert_true(keystring != NULL);
|
||||
assert_non_null(keystring);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(keystring,
|
||||
passphrase,
|
||||
@ -460,7 +460,7 @@ static void torture_pki_dsa_publickey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_buf = strdup(torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0));
|
||||
assert_true(key_buf != NULL);
|
||||
assert_non_null(key_buf);
|
||||
|
||||
keylen = strlen(key_buf);
|
||||
|
||||
@ -566,7 +566,6 @@ static void torture_pki_dsa_duplicate_key(void **state)
|
||||
assert_non_null(privkey);
|
||||
|
||||
privkey_dup = ssh_key_dup(privkey);
|
||||
assert_true(privkey_dup != NULL);
|
||||
assert_non_null(privkey_dup);
|
||||
|
||||
rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey);
|
||||
@ -599,9 +598,9 @@ static void torture_pki_dsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_DSS, 1024, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, DSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,DSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
@ -609,9 +608,9 @@ static void torture_pki_dsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_DSS, 2048, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, DSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,DSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
@ -619,9 +618,9 @@ static void torture_pki_dsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_DSS, 3072, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, DSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,DSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
|
@ -203,7 +203,7 @@ static void torture_pki_ecdsa_import_privkey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_str = torture_pki_read_file(LIBSSH_ECDSA_TESTKEY);
|
||||
assert_true(key_str != NULL);
|
||||
assert_non_null(key_str);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
@ -226,7 +226,7 @@ static void torture_pki_ecdsa_publickey_from_privatekey(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_str = torture_pki_read_file(LIBSSH_ECDSA_TESTKEY);
|
||||
assert_true(key_str != NULL);
|
||||
assert_non_null(key_str);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
@ -250,7 +250,7 @@ static void torture_pki_ecdsa_publickey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_buf = torture_pki_read_file(LIBSSH_ECDSA_TESTKEY ".pub");
|
||||
assert_true(key_buf != NULL);
|
||||
assert_non_null(key_buf);
|
||||
|
||||
q = p = key_buf;
|
||||
while (p != NULL && *p != '\0' && *p != ' ') p++;
|
||||
@ -419,9 +419,9 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA, 256, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, ECDSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,ECDSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
type = ssh_key_type(key);
|
||||
@ -436,9 +436,9 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA, 384, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, ECDSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,ECDSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
type = ssh_key_type(key);
|
||||
@ -453,9 +453,9 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA, 521, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, ECDSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,ECDSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
type = ssh_key_type(key);
|
||||
|
@ -127,7 +127,7 @@ static void torture_pki_ed25519_import_privkey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_str = torture_pki_read_file(LIBSSH_ED25519_TESTKEY);
|
||||
assert_true(key_str != NULL);
|
||||
assert_non_null(key_str);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
@ -235,7 +235,7 @@ static void torture_pki_ed25519_publickey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_buf = strdup(torture_get_testkey_pub(SSH_KEYTYPE_ED25519, 0));
|
||||
assert_true(key_buf != NULL);
|
||||
assert_non_null(key_buf);
|
||||
|
||||
q = p = key_buf;
|
||||
while (p != NULL && *p != '\0' && *p != ' ') p++;
|
||||
@ -317,9 +317,9 @@ static void torture_pki_ed25519_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ED25519, 256, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
type = ssh_key_type(key);
|
||||
@ -474,7 +474,7 @@ static void torture_pki_ed25519_sign(void **state)
|
||||
assert_true(rc == SSH_OK);
|
||||
|
||||
blob = pki_signature_to_blob(sig);
|
||||
assert_true(blob != NULL);
|
||||
assert_non_null(blob);
|
||||
|
||||
assert_int_equal(ssh_string_len(blob), sizeof(ref_signature));
|
||||
assert_memory_equal(ssh_string_data(blob), ref_signature, sizeof(ref_signature));
|
||||
@ -504,7 +504,7 @@ static void torture_pki_ed25519_verify(void **state){
|
||||
|
||||
ssh_string_fill(blob, ref_signature, ED25519_SIG_LEN);
|
||||
sig = pki_signature_from_blob(pubkey, blob, SSH_KEYTYPE_ED25519, SSH_DIGEST_AUTO);
|
||||
assert_true(sig != NULL);
|
||||
assert_non_null(sig);
|
||||
|
||||
rc = pki_ed25519_verify(pubkey, sig, HASH, sizeof(HASH));
|
||||
assert_true(rc == SSH_OK);
|
||||
@ -541,7 +541,7 @@ static void torture_pki_ed25519_verify_bad(void **state){
|
||||
ssh_string_fill(blob, ref_signature, ED25519_SIG_LEN);
|
||||
((uint8_t *)ssh_string_data(blob))[i] ^= 0xff;
|
||||
sig = pki_signature_from_blob(pubkey, blob, SSH_KEYTYPE_ED25519, SSH_DIGEST_AUTO);
|
||||
assert_true(sig != NULL);
|
||||
assert_non_null(sig);
|
||||
|
||||
rc = pki_ed25519_verify(pubkey, sig, HASH, sizeof(HASH));
|
||||
assert_true(rc == SSH_ERROR);
|
||||
|
@ -196,7 +196,7 @@ static void torture_pki_rsa_import_privkey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_str = torture_pki_read_file(LIBSSH_RSA_TESTKEY);
|
||||
assert_true(key_str != NULL);
|
||||
assert_non_null(key_str);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
|
||||
assert_true(rc == 0);
|
||||
@ -276,7 +276,7 @@ static void torture_pki_rsa_copy_cert_to_privkey(void **state)
|
||||
assert_true(rc == SSH_ERROR);
|
||||
|
||||
/* A public key doesn't have a cert, copy should fail. */
|
||||
assert_true(pubkey->cert == NULL);
|
||||
assert_null(pubkey->cert);
|
||||
rc = ssh_pki_copy_cert_to_privkey(pubkey, privkey);
|
||||
assert_true(rc == SSH_ERROR);
|
||||
|
||||
@ -325,7 +325,7 @@ static void torture_pki_rsa_publickey_base64(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
key_buf = strdup(torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
|
||||
assert_true(key_buf != NULL);
|
||||
assert_non_null(key_buf);
|
||||
|
||||
q = p = key_buf;
|
||||
while (p != NULL && *p != '\0' && *p != ' ') p++;
|
||||
@ -454,9 +454,9 @@ static void torture_pki_rsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 1024, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, RSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,RSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
@ -465,9 +465,9 @@ static void torture_pki_rsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, RSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,RSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
@ -476,9 +476,9 @@ static void torture_pki_rsa_generate_key(void **state)
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 4096, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
sign = pki_do_sign(key, RSA_HASH, 20);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session,sign,key,RSA_HASH,20);
|
||||
assert_true(rc == SSH_OK);
|
||||
ssh_signature_free(sign);
|
||||
@ -501,32 +501,32 @@ static void torture_pki_rsa_sha2(void **state)
|
||||
/* Setup */
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_true(key != NULL);
|
||||
assert_non_null(key);
|
||||
|
||||
/* Sign using automatic digest */
|
||||
sign = pki_do_sign_hash(key, RSA_HASH, 20, SSH_DIGEST_AUTO);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session, sign, key, RSA_HASH, 20);
|
||||
assert_ssh_return_code(session, rc);
|
||||
ssh_signature_free(sign);
|
||||
|
||||
/* Sign using old SHA1 digest */
|
||||
sign = pki_do_sign_hash(key, RSA_HASH, 20, SSH_DIGEST_SHA1);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session, sign, key, RSA_HASH, 20);
|
||||
assert_ssh_return_code(session, rc);
|
||||
ssh_signature_free(sign);
|
||||
|
||||
/* Sign using new SHA256 digest */
|
||||
sign = pki_do_sign_hash(key, SHA256_HASH, 32, SSH_DIGEST_SHA256);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session, sign, key, SHA256_HASH, 32);
|
||||
assert_ssh_return_code(session, rc);
|
||||
ssh_signature_free(sign);
|
||||
|
||||
/* Sign using rsa-sha2-512 algorithm */
|
||||
sign = pki_do_sign_hash(key, SHA512_HASH, 64, SSH_DIGEST_SHA512);
|
||||
assert_true(sign != NULL);
|
||||
assert_non_null(sign);
|
||||
rc = pki_signature_verify(session, sign, key, SHA512_HASH, 64);
|
||||
assert_ssh_return_code(session, rc);
|
||||
ssh_signature_free(sign);
|
||||
@ -671,7 +671,7 @@ torture_pki_rsa_import_openssh_privkey_base64_passphrase(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
keystring = torture_get_openssh_testkey(SSH_KEYTYPE_RSA, 0, 1);
|
||||
assert_true(keystring != NULL);
|
||||
assert_non_null(keystring);
|
||||
|
||||
rc = ssh_pki_import_privkey_base64(keystring,
|
||||
passphrase,
|
||||
|
@ -186,7 +186,7 @@ static void test_ssh_channel_request_x11(void **state) {
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
server = ssh_new();
|
||||
assert_true(server != NULL);
|
||||
assert_non_null(server);
|
||||
|
||||
rc = ssh_bind_accept(sshbind, server);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
@ -198,7 +198,7 @@ static void test_ssh_channel_request_x11(void **state) {
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
event = ssh_event_new();
|
||||
assert_true(event != NULL);
|
||||
assert_non_null(event);
|
||||
|
||||
ssh_event_add_session(event, server);
|
||||
|
||||
|
@ -380,14 +380,14 @@ static void *thread_ssh_buffer_get_format(void *threadid) {
|
||||
assert_true(d == 0xbadc0de);
|
||||
assert_true(q == 0x13243546acbdcedf);
|
||||
|
||||
assert_true(s != NULL);
|
||||
assert_non_null(s);
|
||||
assert_int_equal(ssh_string_len(s), 6);
|
||||
assert_memory_equal(ssh_string_data(s), "libssh", 6);
|
||||
|
||||
assert_true(s1 != NULL);
|
||||
assert_non_null(s1);
|
||||
assert_string_equal(s1, "rocks");
|
||||
|
||||
assert_true(s2 != NULL);
|
||||
assert_non_null(s2);
|
||||
assert_memory_equal(s2, "So much", 7);
|
||||
|
||||
len = ssh_buffer_get_len(buffer);
|
||||
@ -453,9 +453,9 @@ static void *thread_ssh_buffer_get_format_error(void *threadid)
|
||||
&b);
|
||||
assert_int_equal(rc, SSH_ERROR);
|
||||
|
||||
assert_true(s == NULL);
|
||||
assert_true(s1 == NULL);
|
||||
assert_true(s2 == NULL);
|
||||
assert_null(s);
|
||||
assert_null(s1);
|
||||
assert_null(s2);
|
||||
|
||||
/* Teardown */
|
||||
SSH_BUFFER_FREE(buffer);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user