From 3e031006dfce225458dc68fff80bcbe7b87dbcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 2 Aug 2024 09:49:45 +0200 Subject: [PATCH] key deletion: delete first the faster volatile storage and test public keys first Most key deletions are for volatile public keys (temporary keys for FIDO pin protocol, PIN keys from trussed-auth etc...). In any cases, persistent keys are more rarely deleted, and volatile is the fastest storage, so it being first is overall a performance improvement. I think long term (once we have the builder-pattern based syscall implementation maybe?) we should add optional location and secrecy arguments to the syscall. It is rare that the caller would not know the kind of key it is deleting. --- src/store/keystore.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/store/keystore.rs b/src/store/keystore.rs index 01f12e22686..c31db885f2b 100644 --- a/src/store/keystore.rs +++ b/src/store/keystore.rs @@ -138,15 +138,15 @@ impl Keystore for ClientKeystore { // TODO: is this an Oracle? fn delete_key(&self, id: &KeyId) -> bool { - let secrecies = [key::Secrecy::Secret, key::Secrecy::Public]; + let secrecies = [key::Secrecy::Public, key::Secrecy::Secret]; - let locations = [Location::Internal, Location::External, Location::Volatile]; + let locations = [Location::Volatile, Location::Internal, Location::External]; - secrecies.iter().any(|secrecy| { - let path = self.key_path(*secrecy, id); - locations - .iter() - .any(|location| store::delete(self.store, *location, &path)) + locations.iter().any(|location| { + secrecies.iter().any(|secrecy| { + let path = self.key_path(*secrecy, id); + store::delete(self.store, *location, &path) + }) }) }