🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(router): setters for direct key and certificate content

Fuwn 78d8147e e109360f

+74 -11
+1 -1
Cargo.toml
··· 5 5 6 6 [package] 7 7 name = "windmark" 8 - version = "0.3.9" 8 + version = "0.3.10" 9 9 authors = ["Fuwn <contact@fuwn.me>"] 10 10 edition = "2021" 11 11 description = "An elegant and highly performant async Gemini server framework"
+1 -1
src/response.rs
··· 97 97 #[must_use] 98 98 pub fn binary_success_auto(content: &[u8]) -> Self { 99 99 Self::new(22, String::from_utf8_lossy(content)) 100 - .with_mime(&tree_magic::from_u8(content)) 100 + .with_mime(tree_magic::from_u8(content)) 101 101 .clone() 102 102 } 103 103
+72 -9
src/router.rs
··· 90 90 routes: matchit::Router<Arc<AsyncMutex<Box<dyn RouteResponse>>>>, 91 91 error_handler: Arc<AsyncMutex<Box<dyn ErrorResponse>>>, 92 92 private_key_file_name: String, 93 - ca_file_name: String, 93 + private_key_content: Option<String>, 94 + certificate_file_name: String, 95 + certificate_content: Option<String>, 94 96 headers: Arc<Mutex<Vec<Box<dyn Partial>>>>, 95 97 footers: Arc<Mutex<Vec<Box<dyn Partial>>>>, 96 98 ssl_acceptor: Arc<SslAcceptor>, ··· 137 139 self 138 140 } 139 141 142 + /// Set the content of the private key 143 + /// 144 + /// # Examples 145 + /// 146 + /// ```rust 147 + /// windmark::router::Router::new().set_private_key("..."); 148 + /// ``` 149 + pub fn set_private_key( 150 + &mut self, 151 + private_key_content: impl Into<String> + AsRef<str>, 152 + ) -> &mut Self { 153 + self.private_key_content = Some(private_key_content.into()); 154 + 155 + self 156 + } 157 + 140 158 /// Set the filename of the certificate chain file. 141 159 /// 142 160 /// # Examples ··· 148 166 &mut self, 149 167 certificate_name: impl Into<String> + AsRef<str>, 150 168 ) -> &mut Self { 151 - self.ca_file_name = certificate_name.into(); 169 + self.certificate_file_name = certificate_name.into(); 170 + 171 + self 172 + } 173 + 174 + /// Set the content of the certificate chain file. 175 + /// 176 + /// # Examples 177 + /// 178 + /// ```rust 179 + /// windmark::router::Router::new().set_certificate("..."); 180 + /// ``` 181 + pub fn set_certificate( 182 + &mut self, 183 + certificate_content: impl Into<String> + AsRef<str>, 184 + ) -> &mut Self { 185 + self.certificate_content = Some(certificate_content.into()); 152 186 153 187 self 154 188 } ··· 340 374 // Ok(()) 341 375 } 342 376 343 - #[allow(clippy::too_many_lines)] 377 + #[allow( 378 + clippy::too_many_lines, 379 + clippy::needless_pass_by_ref_mut, 380 + clippy::significant_drop_in_scrutinee 381 + )] 344 382 async fn handle( 345 383 &mut self, 346 384 stream: &mut Stream, ··· 515 553 fn create_acceptor(&mut self) -> Result<(), Box<dyn Error>> { 516 554 let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls())?; 517 555 518 - builder.set_private_key_file( 519 - &self.private_key_file_name, 520 - ssl::SslFiletype::PEM, 521 - )?; 522 - builder.set_certificate_file(&self.ca_file_name, ssl::SslFiletype::PEM)?; 556 + if self.certificate_content.is_some() { 557 + builder.set_certificate( 558 + openssl::x509::X509::from_pem( 559 + self.certificate_content.clone().unwrap().as_bytes(), 560 + )? 561 + .as_ref(), 562 + )?; 563 + } else { 564 + builder.set_certificate_file( 565 + &self.certificate_file_name, 566 + ssl::SslFiletype::PEM, 567 + )?; 568 + } 569 + 570 + if self.private_key_content.is_some() { 571 + builder.set_private_key( 572 + openssl::pkey::PKey::private_key_from_pem( 573 + self.private_key_content.clone().unwrap().as_bytes(), 574 + )? 575 + .as_ref(), 576 + )?; 577 + } else { 578 + builder.set_private_key_file( 579 + &self.private_key_file_name, 580 + ssl::SslFiletype::PEM, 581 + )?; 582 + } 583 + 523 584 builder.check_private_key()?; 524 585 builder.set_verify_callback(ssl::SslVerifyMode::PEER, |_, _| true); 525 586 builder.set_session_id_context( ··· 919 980 } 920 981 }))), 921 982 private_key_file_name: String::new(), 922 - ca_file_name: String::new(), 983 + certificate_file_name: String::new(), 923 984 headers: Arc::new(Mutex::new(vec![])), 924 985 footers: Arc::new(Mutex::new(vec![])), 925 986 ssl_acceptor: Arc::new( ··· 939 1000 modules: Arc::new(Mutex::new(vec![])), 940 1001 async_modules: Arc::new(AsyncMutex::new(vec![])), 941 1002 fix_path: false, 1003 + private_key_content: None, 1004 + certificate_content: None, 942 1005 } 943 1006 } 944 1007 }