db,hagridctl: Autofix clippy issues

This commit is contained in:
Nora Widdecke 2022-03-03 15:41:52 +01:00 committed by Vincent Breitmoser
parent 1802cc6811
commit e00cae5a4e
4 changed files with 38 additions and 43 deletions

View File

@ -837,24 +837,25 @@ mod tests {
.unwrap() .unwrap()
.0; .0;
assert!(db.merge(k1).unwrap().into_tpk_status().email_status.len() > 0); assert!(!db
assert!( .merge(k1)
db.merge(k2.clone()) .unwrap()
.unwrap() .into_tpk_status()
.into_tpk_status() .email_status
.email_status .is_empty());
.len() assert!(!db
> 0 .merge(k2.clone())
); .unwrap()
.into_tpk_status()
.email_status
.is_empty());
assert!(!db.merge(k2).unwrap().into_tpk_status().email_status.len() > 0); assert!(!db.merge(k2).unwrap().into_tpk_status().email_status.len() > 0);
assert!( assert!(!db
db.merge(k3.clone()) .merge(k3.clone())
.unwrap() .unwrap()
.into_tpk_status() .into_tpk_status()
.email_status .email_status
.len() .is_empty());
> 0
);
assert!( assert!(
!db.merge(k3.clone()) !db.merge(k3.clone())
.unwrap() .unwrap()

View File

@ -100,7 +100,7 @@ pub fn test_uid_verification(db: &mut impl Database, log_path: &Path) {
let raw = db.by_fpr(&fpr).unwrap(); let raw = db.by_fpr(&fpr).unwrap();
let key = Cert::from_bytes(raw.as_bytes()).unwrap(); let key = Cert::from_bytes(raw.as_bytes()).unwrap();
assert!(key.userids().skip(1).next().is_none()); assert!(key.userids().nth(1).is_none());
assert!(key.user_attributes().next().is_none()); assert!(key.user_attributes().next().is_none());
assert!(key.keys().subkeys().next().is_none()); assert!(key.keys().subkeys().next().is_none());
@ -128,7 +128,7 @@ pub fn test_uid_verification(db: &mut impl Database, log_path: &Path) {
let raw = db.by_fpr(&fpr).unwrap(); let raw = db.by_fpr(&fpr).unwrap();
let key = Cert::from_bytes(raw.as_bytes()).unwrap(); let key = Cert::from_bytes(raw.as_bytes()).unwrap();
assert!(key.userids().skip(1).next().is_none()); assert!(key.userids().nth(1).is_none());
assert!(key.user_attributes().next().is_none()); assert!(key.user_attributes().next().is_none());
assert!(key.keys().subkeys().next().is_none()); assert!(key.keys().subkeys().next().is_none());
@ -161,7 +161,7 @@ pub fn test_uid_verification(db: &mut impl Database, log_path: &Path) {
assert!(key.keys().subkeys().next().is_none()); assert!(key.keys().subkeys().next().is_none());
let myuid1 = key.userids().next().unwrap().userid().clone(); let myuid1 = key.userids().next().unwrap().userid().clone();
let myuid2 = key.userids().skip(1).next().unwrap().userid().clone(); let myuid2 = key.userids().nth(1).unwrap().userid().clone();
assert_eq!(db.by_email(&email1).unwrap(), raw); assert_eq!(db.by_email(&email1).unwrap(), raw);
assert_eq!(db.by_email(&email2).unwrap(), raw); assert_eq!(db.by_email(&email2).unwrap(), raw);
@ -208,7 +208,7 @@ pub fn test_uid_verification(db: &mut impl Database, log_path: &Path) {
assert!(key.keys().subkeys().next().is_none()); assert!(key.keys().subkeys().next().is_none());
let myuid1 = key.userids().next().unwrap().userid().clone(); let myuid1 = key.userids().next().unwrap().userid().clone();
let myuid2 = key.userids().skip(1).next().unwrap().userid().clone(); let myuid2 = key.userids().nth(1).unwrap().userid().clone();
assert_eq!(db.by_email(&email1).unwrap(), raw); assert_eq!(db.by_email(&email1).unwrap(), raw);
assert_eq!(db.by_email(&email2).unwrap(), raw); assert_eq!(db.by_email(&email2).unwrap(), raw);
@ -1331,7 +1331,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
// Have Alice certify the binding between "bob@bar.com" and // Have Alice certify the binding between "bob@bar.com" and
// Bob's key. // Bob's key.
let alice_certifies_bob = bob.userids().nth(0).unwrap().userid().bind( let alice_certifies_bob = bob.userids().next().unwrap().userid().bind(
&mut alice_signer, &mut alice_signer,
&bob, &bob,
SignatureBuilder::new(SignatureType::GenericCertification) SignatureBuilder::new(SignatureType::GenericCertification)
@ -1361,7 +1361,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
check_log_entry(log_path, &bobs_fp); check_log_entry(log_path, &bobs_fp);
let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?; let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?;
assert_eq!(bob_.bad_signatures().count(), 0); assert_eq!(bob_.bad_signatures().count(), 0);
assert_eq!(bob_.userids().nth(0).unwrap().certifications().count(), 0); assert_eq!(bob_.userids().next().unwrap().certifications().count(), 0);
// Add the attestation, merge into the db, check that the // Add the attestation, merge into the db, check that the
// certification is now included. // certification is now included.
@ -1370,11 +1370,11 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
check_log_entry(log_path, &bobs_fp); check_log_entry(log_path, &bobs_fp);
let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?; let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?;
assert_eq!(bob_.bad_signatures().count(), 0); assert_eq!(bob_.bad_signatures().count(), 0);
assert_eq!(bob_.userids().nth(0).unwrap().certifications().count(), 1); assert_eq!(bob_.userids().next().unwrap().certifications().count(), 1);
assert_eq!( assert_eq!(
bob_.with_policy(&POLICY, None)? bob_.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attestation_key_signatures() .attestation_key_signatures()
.count(), .count(),
@ -1383,7 +1383,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
assert_eq!( assert_eq!(
bob_.with_policy(&POLICY, None)? bob_.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attested_certifications() .attested_certifications()
.count(), .count(),
@ -1396,7 +1396,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
check_log_entry(log_path, &bobs_fp); check_log_entry(log_path, &bobs_fp);
let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?; let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?;
assert_eq!(bob_.bad_signatures().count(), 0); assert_eq!(bob_.bad_signatures().count(), 0);
assert_eq!(bob_.userids().nth(0).unwrap().certifications().count(), 1); assert_eq!(bob_.userids().next().unwrap().certifications().count(), 1);
// Finally, withdraw consent by overriding the attestation, merge // Finally, withdraw consent by overriding the attestation, merge
// into the db, check that the certification is now gone. // into the db, check that the certification is now gone.
@ -1409,11 +1409,11 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
let clear_attestation = attestations[0].clone(); let clear_attestation = attestations[0].clone();
let bob = bob.insert_packets(vec![clear_attestation])?; let bob = bob.insert_packets(vec![clear_attestation])?;
assert_eq!(bob.userids().nth(0).unwrap().certifications().count(), 1); assert_eq!(bob.userids().next().unwrap().certifications().count(), 1);
assert_eq!( assert_eq!(
bob.with_policy(&POLICY, None)? bob.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attestation_key_signatures() .attestation_key_signatures()
.count(), .count(),
@ -1422,7 +1422,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
assert_eq!( assert_eq!(
bob.with_policy(&POLICY, None)? bob.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attested_certifications() .attested_certifications()
.count(), .count(),
@ -1433,11 +1433,11 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
check_log_entry(log_path, &bobs_fp); check_log_entry(log_path, &bobs_fp);
let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?; let bob_ = Cert::from_bytes(&db.by_fpr(&bobs_fp).unwrap())?;
assert_eq!(bob_.bad_signatures().count(), 0); assert_eq!(bob_.bad_signatures().count(), 0);
assert_eq!(bob_.userids().nth(0).unwrap().certifications().count(), 0); assert_eq!(bob_.userids().next().unwrap().certifications().count(), 0);
assert_eq!( assert_eq!(
bob_.with_policy(&POLICY, None)? bob_.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attestation_key_signatures() .attestation_key_signatures()
.count(), .count(),
@ -1446,7 +1446,7 @@ pub fn attested_key_signatures(db: &mut impl Database, log_path: &Path) -> Resul
assert_eq!( assert_eq!(
bob_.with_policy(&POLICY, None)? bob_.with_policy(&POLICY, None)?
.userids() .userids()
.nth(0) .next()
.unwrap() .unwrap()
.attested_certifications() .attested_certifications()
.count(), .count(),

View File

@ -151,20 +151,14 @@ fn import_from_file(db: &KeyDatabase, input: &Path, multi_progress: &MultiProgre
read_file_to_tpks(input_reader, &mut |acc| { read_file_to_tpks(input_reader, &mut |acc| {
let primary_key = acc[0].clone(); let primary_key = acc[0].clone();
let result = import_key(&db, acc); let result = import_key(db, acc);
if let Err(ref e) = result { if let Err(ref e) = result {
let key_fpr = match primary_key { let key_fpr = match primary_key {
Packet::PublicKey(key) => key.fingerprint().to_hex(), Packet::PublicKey(key) => key.fingerprint().to_hex(),
Packet::SecretKey(key) => key.fingerprint().to_hex(), Packet::SecretKey(key) => key.fingerprint().to_hex(),
_ => "Unknown".to_owned(), _ => "Unknown".to_owned(),
}; };
let error = format!( let error = format!("{}:{:05}:{}: {}", filename, stats.count_total, key_fpr, e);
"{}:{:05}:{}: {}",
filename,
stats.count_total,
key_fpr,
e.to_string()
);
progress_bar.println(error); progress_bar.println(error);
} }
stats.update(result); stats.update(result);
@ -176,7 +170,7 @@ fn import_from_file(db: &KeyDatabase, input: &Path, multi_progress: &MultiProgre
fn read_file_to_tpks( fn read_file_to_tpks(
reader: impl Read + Send + Sync, reader: impl Read + Send + Sync,
callback: &mut impl FnMut(Vec<Packet>) -> (), callback: &mut impl FnMut(Vec<Packet>),
) -> Result<()> { ) -> Result<()> {
let mut ppr = PacketParser::from_reader(reader)?; let mut ppr = PacketParser::from_reader(reader)?;
let mut acc = Vec::new(); let mut acc = Vec::new();

View File

@ -46,7 +46,7 @@ impl<'a> RegenerateStats<'a> {
} }
match result { match result {
Err(e) => { Err(e) => {
self.progress.println(format!("{}: {}", fpr, e.to_string())); self.progress.println(format!("{}: {}", fpr, e));
self.count_err += 1; self.count_err += 1;
} }
Ok(RegenerateResult::Updated) => self.count_updated += 1, Ok(RegenerateResult::Updated) => self.count_updated += 1,