1
0
mirror of https://github.com/pcvolkmer/cert-tools.git synced 2025-04-19 09:06:49 +00:00

refactor: remove duplicated lines

This commit is contained in:
Paul-Christian Volkmer 2025-02-13 20:26:32 +01:00
parent cdce8c4dab
commit bc0dc263a3

View File

@ -105,6 +105,16 @@ impl Ui {
} }
fn update(&mut self, message: Message) -> Task<Message> { fn update(&mut self, message: Message) -> Task<Message> {
fn fixed_chain(chain: &Option<Chain>) -> Option<Chain> {
match chain {
Some(chain) => match Chain::create_fixed(chain.certs()) {
Ok(chain) => Some(chain),
_ => None,
},
_ => None,
}
}
self.mode = UiMode::CertList; self.mode = UiMode::CertList;
match message { match message {
Message::PickCertFile => Task::perform(pick_file(), Message::SetCertFile), Message::PickCertFile => Task::perform(pick_file(), Message::SetCertFile),
@ -126,13 +136,7 @@ impl Ui {
Ok(chain) => Some(chain), Ok(chain) => Some(chain),
_ => None, _ => None,
}; };
self.fixed_chain = match &self.chain { self.fixed_chain = fixed_chain(&self.chain);
Some(chain) => match Chain::create_fixed(chain.certs()) {
Ok(chain) => Some(chain),
_ => None,
},
_ => None,
};
self.chain_indicator_state = self.chain_indicator_state(); self.chain_indicator_state = self.chain_indicator_state();
Task::done(Message::Print) Task::done(Message::Print)
} }
@ -152,13 +156,7 @@ impl Ui {
Ok(chain) => Some(chain), Ok(chain) => Some(chain),
_ => None, _ => None,
}; };
self.fixed_chain = match &self.chain { self.fixed_chain = fixed_chain(&self.chain);
Some(chain) => match Chain::create_fixed(chain.certs()) {
Ok(chain) => Some(chain),
_ => None,
},
_ => None,
};
self.output = Content::default(); self.output = Content::default();
self.mode = UiMode::CertList; self.mode = UiMode::CertList;
} }
@ -178,13 +176,7 @@ impl Ui {
Ok(chain) => Some(chain), Ok(chain) => Some(chain),
_ => None, _ => None,
}; };
self.fixed_chain = match &self.chain { self.fixed_chain = fixed_chain(&self.chain);
Some(chain) => match Chain::create_fixed(chain.certs()) {
Ok(chain) => Some(chain),
_ => None,
},
_ => None,
};
self.output = Content::default(); self.output = Content::default();
} }
_ => self.ca_file = File::None, _ => self.ca_file = File::None,
@ -205,7 +197,7 @@ impl Ui {
self.key_indicator_state = self.key_indicator_state(); self.key_indicator_state = self.key_indicator_state();
Task::done(Message::Print) Task::done(Message::Print)
} }
Message::Print => { Message::Print | Message::PrintPem => {
match self.print_output() { match self.print_output() {
Ok(output) => { Ok(output) => {
self.output = Content::with_text(output.as_str()); self.output = Content::with_text(output.as_str());
@ -219,20 +211,6 @@ impl Ui {
}; };
Task::none() Task::none()
} }
Message::PrintPem => {
match self.pem_output() {
Ok(output) => {
self.output = Content::with_text(output.as_str());
self.status = String::new();
self.mode = UiMode::Output;
}
Err(err) => {
self.output = Content::default();
self.status = err
}
};
Task::none()
}
Message::CopyValue(value) => clipboard::write::<Message>(value), Message::CopyValue(value) => clipboard::write::<Message>(value),
Message::Cleanup => { Message::Cleanup => {
if let Some(chain) = self.fixed_chain.take() { if let Some(chain) = self.fixed_chain.take() {