2323//! and revoked markers. See "FIXME" comments littered in this file.
2424
2525use crate :: util:: context:: { Definition , GlobalContext , Value } ;
26+ use crate :: CargoResult ;
2627use base64:: engine:: general_purpose:: STANDARD ;
2728use base64:: engine:: general_purpose:: STANDARD_NO_PAD ;
2829use base64:: Engine as _;
@@ -137,7 +138,7 @@ pub fn certificate_check(
137138 port : Option < u16 > ,
138139 config_known_hosts : Option < & Vec < Value < String > > > ,
139140 diagnostic_home_config : & str ,
140- ) -> Result < CertificateCheckStatus , git2 :: Error > {
141+ ) -> CargoResult < CertificateCheckStatus > {
141142 let Some ( host_key) = cert. as_hostkey ( ) else {
142143 // Return passthrough for TLS X509 certificates to use whatever validation
143144 // was done in git2.
@@ -150,13 +151,12 @@ pub fn certificate_check(
150151 _ => host. to_string ( ) ,
151152 } ;
152153 // The error message must be constructed as a string to pass through the libgit2 C API.
153- let err_msg = match check_ssh_known_hosts ( gctx, host_key, & host_maybe_port, config_known_hosts)
154- {
154+ match check_ssh_known_hosts ( gctx, host_key, & host_maybe_port, config_known_hosts) {
155155 Ok ( ( ) ) => {
156156 return Ok ( CertificateCheckStatus :: CertificateOk ) ;
157157 }
158158 Err ( KnownHostError :: CheckError ( e) ) => {
159- format ! ( "error: failed to validate host key:\n {:#}" , e)
159+ anyhow :: bail !( "error: failed to validate host key:\n {:#}" , e)
160160 }
161161 Err ( KnownHostError :: HostKeyNotFound {
162162 hostname,
@@ -193,7 +193,7 @@ pub fn certificate_check(
193193 }
194194 msg
195195 } ;
196- format ! ( "error: unknown SSH host key\n \
196+ anyhow :: bail !( "error: unknown SSH host key\n \
197197 The SSH host key for `{hostname}` is not known and cannot be validated.\n \
198198 \n \
199199 To resolve this issue, add the host key to {known_hosts_location}\n \
@@ -242,7 +242,7 @@ pub fn certificate_check(
242242 )
243243 }
244244 } ;
245- format ! ( "error: SSH host key has changed for `{hostname}`\n \
245+ anyhow :: bail !( "error: SSH host key has changed for `{hostname}`\n \
246246 *********************************\n \
247247 * WARNING: HOST KEY HAS CHANGED *\n \
248248 *********************************\n \
@@ -274,7 +274,7 @@ pub fn certificate_check(
274274 location,
275275 } ) => {
276276 let key_type_short_name = key_type. short_name ( ) ;
277- format ! (
277+ anyhow :: bail !(
278278 "error: Key has been revoked for `{hostname}`\n \
279279 **************************************\n \
280280 * WARNING: REVOKED HOST KEY DETECTED *\n \
@@ -288,7 +288,7 @@ pub fn certificate_check(
288288 )
289289 }
290290 Err ( KnownHostError :: HostHasOnlyCertAuthority { hostname, location } ) => {
291- format ! ( "error: Found a `@cert-authority` marker for `{hostname}`\n \
291+ anyhow :: bail !( "error: Found a `@cert-authority` marker for `{hostname}`\n \
292292 \n \
293293 Cargo doesn't support certificate authorities for host key verification. It is\n \
294294 recommended that the command line Git client is used instead. This can be achieved\n \
@@ -300,12 +300,7 @@ pub fn certificate_check(
300300 for more information.\n \
301301 ")
302302 }
303- } ;
304- Err ( git2:: Error :: new (
305- git2:: ErrorCode :: GenericError ,
306- git2:: ErrorClass :: Callback ,
307- err_msg,
308- ) )
303+ }
309304}
310305
311306/// Checks if the given host/host key pair is known.
0 commit comments