Skip to content

Commit 659e318

Browse files
committed
implement valid in certificate_check_cb
1 parent 62d353e commit 659e318

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/remote_callbacks.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -412,27 +412,32 @@ extern "C" fn update_tips_cb(
412412

413413
extern "C" fn certificate_check_cb(
414414
cert: *mut raw::git_cert,
415-
_valid: c_int,
415+
valid: c_int,
416416
hostname: *const c_char,
417417
data: *mut c_void,
418418
) -> c_int {
419-
let ok = panic::wrap(|| unsafe {
420-
let payload = &mut *(data as *mut RemoteCallbacks<'_>);
421-
let callback = match payload.certificate_check {
422-
Some(ref mut c) => c,
423-
None => return Ok(CertificateCheckStatus::CertificatePassthrough),
424-
};
425-
let cert = Binding::from_raw(cert);
426-
let hostname = str::from_utf8(CStr::from_ptr(hostname).to_bytes()).unwrap();
427-
callback(&cert, hostname)
428-
});
429-
match ok {
430-
Some(Ok(CertificateCheckStatus::CertificateOk)) => 0,
431-
Some(Ok(CertificateCheckStatus::CertificatePassthrough)) => raw::GIT_PASSTHROUGH as c_int,
432-
Some(Err(e)) => unsafe { e.raw_set_git_error() },
433-
None => {
434-
// Panic. The *should* get resumed by some future call to check().
435-
-1
419+
match valid {
420+
-1 => valid,
421+
_ => {
422+
let ok = panic::wrap(|| unsafe {
423+
let payload = &mut *(data as *mut RemoteCallbacks<'_>);
424+
let callback = match payload.certificate_check {
425+
Some(ref mut c) => c,
426+
None => return Ok(CertificateCheckStatus::CertificatePassthrough),
427+
};
428+
let cert = Binding::from_raw(cert);
429+
let hostname = str::from_utf8(CStr::from_ptr(hostname).to_bytes()).unwrap();
430+
callback(&cert, hostname)
431+
});
432+
match ok {
433+
Some(Ok(CertificateCheckStatus::CertificateOk)) => 0,
434+
Some(Ok(CertificateCheckStatus::CertificatePassthrough)) => raw::GIT_PASSTHROUGH as c_int,
435+
Some(Err(e)) => unsafe { e.raw_set_git_error() },
436+
None => {
437+
// Panic. The *should* get resumed by some future call to check().
438+
-1
439+
}
440+
}
436441
}
437442
}
438443
}

0 commit comments

Comments
 (0)