diff --git a/ui/src/main.rs b/ui/src/main.rs index 9f54632..496d449 100644 --- a/ui/src/main.rs +++ b/ui/src/main.rs @@ -105,6 +105,16 @@ impl Ui { } fn update(&mut self, message: Message) -> Task { + fn fixed_chain(chain: &Option) -> Option { + match chain { + Some(chain) => match Chain::create_fixed(chain.certs()) { + Ok(chain) => Some(chain), + _ => None, + }, + _ => None, + } + } + self.mode = UiMode::CertList; match message { Message::PickCertFile => Task::perform(pick_file(), Message::SetCertFile), @@ -126,13 +136,7 @@ impl Ui { Ok(chain) => Some(chain), _ => None, }; - self.fixed_chain = match &self.chain { - Some(chain) => match Chain::create_fixed(chain.certs()) { - Ok(chain) => Some(chain), - _ => None, - }, - _ => None, - }; + self.fixed_chain = fixed_chain(&self.chain); self.chain_indicator_state = self.chain_indicator_state(); Task::done(Message::Print) } @@ -152,13 +156,7 @@ impl Ui { Ok(chain) => Some(chain), _ => None, }; - self.fixed_chain = match &self.chain { - Some(chain) => match Chain::create_fixed(chain.certs()) { - Ok(chain) => Some(chain), - _ => None, - }, - _ => None, - }; + self.fixed_chain = fixed_chain(&self.chain); self.output = Content::default(); self.mode = UiMode::CertList; } @@ -178,13 +176,7 @@ impl Ui { Ok(chain) => Some(chain), _ => None, }; - self.fixed_chain = match &self.chain { - Some(chain) => match Chain::create_fixed(chain.certs()) { - Ok(chain) => Some(chain), - _ => None, - }, - _ => None, - }; + self.fixed_chain = fixed_chain(&self.chain); self.output = Content::default(); } _ => self.ca_file = File::None, @@ -205,7 +197,7 @@ impl Ui { self.key_indicator_state = self.key_indicator_state(); Task::done(Message::Print) } - Message::Print => { + Message::Print | Message::PrintPem => { match self.print_output() { Ok(output) => { self.output = Content::with_text(output.as_str()); @@ -219,20 +211,6 @@ impl Ui { }; 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::(value), Message::Cleanup => { if let Some(chain) = self.fixed_chain.take() {