Use SwiftFormat version 0.49.x and enable some new rules (#527)
This commit is contained in:
parent
b62c5fa2e5
commit
cdedff0d4d
32 changed files with 139 additions and 126 deletions
|
|
@ -189,7 +189,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
func forgotPasscodeButtonPressedAction(_: UIButton) {
|
||||
let alert = UIAlertController(title: "ResetPass".localize(), message: "ResetPassExplanation.".localize(), preferredStyle: UIAlertController.Style.alert)
|
||||
alert.addAction(
|
||||
UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ -> Void in
|
||||
UIAlertAction(title: "ErasePasswordStoreData".localize(), style: UIAlertAction.Style.destructive) { [unowned self] _ in
|
||||
let myContext = LAContext()
|
||||
// If the device passcode is not set, reset the app.
|
||||
guard myContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil) else {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
func extractKeysFromArmored(str: String) -> [String] {
|
||||
var keys: [String] = []
|
||||
var key: String = ""
|
||||
var key = ""
|
||||
for line in str.splitByNewline() {
|
||||
if line.trimmed.uppercased().hasPrefix("-----BEGIN PGP") {
|
||||
key = ""
|
||||
|
|
@ -100,7 +100,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
throw AppError.decryption
|
||||
}
|
||||
|
||||
let message = createPgpMessage(from: encryptedData)
|
||||
let message = createPGPMessage(from: encryptedData)
|
||||
return try keyRing.decrypt(message, verifyKey: nil, verifyTime: 0).data
|
||||
} catch {
|
||||
throw Self.errorMapping[error.localizedDescription, default: error]
|
||||
|
|
@ -148,7 +148,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
publicKeys.keys.map { $0.suffix(8).uppercased() }
|
||||
}
|
||||
|
||||
private func createPgpMessage(from encryptedData: Data) -> CryptoPGPMessage? {
|
||||
private func createPGPMessage(from encryptedData: Data) -> CryptoPGPMessage? {
|
||||
// Important note:
|
||||
// Even if Defaults.encryptInArmored is true now, it could be different during the encryption.
|
||||
var error: NSError?
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ public class PGPAgent {
|
|||
}
|
||||
|
||||
public func initKeys() throws {
|
||||
guard let publicKey: String = keyStore.get(for: PgpKey.PUBLIC.getKeychainKey()),
|
||||
let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else {
|
||||
guard let publicKey: String = keyStore.get(for: PGPKey.PUBLIC.getKeychainKey()),
|
||||
let privateKey: String = keyStore.get(for: PGPKey.PRIVATE.getKeychainKey()) else {
|
||||
pgpInterface = nil
|
||||
throw AppError.keyImport
|
||||
}
|
||||
|
|
@ -127,8 +127,8 @@ public class PGPAgent {
|
|||
}
|
||||
|
||||
public var isPrepared: Bool {
|
||||
keyStore.contains(key: PgpKey.PUBLIC.getKeychainKey())
|
||||
&& keyStore.contains(key: PgpKey.PRIVATE.getKeychainKey())
|
||||
keyStore.contains(key: PGPKey.PUBLIC.getKeychainKey())
|
||||
&& keyStore.contains(key: PGPKey.PRIVATE.getKeychainKey())
|
||||
}
|
||||
|
||||
private func checkAndInit() throws {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public protocol CryptographicKey {
|
|||
func getFileSharingPath() -> String
|
||||
}
|
||||
|
||||
public enum PgpKey: CryptographicKey {
|
||||
public enum PGPKey: CryptographicKey {
|
||||
case PUBLIC
|
||||
case PRIVATE
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public enum PgpKey: CryptographicKey {
|
|||
}
|
||||
}
|
||||
|
||||
public enum SshKey: CryptographicKey {
|
||||
public enum SSHKey: CryptographicKey {
|
||||
case PRIVATE
|
||||
|
||||
public func getKeychainKey() -> String {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ public extension FileManager {
|
|||
let contentItemURL = item as! NSURL
|
||||
|
||||
// Bail out on errors from the errorHandler.
|
||||
if let error = errorDidOccur { throw error }
|
||||
if let error = errorDidOccur {
|
||||
throw error
|
||||
}
|
||||
|
||||
let resourceValueForKey: (URLResourceKey) throws -> NSNumber? = { key in
|
||||
var value: AnyObject?
|
||||
|
|
@ -84,7 +86,9 @@ public extension FileManager {
|
|||
}
|
||||
|
||||
// Bail out on errors from the errorHandler.
|
||||
if let error = errorDidOccur { throw error }
|
||||
if let error = errorDidOccur {
|
||||
throw error
|
||||
}
|
||||
|
||||
// We finally got it.
|
||||
return accumulatedSize
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@
|
|||
public class KeyFileManager {
|
||||
public typealias KeyHandler = (String, String) -> Void
|
||||
|
||||
public static let PublicPgp = KeyFileManager(keyType: PgpKey.PUBLIC)
|
||||
public static let PrivatePgp = KeyFileManager(keyType: PgpKey.PRIVATE)
|
||||
public static let PrivateSsh = KeyFileManager(keyType: SshKey.PRIVATE)
|
||||
public static let PublicPGP = KeyFileManager(keyType: PGPKey.PUBLIC)
|
||||
public static let PrivatePGP = KeyFileManager(keyType: PGPKey.PRIVATE)
|
||||
public static let PrivateSSH = KeyFileManager(keyType: SSHKey.PRIVATE)
|
||||
|
||||
private let keyType: CryptographicKey
|
||||
private let keyPath: String
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public struct GitCredential {
|
|||
case .password:
|
||||
return Self(credentialType: .http(userName: userName), keyStore: keyStore)
|
||||
case .key:
|
||||
let privateKey: String = keyStore.get(for: SshKey.PRIVATE.getKeychainKey()) ?? ""
|
||||
let privateKey: String = keyStore.get(for: SSHKey.PRIVATE.getKeychainKey()) ?? ""
|
||||
return Self(credentialType: .ssh(userName: userName, privateKey: privateKey), keyStore: keyStore)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class Password {
|
|||
///
|
||||
/// otpauth://totp/totp-secret?secret=AAAAAAAAAAAAAAAA&issuer=totp-secret
|
||||
///
|
||||
/// See also [Key Uri Format](https://github.com/google/google-authenticator/wiki/Key-Uri-Format).
|
||||
/// See also [Key URI Format](https://github.com/google/google-authenticator/wiki/Key-URI-Format).
|
||||
///
|
||||
/// In case no otpauth is given in the password file, try to construct the token from separate fields using a
|
||||
/// `TokenBuilder`. This means that tokens provided as otpauth have higher priority.
|
||||
|
|
@ -150,7 +150,7 @@ public class Password {
|
|||
if !otpauthString.hasPrefix("\(Constants.OTPAUTH):") {
|
||||
otpauthString = "\(Constants.OTPAUTH):\(otpauthString)"
|
||||
}
|
||||
if let otpauthUrl = URL(string: otpauthString), let token = Token(url: otpauthUrl) {
|
||||
if let otpauthURL = URL(string: otpauthString), let token = Token(url: otpauthURL) {
|
||||
otpToken = token
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,14 +67,14 @@ public class PasswordStore {
|
|||
// Replace this implementation with code to handle the error appropriately.
|
||||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
|
||||
|
||||
/*
|
||||
Typical reasons for an error here include:
|
||||
* The parent directory does not exist, cannot be created, or disallows writing.
|
||||
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
|
||||
* The device is out of space.
|
||||
* The store could not be migrated to the current model version.
|
||||
Check the error message to determine what the actual problem was.
|
||||
*/
|
||||
// Typical reasons for an error here include:
|
||||
//
|
||||
// * The parent directory does not exist, cannot be created, or disallows writing.
|
||||
// * The persistent store is not accessible, due to permissions or data protection when the device is locked.
|
||||
// * The device is out of space.
|
||||
// * The store could not be migrated to the current model version.
|
||||
//
|
||||
// Check the error message to determine what the actual problem was.
|
||||
fatalError("UnresolvedError".localize("\(error.localizedDescription), \(error.userInfo)"))
|
||||
}
|
||||
}
|
||||
|
|
@ -128,9 +128,9 @@ public class PasswordStore {
|
|||
|
||||
private func importExistingKeysIntoKeychain() {
|
||||
// App Store update: v0.5.1 -> v0.6.0
|
||||
try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing()
|
||||
try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing()
|
||||
try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing()
|
||||
try? KeyFileManager(keyType: PGPKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyFromFileSharing()
|
||||
try? KeyFileManager(keyType: PGPKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyFromFileSharing()
|
||||
try? KeyFileManager(keyType: SSHKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyFromFileSharing()
|
||||
Defaults.remove(\.pgpPublicKeyArmor)
|
||||
Defaults.remove(\.pgpPrivateKeyArmor)
|
||||
Defaults.remove(\.gitSSHPrivateKeyArmor)
|
||||
|
|
@ -733,7 +733,7 @@ public class PasswordStore {
|
|||
Defaults.remove(\.gitSSHKeySource)
|
||||
Defaults.remove(\.gitSSHPrivateKeyArmor)
|
||||
Defaults.remove(\.gitSSHPrivateKeyURL)
|
||||
AppKeychain.shared.removeContent(for: SshKey.PRIVATE.getKeychainKey())
|
||||
AppKeychain.shared.removeContent(for: SSHKey.PRIVATE.getKeychainKey())
|
||||
gitSSHPrivateKeyPassphrase = nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue