Skip to content

Commit 8d5eddc

Browse files
committed
refactor out into read_file_fn
1 parent 229fd45 commit 8d5eddc

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

rust/cert-tools/src/cli_args.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ impl GeneratePkcs12 {
8080

8181
impl CertInput {
8282
pub fn read(&self) -> Result<Vec<X509>, snafu::Whatever> {
83+
let read_file_fn = |path| {
84+
fs::read(path).with_whatever_context(|_| format!("failed to read file from {self:?}"))
85+
};
86+
8387
match self {
8488
CertInput::Pem(path) => {
85-
let file_contents = fs::read(path)
86-
.with_whatever_context(|_| format!("failed to read file from {self:?}"))?;
89+
let file_contents = read_file_fn(path)?;
8790

8891
let certs = parse_pem_contents(&file_contents).with_whatever_context(|_| {
8992
format!(
@@ -99,8 +102,7 @@ impl CertInput {
99102
Ok(certs)
100103
}
101104
CertInput::Pkcs12(Pkcs12Source { path, password }) => {
102-
let file_contents = fs::read(path)
103-
.with_whatever_context(|_| format!("failed to read file from {self:?}"))?;
105+
let file_contents = read_file_fn(path)?;
104106

105107
parse_pkcs12_file_workaround(&file_contents, password)
106108
}

0 commit comments

Comments
 (0)