1
0
mirror of https://github.com/pcvolkmer/cert-tools.git synced 2025-09-13 11:12:52 +00:00

feat: keep current files on file pick abort

This commit is contained in:
2025-09-08 13:08:21 +02:00
parent 12868f3c50
commit 4736efb6c5

View File

@@ -145,78 +145,66 @@ impl Ui {
Task::done(Message::Print) Task::done(Message::Print)
} }
Message::SetCertFile(file) => { Message::SetCertFile(file) => {
match file { if let Ok(file) = file {
Ok(file) => { if file.to_str().unwrap_or_default().to_lowercase().ends_with(".p12") {
if file.to_str().unwrap_or_default().to_lowercase().ends_with(".p12") { self.cert_file = File::Certificates(file, Box::new(Chain::from(vec![])));
self.cert_file = File::Certificates(file, Box::new(Chain::from(vec![]))); return Task::done(Message::AskForImportPassword)
return Task::done(Message::AskForImportPassword)
}
self.cert_file = match Chain::read(&file) {
Ok(chain) => File::Certificates(file, Box::new(chain)),
Err(_) => File::Invalid(file),
};
self.chain = self.load_chain().ok();
self.fixed_chain = fixed_chain(&self.chain);
self.output = Content::default();
self.mode = UiMode::CertList;
} }
_ => self.cert_file = File::None, self.cert_file = match Chain::read(&file) {
Ok(chain) => File::Certificates(file, Box::new(chain)),
Err(_) => File::Invalid(file),
};
self.chain = self.load_chain().ok();
self.fixed_chain = fixed_chain(&self.chain);
self.output = Content::default();
self.mode = UiMode::CertList;
}; };
self.chain_indicator_state = self.chain_indicator_state(); self.chain_indicator_state = self.chain_indicator_state();
Task::done(Message::Print) Task::done(Message::Print)
} }
Message::SetCaFile(file) => { Message::SetCaFile(file) => {
match file { if let Ok(file) = file {
Ok(file) => { self.ca_file = match Chain::read(&file) {
self.ca_file = match Chain::read(&file) { Ok(chain) => File::Certificates(file, Box::new(chain)),
Ok(chain) => File::Certificates(file, Box::new(chain)), Err(_) => File::Invalid(file),
Err(_) => File::Invalid(file), };
}; self.chain = self.load_chain().ok();
self.chain = self.load_chain().ok(); self.fixed_chain = fixed_chain(&self.chain);
self.fixed_chain = fixed_chain(&self.chain); self.output = Content::default();
self.output = Content::default();
}
_ => self.ca_file = File::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)
} }
Message::SetKeyFile(file) => { Message::SetKeyFile(file) => {
match file { if let Ok(file) = file {
Ok(file) => { self.key_file = match PrivateKey::read(&file) {
self.key_file = match PrivateKey::read(&file) { Ok(key) => File::PrivateKey(file, Box::new(key)),
Ok(key) => File::PrivateKey(file, Box::new(key)), Err(_) => File::Invalid(file),
Err(_) => File::Invalid(file), };
};
}
_ => self.key_file = File::None,
}; };
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::SetPkcs12File(file) => { Message::SetPkcs12File(file) => {
match file { if let Ok(file) = file {
Ok(file) => { let (cert_file, key_file) = match read_p12_file(&file, &self.password_1) {
let (cert_file, key_file) = match read_p12_file(&file, &self.password_1) { Ok((chain, key)) => (
Ok((chain, key)) => ( File::Certificates(file.clone(), Box::new(chain)),
File::Certificates(file.clone(), Box::new(chain)), File::PrivateKey(file, Box::new(key))
File::PrivateKey(file, Box::new(key)) ),
), Err(_) => (
Err(_) => ( File::Invalid(file.clone()),
File::Invalid(file.clone()), File::Invalid(file)
File::Invalid(file) )
) };
}; self.cert_file = cert_file;
self.cert_file = cert_file; self.key_file = key_file;
self.key_file = key_file; self.chain = self.load_chain().ok();
self.chain = self.load_chain().ok(); self.fixed_chain = fixed_chain(&self.chain);
self.fixed_chain = fixed_chain(&self.chain); self.output = Content::default();
self.output = Content::default(); self.mode = UiMode::CertList;
self.mode = UiMode::CertList; self.password_1 = String::new();
self.password_1 = String::new(); self.password_2 = String::new();
self.password_2 = String::new();
}
_ => self.cert_file = File::None
} }
self.chain_indicator_state = self.chain_indicator_state(); self.chain_indicator_state = self.chain_indicator_state();
self.key_indicator_state = self.key_indicator_state(); self.key_indicator_state = self.key_indicator_state();