int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload) { git_cert_hostkey *key; git_oid expected = {{0}}, actual = {{0}}; GIT_UNUSED(valid); GIT_UNUSED(payload); cl_assert(_remote_ssh_fingerprint); cl_git_pass(git_oid_fromstrp(&expected, _remote_ssh_fingerprint)); cl_assert_equal_i(GIT_CERT_HOSTKEY_LIBSSH2, cert->cert_type); key = (git_cert_hostkey *) cert; /* * We need to figure out how long our input was to check for * the type. Here we abuse the fact that both hashes fit into * our git_oid type. */ if (strlen(_remote_ssh_fingerprint) == 32 && key->type & GIT_CERT_SSH_MD5) { memcpy(&actual.id, key->hash_md5, 16); } else if (strlen(_remote_ssh_fingerprint) == 40 && key->type & GIT_CERT_SSH_SHA1) { memcpy(&actual, key->hash_sha1, 20); } else { cl_fail("Cannot find a usable SSH hash"); } cl_assert(!memcmp(&expected, &actual, 20)); cl_assert_equal_s("localhost", host); return GIT_EUSER; }
void test_odb_loose__exists(void) { git_oid id, id2; git_odb *odb; write_object_files(&one); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, one.id)); cl_assert(git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b137891")); cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); cl_assert_equal_i(0, git_oid_streq(&id2, one.id)); /* Test for a missing object */ cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa")); cl_assert(!git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b13789a")); cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); git_odb_free(odb); }