Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions keymaster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand Down