keyfork-shard: display error message on duplicate key fingerprints found

This commit is contained in:
Ryan Heywood 2024-04-24 13:27:34 -04:00
parent 23db50956f
commit e0687434ef
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 19 additions and 2 deletions

View File

@ -205,11 +205,20 @@ impl<P: PromptHandler> OpenPGP<P> {
pub fn discover_certs(path: impl AsRef<Path>) -> Result<Vec<Cert>> { pub fn discover_certs(path: impl AsRef<Path>) -> Result<Vec<Cert>> {
let path = path.as_ref(); let path = path.as_ref();
let mut pubkeys = std::collections::HashSet::new();
let mut certs = HashMap::new(); let mut certs = HashMap::new();
if path.is_file() { if path.is_file() {
for maybe_cert in CertParser::from_file(path).map_err(Error::Sequoia)? { for maybe_cert in CertParser::from_file(path).map_err(Error::Sequoia)? {
let cert = maybe_cert.map_err(Error::Sequoia)?; let cert = maybe_cert.map_err(Error::Sequoia)?;
certs.insert(cert.fingerprint(), cert); let certfp = cert.fingerprint();
for key in cert.keys() {
let fp = key.fingerprint();
if pubkeys.contains(&fp) {
eprintln!("Received duplicate key: {fp} in public key: {certfp}");
}
pubkeys.insert(fp);
}
certs.insert(certfp, cert);
} }
} else { } else {
for entry in path for entry in path
@ -219,7 +228,15 @@ impl<P: PromptHandler> OpenPGP<P> {
.filter(|p| p.path().is_file()) .filter(|p| p.path().is_file())
{ {
let cert = Cert::from_file(entry.path()).map_err(Error::Sequoia)?; let cert = Cert::from_file(entry.path()).map_err(Error::Sequoia)?;
certs.insert(cert.fingerprint(), cert); let certfp = cert.fingerprint();
for key in cert.keys() {
let fp = key.fingerprint();
if pubkeys.contains(&fp) {
eprintln!("Received duplicate key: {fp} in public key: {certfp}");
}
pubkeys.insert(fp);
}
certs.insert(certfp, cert);
} }
} }
Ok(certs.into_values().collect()) Ok(certs.into_values().collect())