am 593786c9: Merge "keymaster HAL users don\'t need delete_keypair"

* commit '593786c9b885a48a2674e3ebb5c3bab265de2e51':
  keymaster HAL users don't need delete_keypair
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index 6f506dd..d90b999 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -1156,19 +1156,25 @@
         return responseCode;
     }
 
+    ResponseCode rc = NO_ERROR;
+
     const keymaster_device_t* device = keyStore->getDevice();
     if (device == NULL) {
-        return SYSTEM_ERROR;
+        rc = SYSTEM_ERROR;
+    } else {
+        // A device doesn't have to implement delete_keypair.
+        if (device->delete_keypair != NULL) {
+            if (device->delete_keypair(device, keyBlob.getValue(), keyBlob.getLength())) {
+                rc = SYSTEM_ERROR;
+            }
+        }
     }
 
-    if (device->delete_keypair == NULL) {
-        ALOGE("device has no delete_keypair implementation!");
-        return SYSTEM_ERROR;
+    if (rc != NO_ERROR) {
+        return rc;
     }
 
-    int rc = device->delete_keypair(device, keyBlob.getValue(), keyBlob.getLength());
-
-    return rc ? SYSTEM_ERROR : NO_ERROR;
+    return (unlink(filename) && errno != ENOENT) ? SYSTEM_ERROR : NO_ERROR;
 }
 
 static ResponseCode sign(KeyStore* keyStore, int sock, uid_t uid, Value* keyName, Value* data,