23
23
//! and revoked markers. See "FIXME" comments littered in this file.
24
24
25
25
use crate :: util:: context:: { Definition , GlobalContext , Value } ;
26
+ use crate :: CargoResult ;
26
27
use base64:: engine:: general_purpose:: STANDARD ;
27
28
use base64:: engine:: general_purpose:: STANDARD_NO_PAD ;
28
29
use base64:: Engine as _;
@@ -137,7 +138,7 @@ pub fn certificate_check(
137
138
port : Option < u16 > ,
138
139
config_known_hosts : Option < & Vec < Value < String > > > ,
139
140
diagnostic_home_config : & str ,
140
- ) -> Result < CertificateCheckStatus , git2 :: Error > {
141
+ ) -> CargoResult < CertificateCheckStatus > {
141
142
let Some ( host_key) = cert. as_hostkey ( ) else {
142
143
// Return passthrough for TLS X509 certificates to use whatever validation
143
144
// was done in git2.
@@ -150,13 +151,12 @@ pub fn certificate_check(
150
151
_ => host. to_string ( ) ,
151
152
} ;
152
153
// 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) {
155
155
Ok ( ( ) ) => {
156
156
return Ok ( CertificateCheckStatus :: CertificateOk ) ;
157
157
}
158
158
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)
160
160
}
161
161
Err ( KnownHostError :: HostKeyNotFound {
162
162
hostname,
@@ -193,7 +193,7 @@ pub fn certificate_check(
193
193
}
194
194
msg
195
195
} ;
196
- format ! ( "error: unknown SSH host key\n \
196
+ anyhow :: bail !( "error: unknown SSH host key\n \
197
197
The SSH host key for `{hostname}` is not known and cannot be validated.\n \
198
198
\n \
199
199
To resolve this issue, add the host key to {known_hosts_location}\n \
@@ -242,7 +242,7 @@ pub fn certificate_check(
242
242
)
243
243
}
244
244
} ;
245
- format ! ( "error: SSH host key has changed for `{hostname}`\n \
245
+ anyhow :: bail !( "error: SSH host key has changed for `{hostname}`\n \
246
246
*********************************\n \
247
247
* WARNING: HOST KEY HAS CHANGED *\n \
248
248
*********************************\n \
@@ -274,7 +274,7 @@ pub fn certificate_check(
274
274
location,
275
275
} ) => {
276
276
let key_type_short_name = key_type. short_name ( ) ;
277
- format ! (
277
+ anyhow :: bail !(
278
278
"error: Key has been revoked for `{hostname}`\n \
279
279
**************************************\n \
280
280
* WARNING: REVOKED HOST KEY DETECTED *\n \
@@ -288,7 +288,7 @@ pub fn certificate_check(
288
288
)
289
289
}
290
290
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 \
292
292
\n \
293
293
Cargo doesn't support certificate authorities for host key verification. It is\n \
294
294
recommended that the command line Git client is used instead. This can be achieved\n \
@@ -300,12 +300,7 @@ pub fn certificate_check(
300
300
for more information.\n \
301
301
")
302
302
}
303
- } ;
304
- Err ( git2:: Error :: new (
305
- git2:: ErrorCode :: GenericError ,
306
- git2:: ErrorClass :: Callback ,
307
- err_msg,
308
- ) )
303
+ }
309
304
}
310
305
311
306
/// Checks if the given host/host key pair is known.
0 commit comments