mirror of
https://github.com/pcvolkmer/cert-tools.git
synced 2025-04-19 17:06:49 +00:00
refactor: create fixed chain using reference to certs
This commit is contained in:
parent
3e19abd4db
commit
41ba88c0b6
@ -285,8 +285,8 @@ impl Chain {
|
|||||||
Self { certs }
|
Self { certs }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fixed_from(certs: Vec<Certificate>) -> Result<Chain, String> {
|
pub fn create_fixed(certs: &[Certificate]) -> Result<Chain, String> {
|
||||||
let mut certs = certs.iter().collect::<Vec<_>>();
|
let mut certs = certs.to_vec();
|
||||||
certs.sort_by(|cert1, cert2| {
|
certs.sort_by(|cert1, cert2| {
|
||||||
if cert1.subject_key_id() == cert2.authority_key_id() {
|
if cert1.subject_key_id() == cert2.authority_key_id() {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
@ -294,7 +294,7 @@ impl Chain {
|
|||||||
Ordering::Less
|
Ordering::Less
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let chain = Chain::from(certs.iter().unique().map(|&c| c.clone()).collect::<Vec<_>>());
|
let chain = Chain::from(certs.iter().unique().cloned().collect::<Vec<_>>());
|
||||||
if !chain.is_valid() {
|
if !chain.is_valid() {
|
||||||
return Err("Cannot merge files to valid chain - giving up!".to_string());
|
return Err("Cannot merge files to valid chain - giving up!".to_string());
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ impl Ui {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
self.fixed_chain = match &self.chain {
|
self.fixed_chain = match &self.chain {
|
||||||
Some(chain) => match Chain::fixed_from(chain.certs().to_vec()) {
|
Some(chain) => match Chain::create_fixed(chain.certs()) {
|
||||||
Ok(chain) => Some(chain),
|
Ok(chain) => Some(chain),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@ -130,7 +130,7 @@ impl Ui {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
self.fixed_chain = match &self.chain {
|
self.fixed_chain = match &self.chain {
|
||||||
Some(chain) => match Chain::fixed_from(chain.certs().to_vec()) {
|
Some(chain) => match Chain::create_fixed(chain.certs()) {
|
||||||
Ok(chain) => Some(chain),
|
Ok(chain) => Some(chain),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@ -156,7 +156,7 @@ impl Ui {
|
|||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
self.fixed_chain = match &self.chain {
|
self.fixed_chain = match &self.chain {
|
||||||
Some(chain) => match Chain::fixed_from(chain.certs().to_vec()) {
|
Some(chain) => match Chain::create_fixed(chain.certs()) {
|
||||||
Ok(chain) => Some(chain),
|
Ok(chain) => Some(chain),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user