Allow setting a nil value in AppKeychain.add to delete existing content
This commit is contained in:
parent
fa2fde1af4
commit
cc493cb490
2 changed files with 6 additions and 12 deletions
|
|
@ -14,11 +14,11 @@ public class AppKeychain {
|
||||||
.accessibility(.whenUnlockedThisDeviceOnly)
|
.accessibility(.whenUnlockedThisDeviceOnly)
|
||||||
.synchronizable(false)
|
.synchronizable(false)
|
||||||
|
|
||||||
public static func add(data: Data, for key: String) {
|
public static func add(data: Data?, for key: String) {
|
||||||
keychain[data: key] = data
|
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
|
keychain[key] = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ public class PasswordStore {
|
||||||
|
|
||||||
public var pgpKeyPassphrase: String? {
|
public var pgpKeyPassphrase: String? {
|
||||||
set {
|
set {
|
||||||
if newValue != nil {
|
AppKeychain.add(string: newValue, for: "pgpKeyPassphrase")
|
||||||
AppKeychain.add(string: newValue!, for: "pgpKeyPassphrase")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
get {
|
get {
|
||||||
return AppKeychain.get(for: "pgpKeyPassphrase")
|
return AppKeychain.get(for: "pgpKeyPassphrase")
|
||||||
|
|
@ -56,9 +54,7 @@ public class PasswordStore {
|
||||||
|
|
||||||
public var gitPassword: String? {
|
public var gitPassword: String? {
|
||||||
set {
|
set {
|
||||||
if newValue != nil {
|
AppKeychain.add(string: newValue, for: "gitPassword")
|
||||||
AppKeychain.add(string: newValue!, for: "gitPassword")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
get {
|
get {
|
||||||
return AppKeychain.get(for: "gitPassword")
|
return AppKeychain.get(for: "gitPassword")
|
||||||
|
|
@ -67,9 +63,7 @@ public class PasswordStore {
|
||||||
|
|
||||||
public var gitSSHPrivateKeyPassphrase: String? {
|
public var gitSSHPrivateKeyPassphrase: String? {
|
||||||
set {
|
set {
|
||||||
if newValue != nil {
|
AppKeychain.add(string: newValue, for: "gitSSHPrivateKeyPassphrase")
|
||||||
AppKeychain.add(string: newValue!, for: "gitSSHPrivateKeyPassphrase")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
get {
|
get {
|
||||||
return AppKeychain.get(for: "gitSSHPrivateKeyPassphrase")
|
return AppKeychain.get(for: "gitSSHPrivateKeyPassphrase")
|
||||||
|
|
@ -834,9 +828,9 @@ public class PasswordStore {
|
||||||
SharedDefaults.remove(.pgpPublicKeyURL)
|
SharedDefaults.remove(.pgpPublicKeyURL)
|
||||||
SharedDefaults.remove(.pgpPublicKeyArmor)
|
SharedDefaults.remove(.pgpPublicKeyArmor)
|
||||||
SharedDefaults.remove(.pgpPrivateKeyArmor)
|
SharedDefaults.remove(.pgpPrivateKeyArmor)
|
||||||
AppKeychain.removeContent(for: "pgpKeyPassphrase")
|
|
||||||
AppKeychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
|
AppKeychain.removeContent(for: PgpKey.PUBLIC.getKeychainKey())
|
||||||
AppKeychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
|
AppKeychain.removeContent(for: PgpKey.PRIVATE.getKeychainKey())
|
||||||
|
pgpKeyPassphrase = nil
|
||||||
publicKey = nil
|
publicKey = nil
|
||||||
privateKey = nil
|
privateKey = nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue