Skip to content

Commit

Permalink
address ci failures
Browse files Browse the repository at this point in the history
* rustfmt
* clippy
  • Loading branch information
jmayclin committed Nov 26, 2024
1 parent 222a7c3 commit 4174080
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
15 changes: 6 additions & 9 deletions bindings/rust/s2n-tls/src/cert_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl CertificateChain<'_> {
///
/// This can be used with [crate::config::Builder::add_to_store] to share a
/// single cert across multiple configs.
pub fn load_pems(cert: &[u8], key: &[u8]) -> Result<CertificateChain<'static>, Error> {
pub fn load_pem(cert: &[u8], key: &[u8]) -> Result<CertificateChain<'static>, Error> {
let mut chain = Self::allocate_owned()?;
unsafe {
// SAFETY: manual audit of load_pem_bytes shows that `chain_pem` and
Expand Down Expand Up @@ -222,10 +222,10 @@ mod tests {
.with_system_certs(false)?
.set_security_policy(&DEFAULT_TLS13)?;
for cert in certs.into_iter() {
server_config.add_to_store(cert)?;
server_config.add_cert_chain_and_key_to_store(cert)?;
}
if let Some(defaults) = defaults {
server_config.set_default_cert_chain_and_key(defaults)?;
server_config.set_cert_chain_and_key_defaults(defaults)?;
}

let mut client_config = config::Builder::new();
Expand All @@ -244,10 +244,7 @@ mod tests {

/// This is a useful (but inefficient) test utility to check if CertificateChain
/// structs are equal. It does this by comparing the serialized `der` representation.
fn cert_chains_are_equal(
this: &CertificateChain<'_>,
that: &CertificateChain<'_>,
) -> bool {
fn cert_chains_are_equal(this: &CertificateChain<'_>, that: &CertificateChain<'_>) -> bool {
let this: Vec<Vec<u8>> = this
.iter()
.map(|cert| cert.unwrap().der().unwrap().to_owned())
Expand All @@ -266,7 +263,7 @@ mod tests {

{
let mut server = config::Builder::new();
server.add_to_store(cert.clone())?;
server.add_cert_chain_and_key_to_store(cert.clone())?;

// after being added, the reference count should have increased
assert_eq!(Arc::strong_count(&cert.ptr), 2);
Expand Down Expand Up @@ -390,7 +387,7 @@ mod tests {
let mut config = config::Builder::new();

// library owned certs can not be used with application owned certs
config.add_to_store(application_owned_cert)?;
config.add_cert_chain_and_key_to_store(application_owned_cert)?;
let err = config
.load_pem(cert_for_lib.cert(), cert_for_lib.key())
.err()
Expand Down
7 changes: 5 additions & 2 deletions bindings/rust/s2n-tls/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ impl Builder {
}

/// Corresponds to [s2n_config_add_cert_chain_and_key_to_store](https://aws.github.io/s2n-tls/doxygen/s2n_8h.html#abfb875eff7e81b22378e4ae5b313169f)
pub fn add_to_store(&mut self, chain: CertificateChain<'static>) -> Result<&mut Self, Error> {
pub fn add_cert_chain_and_key_to_store(
&mut self,
chain: CertificateChain<'static>,
) -> Result<&mut Self, Error> {
// Out of an abudance of caution, we hold a reference to the CertificateChain
// regardless of whether add_to_store fails or succeeds. We have limited
// visibility into the failure modes, so this behavior ensures that _if_
Expand All @@ -323,7 +326,7 @@ impl Builder {
}

/// Corresponds to [s2n_config_set_cert_chain_and_key_defaults](https://aws.github.io/s2n-tls/doxygen/s2n_8h.html#a30d021a10ad7183c995d6d2a65926272)
pub fn set_default_cert_chain_and_key(
pub fn set_cert_chain_and_key_defaults(
&mut self,
chains: Vec<CertificateChain<'static>>,
) -> Result<&mut Self, Error> {
Expand Down
5 changes: 3 additions & 2 deletions bindings/rust/s2n-tls/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ impl Default for CertKeyPair {

impl CertKeyPair {
/// This is the directory holding all of the pems used for s2n-tls unit tests
const TEST_PEMS_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../tests/pems/");
const TEST_PEMS_PATH: &'static str =
concat!(env!("CARGO_MANIFEST_DIR"), "/../../../tests/pems/");

/// Create a test CertKeyPair
/// * `prefix`: The *relative* prefix from the s2n-tls/tests/pems/ folder.
Expand Down Expand Up @@ -136,7 +137,7 @@ impl CertKeyPair {
}

pub fn into_certificate_chain(&self) -> CertificateChain<'static> {
CertificateChain::load_pems(&self.cert, &self.key).unwrap()
CertificateChain::load_pem(&self.cert, &self.key).unwrap()
}

pub fn cert_path(&self) -> &str {
Expand Down

0 comments on commit 4174080

Please sign in to comment.