Load certificates from a directory Reads all files in the directory and attempts to parse them as certificates. Invalid files are silently skipped (matches OpenSSL capath behavior).
(&mut self, dir_path: &str)
| 648 | /// Reads all files in the directory and attempts to parse them as certificates. |
| 649 | /// Invalid files are silently skipped (matches OpenSSL capath behavior). |
| 650 | pub fn load_from_dir(&mut self, dir_path: &str) -> Result<CertStats, std::io::Error> { |
| 651 | let entries = std::fs::read_dir(dir_path)?; |
| 652 | let mut stats = CertStats::default(); |
| 653 | |
| 654 | for entry in entries { |
| 655 | let entry = entry?; |
| 656 | let path = entry.path(); |
| 657 | |
| 658 | // Skip directories and process all files |
| 659 | // OpenSSL capath uses hash-based naming like "4e1295a3.0" |
| 660 | if path.is_file() |
| 661 | && let Ok(contents) = std::fs::read(&path) |
| 662 | { |
| 663 | // Ignore errors for individual files (some may not be certs) |
| 664 | if let Ok(file_stats) = self.load_from_bytes(&contents) { |
| 665 | stats.total_certs += file_stats.total_certs; |
| 666 | stats.ca_certs += file_stats.ca_certs; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | Ok(stats) |
| 672 | } |
| 673 | |
| 674 | /// Helper: Add a certificate to the store with duplicate checking |
| 675 | /// |
no test coverage detected