Skip to content

Commit

Permalink
server: specific err for config w/o cert resolver
Browse files Browse the repository at this point in the history
When we made the server config builder use an out param for the built
config it allowed us to return an error when building a config without
a cert resolver. At the time we used `RUSTLS_RESULT_GENERAL`, but this
offers no significant hint at the root cause. This commit introduces
a new `RUSTLS_RESULT_NO_CERT_RESOLVER` error and updates the impl and
unit test to use it.
  • Loading branch information
cpu committed Oct 4, 2024
1 parent eb3ccfa commit 1e9d925
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ u32_enum_builder! {
NoServerCertVerifier => 7015,
NoDefaultCryptoProvider => 7016,
GetRandomFailed => 7017,
NoCertResolver => 7018,

// From https://docs.rs/rustls/latest/rustls/enum.Error.html
NoCertificatesPresented => 7101,
Expand Down Expand Up @@ -499,6 +500,9 @@ impl Display for rustls_result {
GetRandomFailed => {
write!(f, "failed to get random bytes from the crypto provider")
}
NoCertResolver => {
write!(f, "no certificate resolver was configured")
}

CertEncodingBad => Error::InvalidCertificate(CertificateError::BadEncoding).fmt(f),
CertExpired => Error::InvalidCertificate(CertificateError::Expired).fmt(f),
Expand Down
1 change: 1 addition & 0 deletions src/rustls.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum rustls_result {
RUSTLS_RESULT_NO_SERVER_CERT_VERIFIER = 7015,
RUSTLS_RESULT_NO_DEFAULT_CRYPTO_PROVIDER = 7016,
RUSTLS_RESULT_GET_RANDOM_FAILED = 7017,
RUSTLS_RESULT_NO_CERT_RESOLVER = 7018,
RUSTLS_RESULT_NO_CERTIFICATES_PRESENTED = 7101,
RUSTLS_RESULT_DECRYPT_ERROR = 7102,
RUSTLS_RESULT_FAILED_TO_GET_CURRENT_TIME = 7103,
Expand Down
4 changes: 2 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl rustls_server_config_builder {
let mut config = if let Some(r) = builder.cert_resolver {
base.with_cert_resolver(r)
} else {
return rustls_result::General;
return rustls_result::NoCertResolver;
};
if let Some(ss) = builder.session_storage {
config.session_storage = ss;
Expand Down Expand Up @@ -816,7 +816,7 @@ mod tests {
let mut config = null();
let result =
rustls_server_config_builder::rustls_server_config_builder_build(builder, &mut config);
assert_eq!(result, rustls_result::General);
assert_eq!(result, rustls_result::NoCertResolver);
assert!(config.is_null());
}

Expand Down

0 comments on commit 1e9d925

Please sign in to comment.