Use SwiftFormat version 0.47.x
This commit is contained in:
parent
e8389eb262
commit
49c6b25611
18 changed files with 69 additions and 49 deletions
|
|
@ -72,7 +72,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
func decrypt(encryptedData: Data, keyID: String, passphrase: String) throws -> Data? {
|
||||
guard let key = privateKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let privateKey = privateKeys[key.key] else {
|
||||
let privateKey = privateKeys[key.key] else {
|
||||
throw AppError.decryption
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ struct GopenPGPInterface: PGPInterface {
|
|||
|
||||
func encrypt(plainData: Data, keyID: String) throws -> Data {
|
||||
guard let key = publicKeys.first(where: { key, _ in key.hasSuffix(keyID.lowercased()) }),
|
||||
let publicKey = publicKeys[key.key] else {
|
||||
let publicKey = publicKeys[key.key] else {
|
||||
throw AppError.encryption
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ 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 {
|
||||
let privateKey: String = keyStore.get(for: PgpKey.PRIVATE.getKeychainKey()) else {
|
||||
pgpInterface = nil
|
||||
throw AppError.keyImport
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,21 +6,21 @@
|
|||
// Copyright © 2019 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
extension String {
|
||||
public func localize() -> String {
|
||||
public extension String {
|
||||
func localize() -> String {
|
||||
// swiftlint:disable:next nslocalizedstring_key
|
||||
NSLocalizedString(self, bundle: Bundle.main, value: "#\(self)#", comment: "")
|
||||
}
|
||||
|
||||
public func localize(_ firstValue: CVarArg) -> String {
|
||||
func localize(_ firstValue: CVarArg) -> String {
|
||||
String(format: localize(), firstValue)
|
||||
}
|
||||
|
||||
public func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
|
||||
func localize(_ firstValue: CVarArg, _ secondValue: CVarArg) -> String {
|
||||
String(format: localize(), firstValue, secondValue)
|
||||
}
|
||||
|
||||
public func localize(_ error: Error) -> String {
|
||||
func localize(_ error: Error) -> String {
|
||||
localize(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,25 @@
|
|||
// Copyright © 2018 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
extension String {
|
||||
public var trimmed: String {
|
||||
public extension String {
|
||||
var trimmed: String {
|
||||
trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
|
||||
public func stringByAddingPercentEncodingForRFC3986() -> String? {
|
||||
func stringByAddingPercentEncodingForRFC3986() -> String? {
|
||||
let unreserved = "-._~/?"
|
||||
var allowed = CharacterSet.alphanumerics
|
||||
allowed.insert(charactersIn: unreserved)
|
||||
return addingPercentEncoding(withAllowedCharacters: allowed)
|
||||
}
|
||||
|
||||
public func splitByNewline() -> [String] {
|
||||
func splitByNewline() -> [String] {
|
||||
split(omittingEmptySubsequences: false) { $0 == "\n" || $0 == "\r\n" }.map(String.init)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
public static func | (left: String, right: String) -> String {
|
||||
public extension String {
|
||||
static func | (left: String, right: String) -> String {
|
||||
right.isEmpty ? left : left + "\n" + right
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,32 +9,32 @@
|
|||
import Foundation
|
||||
import UIKit
|
||||
|
||||
extension UIAlertAction {
|
||||
public static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
public extension UIAlertAction {
|
||||
static func cancelAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
cancel { _ in
|
||||
controller.navigationController?.popViewController(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
public static func cancel(title: String = "Cancel".localize(), handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
static func cancel(title: String = "Cancel".localize(), handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
UIAlertAction(title: title, style: .cancel, handler: handler)
|
||||
}
|
||||
|
||||
public static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
static func dismiss(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
cancel(title: "Dismiss".localize(), handler: handler)
|
||||
}
|
||||
|
||||
public static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
static func ok(handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction {
|
||||
UIAlertAction(title: "Ok".localize(), style: .default, handler: handler)
|
||||
}
|
||||
|
||||
public static func okAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
static func okAndPopView(controller: UIViewController) -> UIAlertAction {
|
||||
ok { _ in
|
||||
controller.navigationController?.popViewController(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
public static func selectKey(controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
|
||||
static func selectKey(controller: UIViewController, handler: ((UIAlertAction) -> Void)?) -> UIAlertAction {
|
||||
UIAlertAction(title: "Select Key", style: .default) { _ in
|
||||
let selectKeyAlert = UIAlertController(title: "Select from imported keys", message: nil, preferredStyle: .actionSheet)
|
||||
try? PGPAgent.shared.getShortKeyID().forEach { keyID in
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
// Copyright © 2017 Yishi Lin. All rights reserved.
|
||||
//
|
||||
|
||||
extension UIViewController {
|
||||
public extension UIViewController {
|
||||
@objc
|
||||
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
if textField.nextField != nil {
|
||||
textField.nextField?.becomeFirstResponder()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@
|
|||
import Foundation
|
||||
import SwiftyUserDefaults
|
||||
|
||||
extension PasswordEntity {
|
||||
public var nameWithCategory: String {
|
||||
public extension PasswordEntity {
|
||||
var nameWithCategory: String {
|
||||
if let path = path, path.hasSuffix(".gpg") {
|
||||
return String(path.prefix(upTo: path.index(path.endIndex, offsetBy: -4)))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
public func getCategoryText() -> String {
|
||||
func getCategoryText() -> String {
|
||||
getCategoryArray().joined(separator: " > ")
|
||||
}
|
||||
|
||||
public func getCategoryArray() -> [String] {
|
||||
func getCategoryArray() -> [String] {
|
||||
var parentEntity = parent
|
||||
var passwordCategoryArray: [String] = []
|
||||
while parentEntity != nil {
|
||||
|
|
@ -32,7 +32,7 @@ extension PasswordEntity {
|
|||
return passwordCategoryArray
|
||||
}
|
||||
|
||||
public func getURL() throws -> URL {
|
||||
func getURL() throws -> URL {
|
||||
if let path = getPath().stringByAddingPercentEncodingForRFC3986(), let url = URL(string: path) {
|
||||
return url
|
||||
}
|
||||
|
|
@ -42,16 +42,16 @@ extension PasswordEntity {
|
|||
// XXX: define some getters to get core data, we need to consider
|
||||
// manually write models instead auto generation.
|
||||
|
||||
public func getImage() -> Data? {
|
||||
func getImage() -> Data? {
|
||||
image
|
||||
}
|
||||
|
||||
public func getName() -> String {
|
||||
func getName() -> String {
|
||||
// unwrap non-optional core data
|
||||
name ?? ""
|
||||
}
|
||||
|
||||
public func getPath() -> String {
|
||||
func getPath() -> String {
|
||||
// unwrap non-optional core data
|
||||
path ?? ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -645,8 +645,8 @@ public class PasswordStore {
|
|||
}
|
||||
// get the oldest local commit
|
||||
guard let firstLocalCommit = localCommits.last,
|
||||
firstLocalCommit.parents.count == 1,
|
||||
let newHead = firstLocalCommit.parents.first else {
|
||||
firstLocalCommit.parents.count == 1,
|
||||
let newHead = firstLocalCommit.parents.first else {
|
||||
throw AppError.gitReset
|
||||
}
|
||||
try storeRepository.reset(to: newHead, resetType: .hard)
|
||||
|
|
@ -707,7 +707,7 @@ public class PasswordStore {
|
|||
public func findGPGID(from url: URL) -> String {
|
||||
var path = url
|
||||
while !FileManager.default.fileExists(atPath: path.appendingPathComponent(".gpg-id").path),
|
||||
path.path != "file:///" {
|
||||
path.path != "file:///" {
|
||||
path = path.deletingLastPathComponent()
|
||||
}
|
||||
path = path.appendingPathComponent(".gpg-id")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public struct PasswordGenerator: Codable {
|
|||
return ["eff_long_wordlist", "eff_short_wordlist"]
|
||||
.map { name -> String in
|
||||
guard let asset = NSDataAsset(name: name, bundle: bundle),
|
||||
let data = String(data: asset.data, encoding: .utf8) else {
|
||||
let data = String(data: asset.data, encoding: .utf8) else {
|
||||
return ""
|
||||
}
|
||||
return data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue