Allow setting a nil value in AppKeychain.add to delete existing content

This commit is contained in:
Danny Moesch 2019-07-03 22:55:37 +02:00 committed by Mingshen Sun
parent fa2fde1af4
commit cc493cb490
2 changed files with 6 additions and 12 deletions

View file

@ -14,11 +14,11 @@ public class AppKeychain {
.accessibility(.whenUnlockedThisDeviceOnly)
.synchronizable(false)
public static func add(data: Data, for key: String) {
public static func add(data: Data?, for key: String) {
keychain[data: key] = data
}
public static func add(string: String, for key: String) {
public static func add(string: String?, for key: String) {
keychain[key] = string
}

View file

@ -45,9 +45,7 @@ public class PasswordStore {
public var pgpKeyPassphrase: String? {
set {
if newValue != nil {
AppKeychain.add(string: newValue!, for: "pgpKeyPassphrase")
}
AppKeychain.add(string: newValue, for: "pgpKeyPassphrase")
}
get {
return AppKeychain.get(for: "pgpKeyPassphrase")
@ -56,9 +54,7 @@ public class PasswordStore {
public var gitPassword: String? {
set {
if newValue != nil {
AppKeychain.add(string: newValue!, for: "gitPassword")
}
AppKeychain.add(string: newValue, for: "gitPassword")
}
get {
return AppKeychain.get(for: "gitPassword")
@ -67,9 +63,7 @@ public class PasswordStore {
public var gitSSHPrivateKeyPassphrase: String? {
set {
if newValue != nil {
AppKeychain.add(string: newValue!, for: "gitSSHPrivateKeyPassphrase")
}
AppKeychain.add(string: newValue, for: "gitSSHPrivateKeyPassphrase")
}
get {
return AppKeychain.get(for: "gitSSHPrivateKeyPassphrase")
@ -834,9 +828,9 @@ public class PasswordStore {
SharedDefaults.remove(.pgpPublicKeyURL)
SharedDefaults.remove(.pgpPublicKeyArmor)
SharedDefaults.remove(.pgpPrivateKeyArmor)
AppKeychain.removeContent(for: "pgpKeyPassphrase")
AppKeychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
AppKeychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
pgpKeyPassphrase = nil
publicKey = nil
privateKey = nil
}