mirror of
https://gitlab.com/hagrid-keyserver/hagrid.git
synced 2023-02-13 20:55:02 -05:00
parent
3e81d2dc17
commit
667980848a
2 changed files with 20 additions and 6 deletions
|
@ -529,6 +529,24 @@ pub trait Database: Sync + Send {
|
|||
self.filter_userids(fpr, |_| false)
|
||||
}
|
||||
|
||||
/// Deletes all UserID packets matching `addr` (see [RFC2822
|
||||
/// name-addr] and unlinks the email addresses.
|
||||
///
|
||||
/// [RFC2822 name-addr]: https://tools.ietf.org/html/rfc2822#section-3.4
|
||||
fn delete_userids_matching(&self, fpr: &Fingerprint, addr: &Email)
|
||||
-> Result <()> {
|
||||
self.filter_userids(fpr, |uid| {
|
||||
match Email::try_from(uid) {
|
||||
// Keep those not matching `addr`.
|
||||
Ok(a) => a != *addr,
|
||||
// This should not happen, because all TPKs in the
|
||||
// database should only have UserIDs with well-formed
|
||||
// values. Be conservative and keep the component.
|
||||
Err(_) => true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Deletes all user ids NOT matching fulfilling `filter`.
|
||||
///
|
||||
/// I.e. we retain fulfilling `filter`.
|
||||
|
|
|
@ -323,9 +323,7 @@ pub fn test_uid_deletion<D: Database>(db: &mut D) {
|
|||
let fpr = Fingerprint::try_from(tpk.fingerprint()).unwrap();
|
||||
|
||||
// Delete second UID.
|
||||
db.filter_userids(
|
||||
&fpr, |u| Email::try_from(u).map(|e| e != email2).unwrap_or(true))
|
||||
.unwrap();
|
||||
db.delete_userids_matching(&fpr, &email2).unwrap();
|
||||
|
||||
// Check that the second is still there, and that the TPK is
|
||||
// otherwise intact.
|
||||
|
@ -334,9 +332,7 @@ pub fn test_uid_deletion<D: Database>(db: &mut D) {
|
|||
assert_eq!(tpk.subkeys().count(), n_subkeys);
|
||||
|
||||
// Delete first UID.
|
||||
db.filter_userids(
|
||||
&fpr, |u| Email::try_from(u).map(|e| e != email1).unwrap_or(true))
|
||||
.unwrap();
|
||||
db.delete_userids_matching(&fpr, &email1).unwrap();
|
||||
|
||||
// Check that the second is still there, and that the TPK is
|
||||
// otherwise intact.
|
||||
|
|
Loading…
Reference in a new issue