diff --git a/src/main.rs b/src/main.rs index db35f60..f3a04a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,6 +180,7 @@ fn generate_rsa_private_key() -> Result, ErrorStack> { /// Create root CA certificate, given root CA private key fn create_root_ca_certificate(args: &Args, pkey: &PKey) -> Result { + // Build the subject and issuer names. let mut name_builder = X509NameBuilder::new()?; name_builder.append_entry_by_text("C", &args.ca_country)?; if let Some(txt) = args.ca_state.clone() { @@ -194,12 +195,14 @@ fn create_root_ca_certificate(args: &Args, pkey: &PKey) -> Result) -> Result) -> Result { + // Create a new certificate signing request (CSR) builder. let mut req_builder = X509ReqBuilder::new()?; req_builder.set_pubkey(server_key)?; + // Build the subject name. let mut name_builder = X509NameBuilder::new()?; name_builder.append_entry_by_text("C", &args.srv_country)?; - match args.srv_state.clone() { - Some(txt) => { - name_builder.append_entry_by_text("ST", &txt)?; - } - None => {} + if let Some(txt) = args.srv_state.clone() { + name_builder.append_entry_by_text("ST", &txt)?; } - match args.srv_city.clone() { - Some(txt) => { - name_builder.append_entry_by_text("L", &txt)?; - } - None => {} + if let Some(txt) = args.srv_city.clone() { + name_builder.append_entry_by_text("L", &txt)?; } - match args.srv_org.clone() { - Some(txt) => { - name_builder.append_entry_by_text("O", &txt)?; - } - None => {} + if let Some(txt) = args.srv_org.clone() { + name_builder.append_entry_by_text("O", &txt)?; } name_builder.append_entry_by_text("CN", &args.srv_common_name)?; let name = name_builder.build(); @@ -272,6 +268,7 @@ fn generate_web_server_csr(args: &Args, server_key: &PKey) -> Result