diff --git a/keymaster.swift b/keymaster.swift index 747297e..31b42a4 100644 --- a/keymaster.swift +++ b/keymaster.swift @@ -71,19 +71,25 @@ func main() { } if (action == "set") { - context.evaluatePolicy(policy, localizedReason: "set to your password") { success, error in - guard setPassword(key: key, password: secret) else { - print("Error setting password") + context.evaluatePolicy(policy, localizedReason: "set the password for \(key)") { success, error in + if success && error == nil { + guard setPassword(key: key, password: secret) else { + print("Error setting password") + exit(EXIT_FAILURE) + } + print("Key \(key) has been successfully set in the keychain") + exit(EXIT_SUCCESS) + } else { + let errorDescription = error?.localizedDescription ?? "Unknown error" + print("Error \(errorDescription)") exit(EXIT_FAILURE) } - print("Key \(key) has been sucessfully set in the keychain") - exit(EXIT_SUCCESS) } dispatchMain() } if (action == "get") { - context.evaluatePolicy(policy, localizedReason: "access to your password") { success, error in + context.evaluatePolicy(policy, localizedReason: "access the password for \(key)") { success, error in if success && error == nil { guard let password = getPassword(key: key) else { print("Error getting password") @@ -101,13 +107,13 @@ func main() { } if (action == "delete") { - context.evaluatePolicy(policy, localizedReason: "delete your password") { success, error in + context.evaluatePolicy(policy, localizedReason: "delete the password for \(key)") { success, error in if success && error == nil { guard deletePassword(key: key) else { print("Error deleting password") exit(EXIT_FAILURE) } - print("Key \(key) has been sucessfully deleted from the keychain") + print("Key \(key) has been successfully deleted from the keychain") exit(EXIT_SUCCESS) } else { let errorDescription = error?.localizedDescription ?? "Unknown error"