lint: delete trailing whitespaces
This commit is contained in:
parent
2ba6917710
commit
ed387069a4
59 changed files with 624 additions and 623 deletions
|
|
@ -11,7 +11,7 @@
|
|||
import UIKit
|
||||
|
||||
open class PasscodeLockPresenter {
|
||||
|
||||
|
||||
fileprivate var mainWindow: UIWindow?
|
||||
fileprivate var passcodeLockWindow: UIWindow?
|
||||
|
||||
|
|
@ -21,16 +21,16 @@ open class PasscodeLockPresenter {
|
|||
|
||||
open func present(windowLevel: CGFloat?) {
|
||||
guard PasscodeLock.shared.hasPasscode else { return }
|
||||
|
||||
|
||||
// dismiss the original window
|
||||
dismiss()
|
||||
|
||||
|
||||
// new window
|
||||
mainWindow?.endEditing(true)
|
||||
passcodeLockWindow = UIWindow(frame: self.mainWindow!.frame)
|
||||
moveWindowsToFront(windowLevel: windowLevel)
|
||||
passcodeLockWindow?.isHidden = false
|
||||
|
||||
|
||||
// new vc
|
||||
let passcodeLockVC = PasscodeLockViewController()
|
||||
let userDismissCompletionCallback = passcodeLockVC.dismissCompletionCallback
|
||||
|
|
|
|||
|
|
@ -12,23 +12,23 @@ import UIKit
|
|||
import LocalAuthentication
|
||||
|
||||
open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
||||
|
||||
|
||||
open var dismissCompletionCallback: (()->Void)?
|
||||
open var successCallback: (()->Void)?
|
||||
open var cancelCallback: (()->Void)?
|
||||
|
||||
|
||||
weak var passcodeLabel: UILabel?
|
||||
weak var passcodeWrongAttemptsLabel: UILabel?
|
||||
weak var passcodeTextField: UITextField?
|
||||
weak var biometryAuthButton: UIButton?
|
||||
open weak var cancelButton: UIButton?
|
||||
|
||||
|
||||
var passcodeFailedAttempts = 0
|
||||
var isCancellable: Bool = false
|
||||
|
||||
|
||||
open override func loadView() {
|
||||
super.loadView()
|
||||
|
||||
|
||||
let passcodeLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
|
||||
passcodeLabel.text = "Enter passcode for Pass"
|
||||
passcodeLabel.font = UIFont.boldSystemFont(ofSize: 18)
|
||||
|
|
@ -37,7 +37,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
passcodeLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.view.addSubview(passcodeLabel)
|
||||
self.passcodeLabel = passcodeLabel
|
||||
|
||||
|
||||
let passcodeWrongAttemptsLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
|
||||
passcodeWrongAttemptsLabel.text = ""
|
||||
passcodeWrongAttemptsLabel.textColor = UIColor.red
|
||||
|
|
@ -45,7 +45,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
passcodeWrongAttemptsLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.view.addSubview(passcodeWrongAttemptsLabel)
|
||||
self.passcodeWrongAttemptsLabel = passcodeWrongAttemptsLabel
|
||||
|
||||
|
||||
let passcodeTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
|
||||
passcodeTextField.borderStyle = UITextBorderStyle.roundedRect
|
||||
passcodeTextField.placeholder = "passcode"
|
||||
|
|
@ -57,7 +57,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
passcodeTextField.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.view.addSubview(passcodeTextField)
|
||||
self.passcodeTextField = passcodeTextField
|
||||
|
||||
|
||||
let biometryAuthButton = UIButton(type: .custom)
|
||||
biometryAuthButton.setTitle("", for: .normal)
|
||||
biometryAuthButton.setTitleColor(Globals.blue, for: .normal)
|
||||
|
|
@ -66,7 +66,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
biometryAuthButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.view.addSubview(biometryAuthButton)
|
||||
self.biometryAuthButton = biometryAuthButton
|
||||
|
||||
|
||||
let myContext = LAContext()
|
||||
var authError: NSError?
|
||||
if #available(iOS 8.0, macOS 10.12.1, *) {
|
||||
|
|
@ -81,7 +81,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
biometryAuthButton.isHidden = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let cancelButton = UIButton(type: .custom)
|
||||
cancelButton.setTitle("Cancel", for: .normal)
|
||||
cancelButton.setTitleColor(Globals.blue, for: .normal)
|
||||
|
|
@ -91,7 +91,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left
|
||||
self.view.addSubview(cancelButton)
|
||||
self.cancelButton = cancelButton
|
||||
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
passcodeTextField.widthAnchor.constraint(equalToConstant: 300),
|
||||
passcodeTextField.heightAnchor.constraint(equalToConstant: 40),
|
||||
|
|
@ -118,13 +118,13 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
cancelButton.topAnchor.constraint(equalTo: self.view.safeTopAnchor),
|
||||
cancelButton.leftAnchor.constraint(equalTo: self.view.safeLeftAnchor, constant: 20)
|
||||
])
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
open override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
}
|
||||
|
||||
|
||||
open override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
if let biometryAuthButton = biometryAuthButton {
|
||||
|
|
@ -137,7 +137,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
DispatchQueue.main.async {
|
||||
self.passcodeTextField?.text = ""
|
||||
}
|
||||
|
||||
|
||||
// pop
|
||||
if presentingViewController?.presentedViewController == self {
|
||||
// if presented as modal
|
||||
|
|
@ -160,16 +160,16 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
passcodeWrongAttemptsLabel?.text = ""
|
||||
dismissPasscodeLock(completionHandler: successCallback)
|
||||
}
|
||||
|
||||
|
||||
@objc func passcodeLockDidCancel() {
|
||||
dismissPasscodeLock(completionHandler: cancelCallback)
|
||||
}
|
||||
|
||||
|
||||
@objc func bioButtonPressedAction(_ uiButton: UIButton) {
|
||||
let myContext = LAContext()
|
||||
let myLocalizedReasonString = "Authentication is needed to access Pass."
|
||||
var authError: NSError?
|
||||
|
||||
|
||||
if #available(iOS 8.0, *) {
|
||||
if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
|
||||
myContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { success, evaluateError in
|
||||
|
|
@ -183,7 +183,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
if textField == passcodeTextField {
|
||||
if !PasscodeLock.shared.check(passcode: textField.text ?? "") {
|
||||
|
|
@ -198,13 +198,13 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
textField.resignFirstResponder()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@objc func passcodeTextFieldDidChange(_ textField: UITextField) {
|
||||
if PasscodeLock.shared.check(passcode: textField.text ?? "") {
|
||||
self.passcodeLockDidSucceed()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func setCancellable(_ isCancellable: Bool) {
|
||||
self.isCancellable = isCancellable
|
||||
cancelButton?.isHidden = !isCancellable
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ public extension DefaultsKeys {
|
|||
static let pgpKeySource = DefaultsKey<String?>("pgpKeySource")
|
||||
static let pgpPublicKeyURL = DefaultsKey<URL?>("pgpPublicKeyURL")
|
||||
static let pgpPrivateKeyURL = DefaultsKey<URL?>("pgpPrivateKeyURL")
|
||||
|
||||
|
||||
static let pgpPublicKeyArmor = DefaultsKey<String?>("pgpPublicKeyArmor")
|
||||
static let pgpPrivateKeyArmor = DefaultsKey<String?>("pgpPrivateKeyArmor")
|
||||
|
||||
|
||||
static let gitURL = DefaultsKey<URL?>("gitURL")
|
||||
static let gitAuthenticationMethod = DefaultsKey<String?>("gitAuthenticationMethod")
|
||||
static let gitUsername = DefaultsKey<String?>("gitUsername")
|
||||
|
|
@ -29,10 +29,10 @@ public extension DefaultsKeys {
|
|||
static let gitSignatureEmail = DefaultsKey<String?>("gitSignatureEmail")
|
||||
|
||||
static let lastSyncedTime = DefaultsKey<Date?>("lastSyncedTime")
|
||||
|
||||
|
||||
static let isTouchIDOn = DefaultsKey<Bool>("isTouchIDOn")
|
||||
static let passcodeKey = DefaultsKey<String?>("passcodeKey")
|
||||
|
||||
|
||||
static let isHideUnknownOn = DefaultsKey<Bool>("isHideUnknownOn")
|
||||
static let isHideOTPOn = DefaultsKey<Bool>("isHideOTPOn")
|
||||
static let isRememberPGPPassphraseOn = DefaultsKey<Bool>("isRememberPGPPassphraseOn")
|
||||
|
|
@ -40,6 +40,6 @@ public extension DefaultsKeys {
|
|||
static let isShowFolderOn = DefaultsKey<Bool>("isShowFolderOn")
|
||||
static let isSearchDefaultAll = DefaultsKey<Bool>("isSearchDefaultAll")
|
||||
static let passwordGeneratorFlavor = DefaultsKey<String>("passwordGeneratorFlavor")
|
||||
|
||||
|
||||
static let encryptInArmored = DefaultsKey<Bool>("encryptInArmored")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
|
||||
// https://gist.github.com/NikolaiRuhe/eeb135d20c84a7097516
|
||||
public extension FileManager {
|
||||
|
||||
|
||||
/// This method calculates the accumulated size of a directory on the volume in bytes.
|
||||
///
|
||||
/// As there's no simple way to get this information from the file system it has to crawl the entire hierarchy,
|
||||
|
|
@ -20,73 +20,73 @@ public extension FileManager {
|
|||
/// - note: There are a couple of oddities that are not taken into account (like symbolic links, meta data of
|
||||
/// directories, hard links, ...).
|
||||
func allocatedSizeOfDirectoryAtURL(directoryURL : URL) throws -> UInt64 {
|
||||
|
||||
|
||||
// We'll sum up content size here:
|
||||
var accumulatedSize = UInt64(0)
|
||||
|
||||
|
||||
// prefetching some properties during traversal will speed up things a bit.
|
||||
let prefetchedProperties = [
|
||||
URLResourceKey.isRegularFileKey,
|
||||
URLResourceKey.fileAllocatedSizeKey,
|
||||
URLResourceKey.totalFileAllocatedSizeKey,
|
||||
]
|
||||
|
||||
|
||||
// The error handler simply signals errors to outside code.
|
||||
var errorDidOccur: Error?
|
||||
let errorHandler: (URL, Error) -> Bool = { _, error in
|
||||
errorDidOccur = error
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// We have to enumerate all directory contents, including subdirectories.
|
||||
let enumerator = self.enumerator(at: directoryURL,
|
||||
includingPropertiesForKeys: prefetchedProperties,
|
||||
options: FileManager.DirectoryEnumerationOptions(),
|
||||
errorHandler: errorHandler)
|
||||
precondition(enumerator != nil)
|
||||
|
||||
|
||||
// Start the traversal:
|
||||
for item in enumerator! {
|
||||
let contentItemURL = item as! NSURL
|
||||
|
||||
|
||||
// Bail out on errors from the errorHandler.
|
||||
if let error = errorDidOccur { throw error }
|
||||
|
||||
|
||||
let resourceValueForKey: (URLResourceKey) throws -> NSNumber? = { key in
|
||||
var value: AnyObject?
|
||||
try contentItemURL.getResourceValue(&value, forKey: key)
|
||||
return value as? NSNumber
|
||||
}
|
||||
|
||||
|
||||
// Get the type of this item, making sure we only sum up sizes of regular files.
|
||||
guard let isRegularFile = try resourceValueForKey(URLResourceKey.isRegularFileKey) else {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
|
||||
guard isRegularFile.boolValue else {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// To get the file's size we first try the most comprehensive value in terms of what the file may use on disk.
|
||||
// This includes metadata, compression (on file system level) and block size.
|
||||
var fileSize = try resourceValueForKey(URLResourceKey.totalFileAllocatedSizeKey)
|
||||
|
||||
|
||||
// In case the value is unavailable we use the fallback value (excluding meta data and compression)
|
||||
// This value should always be available.
|
||||
fileSize = try fileSize ?? resourceValueForKey(URLResourceKey.fileAllocatedSizeKey)
|
||||
|
||||
|
||||
guard let size = fileSize else {
|
||||
preconditionFailure("huh? NSURLFileAllocatedSizeKey should always return a value")
|
||||
}
|
||||
|
||||
|
||||
// We're good, add up the value.
|
||||
accumulatedSize += size.uint64Value
|
||||
}
|
||||
|
||||
|
||||
// Bail out on errors from the errorHandler.
|
||||
if let error = errorDidOccur { throw error }
|
||||
|
||||
|
||||
// We finally got it.
|
||||
return accumulatedSize
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
import UIKit
|
||||
|
||||
public class Globals {
|
||||
|
||||
|
||||
// Legacy paths (not shared)
|
||||
public static let documentPathLegacy = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
|
||||
public static let libraryPathLegacy = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0];
|
||||
|
|
@ -19,11 +19,11 @@ public class Globals {
|
|||
public static let gitSSHPrivateKeyPathLegacy = "\(documentPathLegacy)/ssh_key"
|
||||
public static let gitSSHPrivateKeyURLLegacy = URL(fileURLWithPath: gitSSHPrivateKeyPathLegacy)
|
||||
public static let repositoryPathLegacy = "\(libraryPathLegacy)/password-store"
|
||||
|
||||
|
||||
public static let bundleIdentifier = "me.mssun.passforios"
|
||||
public static let groupIdentifier = "group." + bundleIdentifier
|
||||
public static let passKitBundleIdentifier = bundleIdentifier + ".passKit"
|
||||
|
||||
|
||||
public static let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)!
|
||||
public static let documentPath = sharedContainerURL.appendingPathComponent("Documents").path
|
||||
public static let libraryPath = sharedContainerURL.appendingPathComponent("Library").path
|
||||
|
|
@ -33,19 +33,19 @@ public class Globals {
|
|||
public static let gitSSHPrivateKeyURL = URL(fileURLWithPath: gitSSHPrivateKeyPath)
|
||||
public static let repositoryPath = libraryPath + "/password-store"
|
||||
public static let dbPath = documentPath + "/pass.sqlite"
|
||||
|
||||
|
||||
public static let iTunesFileSharingPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
||||
public static let iTunesFileSharingPGPPublic = iTunesFileSharingPath + "/gpg_key.pub"
|
||||
public static let iTunesFileSharingPGPPrivate = iTunesFileSharingPath + "/gpg_key"
|
||||
public static let iTunesFileSharingSSHPrivate = iTunesFileSharingPath + "/ssh_key"
|
||||
|
||||
|
||||
public static let gitSignatureDefaultName = "Pass for iOS"
|
||||
public static let gitSignatureDefaultEmail = "user@passforios"
|
||||
|
||||
|
||||
public static let passwordDots = "••••••••••••"
|
||||
public static let oneTimePasswordDots = "••••••"
|
||||
public static let passwordFont = UIFont(name: "Courier-Bold", size: UIFont.labelFontSize - 1)
|
||||
|
||||
|
||||
// UI related
|
||||
public static let red = UIColor(red:1.00, green:0.23, blue:0.19, alpha:1.0)
|
||||
public static let blue = UIColor(red:0.00, green:0.48, blue:1.00, alpha:1.0)
|
||||
|
|
@ -53,7 +53,7 @@ public class Globals {
|
|||
public static let symbolColor = UIColor(red:200/255.0, green:40/255.0, blue:41/255.0, alpha:1.0)
|
||||
public static let digitColor = UIColor(red:66/255.0, green:113/255.0, blue:174/255.0, alpha:1.0)
|
||||
public static let tableCellButtonSize = CGFloat(20.0)
|
||||
|
||||
|
||||
private init() { }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public extension Notification.Name {
|
|||
static let passwordStoreErased = Notification.Name("passwordStoreErased")
|
||||
static let passwordStoreChangeDiscarded = Notification.Name("passwordStoreChangeDiscarded")
|
||||
static let passwordSearch = Notification.Name("passwordSearch")
|
||||
|
||||
|
||||
static let passwordDisplaySettingChanged = Notification.Name("passwordDisplaySettingChanged")
|
||||
static let passwordDetailDisplaySettingChanged = Notification.Name("passwordDetailDisplaySettingChanged")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
import Foundation
|
||||
|
||||
extension UIView {
|
||||
|
||||
|
||||
// Save anchors: https://stackoverflow.com/questions/46317061/use-safe-area-layout-programmatically
|
||||
var safeTopAnchor: NSLayoutYAxisAnchor {
|
||||
if #available(iOS 11.0, *) {
|
||||
|
|
@ -18,7 +18,7 @@ extension UIView {
|
|||
return self.topAnchor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var safeLeftAnchor: NSLayoutXAxisAnchor {
|
||||
if #available(iOS 11.0, *){
|
||||
return self.safeAreaLayoutGuide.leftAnchor
|
||||
|
|
@ -26,7 +26,7 @@ extension UIView {
|
|||
return self.leftAnchor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var safeRightAnchor: NSLayoutXAxisAnchor {
|
||||
if #available(iOS 11.0, *){
|
||||
return self.safeAreaLayoutGuide.rightAnchor
|
||||
|
|
@ -34,7 +34,7 @@ extension UIView {
|
|||
return self.rightAnchor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var safeBottomAnchor: NSLayoutYAxisAnchor {
|
||||
if #available(iOS 11.0, *) {
|
||||
return self.safeAreaLayoutGuide.bottomAnchor
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@ public class Utils {
|
|||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||
return (try? keychain.getString(name)) ?? nil
|
||||
}
|
||||
|
||||
|
||||
public static func addPasswordToKeychain(name: String, password: String?) {
|
||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||
keychain[name] = password
|
||||
}
|
||||
|
||||
|
||||
public static func removeKeychain(name: String) {
|
||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||
try? keychain.remove(name)
|
||||
}
|
||||
|
||||
|
||||
public static func removeAllKeychain() {
|
||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||
try? keychain.removeAll()
|
||||
|
|
@ -53,7 +53,7 @@ public class Utils {
|
|||
}
|
||||
return attributedPassword
|
||||
}
|
||||
|
||||
|
||||
public static func alert(title: String, message: String, controller: UIViewController, handler: ((UIAlertAction) -> Void)? = nil, completion: (() -> Void)? = nil) {
|
||||
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: handler))
|
||||
|
|
|
|||
|
|
@ -14,21 +14,21 @@ import ObjectiveGit
|
|||
public struct GitCredential {
|
||||
private var credential: Credential
|
||||
private let passwordStore = PasswordStore.shared
|
||||
|
||||
|
||||
public enum Credential {
|
||||
case http(userName: String)
|
||||
case ssh(userName: String, privateKeyFile: URL)
|
||||
}
|
||||
|
||||
|
||||
public init(credential: Credential) {
|
||||
self.credential = credential
|
||||
}
|
||||
|
||||
|
||||
public func credentialProvider(requestGitPassword: @escaping (Credential, String?) -> String?) throws -> GTCredentialProvider {
|
||||
var attempts = 0
|
||||
return GTCredentialProvider { (_, _, _) -> (GTCredential?) in
|
||||
var credential: GTCredential? = nil
|
||||
|
||||
|
||||
switch self.credential {
|
||||
case let .http(userName):
|
||||
var lastPassword = self.passwordStore.gitPassword
|
||||
|
|
@ -63,7 +63,7 @@ public struct GitCredential {
|
|||
return credential
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func delete() {
|
||||
switch credential {
|
||||
case .http:
|
||||
|
|
|
|||
|
|
@ -11,24 +11,24 @@ import LocalAuthentication
|
|||
|
||||
open class PasscodeLock {
|
||||
public static let shared = PasscodeLock()
|
||||
|
||||
|
||||
fileprivate let passcodeKey = "passcode.lock.passcode"
|
||||
fileprivate var passcode: String? {
|
||||
return SharedDefaults[.passcodeKey]
|
||||
}
|
||||
|
||||
|
||||
public var hasPasscode: Bool {
|
||||
return passcode != nil
|
||||
}
|
||||
|
||||
|
||||
public func save(passcode: String) {
|
||||
SharedDefaults[.passcodeKey] = passcode
|
||||
}
|
||||
|
||||
|
||||
public func check(passcode: String) -> Bool {
|
||||
return self.passcode == passcode
|
||||
}
|
||||
|
||||
|
||||
public func delete() {
|
||||
SharedDefaults[.passcodeKey] = nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import OneTimePassword
|
|||
import Base32
|
||||
|
||||
public class Password {
|
||||
|
||||
|
||||
public var name: String
|
||||
public var url: URL
|
||||
public var plainText: String
|
||||
|
|
@ -50,7 +50,7 @@ public class Password {
|
|||
public var login: String? {
|
||||
return getAdditionValue(withKey: Constants.LOGIN_KEYWORD)
|
||||
}
|
||||
|
||||
|
||||
public var urlString: String? {
|
||||
return getAdditionValue(withKey: Constants.URL_KEYWORD)
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ public class Password {
|
|||
self.plainText = plainText
|
||||
initEverything()
|
||||
}
|
||||
|
||||
|
||||
|
||||
public func updatePassword(name: String, url: URL, plainText: String) {
|
||||
guard self.plainText != plainText || self.url != url else {
|
||||
|
|
@ -129,7 +129,7 @@ public class Password {
|
|||
let toLowercase = { (string: String) -> String in caseSensitive ? string : string.lowercased() }
|
||||
return additions.first(where: { toLowercase($0.title) == toLowercase(key) })?.content
|
||||
}
|
||||
|
||||
|
||||
/// Set the OTP token if we are able to construct a valid one.
|
||||
///
|
||||
/// Example of TOTP otpauth:
|
||||
|
|
@ -164,7 +164,7 @@ public class Password {
|
|||
.usingCounter(getAdditionValue(withKey: Constants.OTP_COUNTER))
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
/// Get the OTP description and the current password.
|
||||
public func getOtpStrings() -> (description: String, otp: String)? {
|
||||
guard otpToken != nil else {
|
||||
|
|
@ -178,18 +178,18 @@ public class Password {
|
|||
}
|
||||
return (description, otpToken!.currentPassword ?? "error")
|
||||
}
|
||||
|
||||
|
||||
// return the password strings
|
||||
// it is guaranteed that it is a HOTP password when we call this
|
||||
public func getNextHotp() -> String? {
|
||||
// increase the counter
|
||||
otpToken = otpToken?.updatedToken()
|
||||
|
||||
|
||||
// replace old HOTP settings with the new otpauth
|
||||
var newOtpauth = try! otpToken?.toURL().absoluteString
|
||||
newOtpauth?.append("&secret=")
|
||||
newOtpauth?.append(MF_Base32Codec.base32String(from: otpToken?.generator.secret))
|
||||
|
||||
|
||||
var lines : [String] = []
|
||||
self.plainText.enumerateLines() { line, _ in
|
||||
let (key, _) = Parser.getKeyValuePair(from: line)
|
||||
|
|
@ -205,7 +205,7 @@ public class Password {
|
|||
lines.append(newOtpauth!)
|
||||
}
|
||||
self.updatePassword(name: self.name, url: self.url, plainText: lines.joined(separator: "\n"))
|
||||
|
||||
|
||||
// get and return the password
|
||||
return self.otpToken?.currentPassword
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import Foundation
|
|||
import SwiftyUserDefaults
|
||||
|
||||
extension PasswordEntity {
|
||||
|
||||
|
||||
public var nameWithCategory: String {
|
||||
get {
|
||||
if let p = path, p.hasSuffix(".gpg") {
|
||||
|
|
@ -20,11 +20,11 @@ extension PasswordEntity {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func getCategoryText() -> String {
|
||||
return getCategoryArray().joined(separator: " > ")
|
||||
}
|
||||
|
||||
|
||||
public func getCategoryArray() -> [String] {
|
||||
var parentEntity = parent
|
||||
var passwordCategoryArray: [String] = []
|
||||
|
|
@ -35,7 +35,7 @@ extension PasswordEntity {
|
|||
passwordCategoryArray.reverse()
|
||||
return passwordCategoryArray
|
||||
}
|
||||
|
||||
|
||||
public func getURL() -> URL? {
|
||||
if let p = getPath().stringByAddingPercentEncodingForRFC3986() {
|
||||
return URL(string: p)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class PasswordStore {
|
|||
public static let shared = PasswordStore()
|
||||
public let storeURL = URL(fileURLWithPath: "\(Globals.repositoryPath)")
|
||||
public let tempStoreURL = URL(fileURLWithPath: "\(Globals.repositoryPath)-temp")
|
||||
|
||||
|
||||
public var storeRepository: GTRepository?
|
||||
public var pgpKeyID: String?
|
||||
public var publicKey: Key? {
|
||||
|
|
@ -31,7 +31,7 @@ public class PasswordStore {
|
|||
}
|
||||
}
|
||||
public var privateKey: Key?
|
||||
|
||||
|
||||
public var gitSignatureForNow: GTSignature {
|
||||
get {
|
||||
let gitSignatureName = SharedDefaults[.gitSignatureName] ?? Globals.gitSignatureDefaultName
|
||||
|
|
@ -39,9 +39,9 @@ public class PasswordStore {
|
|||
return GTSignature(name: gitSignatureName, email: gitSignatureEmail, time: Date())!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public let keyring = ObjectivePGP.defaultKeyring
|
||||
|
||||
|
||||
public var pgpKeyPassphrase: String? {
|
||||
set {
|
||||
Utils.addPasswordToKeychain(name: "pgpKeyPassphrase", password: newValue)
|
||||
|
|
@ -50,7 +50,7 @@ public class PasswordStore {
|
|||
return Utils.getPasswordFromKeychain(name: "pgpKeyPassphrase")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var gitPassword: String? {
|
||||
set {
|
||||
Utils.addPasswordToKeychain(name: "gitPassword", password: newValue)
|
||||
|
|
@ -59,7 +59,7 @@ public class PasswordStore {
|
|||
return Utils.getPasswordFromKeychain(name: "gitPassword")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public var gitSSHPrivateKeyPassphrase: String? {
|
||||
set {
|
||||
Utils.addPasswordToKeychain(name: "gitSSHPrivateKeyPassphrase", password: newValue)
|
||||
|
|
@ -68,7 +68,7 @@ public class PasswordStore {
|
|||
return Utils.getPasswordFromKeychain(name: "gitSSHPrivateKeyPassphrase")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let fm = FileManager.default
|
||||
lazy private var context: NSManagedObjectContext = {
|
||||
let modelURL = Bundle(identifier: Globals.passKitBundleIdentifier)!.url(forResource: "pass", withExtension: "momd")!
|
||||
|
|
@ -82,7 +82,7 @@ public class PasswordStore {
|
|||
if let error = error as NSError? {
|
||||
// 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.
|
||||
|
|
@ -96,11 +96,11 @@ public class PasswordStore {
|
|||
})
|
||||
return container.viewContext
|
||||
}()
|
||||
|
||||
|
||||
public var numberOfPasswords : Int {
|
||||
return self.fetchPasswordEntityCoreData(withDir: false).count
|
||||
return self.fetchPasswordEntityCoreData(withDir: false).count
|
||||
}
|
||||
|
||||
|
||||
public var sizeOfRepositoryByteCount : UInt64 {
|
||||
return (try? fm.allocatedSizeOfDirectoryAtURL(directoryURL: self.storeURL)) ?? 0
|
||||
}
|
||||
|
|
@ -112,12 +112,12 @@ public class PasswordStore {
|
|||
public var lastSyncedTime: Date? {
|
||||
return SharedDefaults[.lastSyncedTime]
|
||||
}
|
||||
|
||||
|
||||
private init() {
|
||||
// File migration to group
|
||||
migrateIfNeeded()
|
||||
backwardCompatibility()
|
||||
|
||||
|
||||
do {
|
||||
if fm.fileExists(atPath: storeURL.path) {
|
||||
try storeRepository = GTRepository.init(url: storeURL)
|
||||
|
|
@ -127,14 +127,14 @@ public class PasswordStore {
|
|||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func migrateIfNeeded() {
|
||||
// migrate happens only if the repository was cloned and pgp keys were set up using earlier versions
|
||||
let needMigration = !pgpKeyExists() && !gitSSHKeyExists() && !fm.fileExists(atPath: Globals.repositoryPath) && fm.fileExists(atPath: Globals.repositoryPathLegacy)
|
||||
guard needMigration == true else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
// migrate Defaults
|
||||
let userDefaults = UserDefaults()
|
||||
|
|
@ -143,7 +143,7 @@ public class PasswordStore {
|
|||
SharedDefaults.setValue(userDefaults.value(forKey: key), forKey: key)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// migrate files
|
||||
try fm.createDirectory(atPath: Globals.documentPath, withIntermediateDirectories: true, attributes: nil)
|
||||
try fm.createDirectory(atPath: Globals.libraryPath, withIntermediateDirectories: true, attributes: nil)
|
||||
|
|
@ -162,7 +162,7 @@ public class PasswordStore {
|
|||
}
|
||||
updatePasswordEntityCoreData()
|
||||
}
|
||||
|
||||
|
||||
private func backwardCompatibility() {
|
||||
// For the newly-introduced isRememberGitCredentialPassphraseOn (20171008)
|
||||
if (self.gitPassword != nil || self.gitSSHPrivateKeyPassphrase != nil) && SharedDefaults[.isRememberGitCredentialPassphraseOn] == false {
|
||||
|
|
@ -173,21 +173,21 @@ public class PasswordStore {
|
|||
SharedDefaults[.isRememberPGPPassphraseOn] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum SSHKeyType {
|
||||
case `public`, secret
|
||||
}
|
||||
|
||||
|
||||
public func initGitSSHKey(with armorKey: String) throws {
|
||||
let keyPath = Globals.gitSSHPrivateKeyPath
|
||||
try armorKey.write(toFile: keyPath, atomically: true, encoding: .ascii)
|
||||
}
|
||||
|
||||
|
||||
public func initPGPKeys() throws {
|
||||
try initPGPKey(.public)
|
||||
try initPGPKey(.secret)
|
||||
}
|
||||
|
||||
|
||||
public func initPGPKey(_ keyType: PGPKeyType) throws {
|
||||
switch keyType {
|
||||
case .public:
|
||||
|
|
@ -206,7 +206,7 @@ public class PasswordStore {
|
|||
throw AppError.UnknownError
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func initPGPKey(from url: URL, keyType: PGPKeyType) throws {
|
||||
var pgpKeyLocalPath = ""
|
||||
if keyType == .public {
|
||||
|
|
@ -218,7 +218,7 @@ public class PasswordStore {
|
|||
try pgpKeyData.write(to: URL(fileURLWithPath: pgpKeyLocalPath), options: .atomic)
|
||||
try initPGPKey(keyType)
|
||||
}
|
||||
|
||||
|
||||
public func initPGPKey(with armorKey: String, keyType: PGPKeyType) throws {
|
||||
var pgpKeyLocalPath = ""
|
||||
if keyType == .public {
|
||||
|
|
@ -229,8 +229,8 @@ public class PasswordStore {
|
|||
try armorKey.write(toFile: pgpKeyLocalPath, atomically: true, encoding: .ascii)
|
||||
try initPGPKey(keyType)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private func importKey(from keyPath: String) -> Key? {
|
||||
if fm.fileExists(atPath: keyPath) {
|
||||
let keys = try! ObjectivePGP.readKeys(fromPath: keyPath)
|
||||
|
|
@ -245,12 +245,12 @@ public class PasswordStore {
|
|||
public func getPgpPrivateKey() -> Key {
|
||||
return keyring.keys.filter({$0.secretKey != nil})[0]
|
||||
}
|
||||
|
||||
|
||||
public func repositoryExisted() -> Bool {
|
||||
let fm = FileManager()
|
||||
return fm.fileExists(atPath: Globals.repositoryPath)
|
||||
}
|
||||
|
||||
|
||||
public func passwordExisted(password: Password) -> Bool {
|
||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -266,7 +266,7 @@ public class PasswordStore {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
public func passwordEntityExisted(path: String) -> Bool {
|
||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -282,7 +282,7 @@ public class PasswordStore {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
public func getPasswordEntity(by path: String, isDir: Bool) -> PasswordEntity? {
|
||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -292,7 +292,7 @@ public class PasswordStore {
|
|||
fatalError("Failed to fetch password entities: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func cloneRepository(remoteRepoURL: URL,
|
||||
credential: GitCredential,
|
||||
requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?,
|
||||
|
|
@ -323,7 +323,7 @@ public class PasswordStore {
|
|||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func pullRepository(credential: GitCredential, requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?, transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -339,7 +339,7 @@ public class PasswordStore {
|
|||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func updatePasswordEntityCoreData() {
|
||||
deleteCoreData(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -393,7 +393,7 @@ public class PasswordStore {
|
|||
print("Error with save: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func getRecentCommits(count: Int) throws -> [GTCommit] {
|
||||
guard let storeRepository = storeRepository else {
|
||||
return []
|
||||
|
|
@ -410,7 +410,7 @@ public class PasswordStore {
|
|||
}
|
||||
return commits
|
||||
}
|
||||
|
||||
|
||||
public func fetchPasswordEntityCoreData(parent: PasswordEntity?) -> [PasswordEntity] {
|
||||
let passwordEntityFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -421,7 +421,7 @@ public class PasswordStore {
|
|||
fatalError("Failed to fetch passwords: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func fetchPasswordEntityCoreData(withDir: Bool) -> [PasswordEntity] {
|
||||
let passwordEntityFetch = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
do {
|
||||
|
|
@ -434,8 +434,8 @@ public class PasswordStore {
|
|||
fatalError("Failed to fetch passwords: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public func fetchUnsyncedPasswords() -> [PasswordEntity] {
|
||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||
passwordEntityFetchRequest.predicate = NSPredicate(format: "synced = %i", 0)
|
||||
|
|
@ -446,7 +446,7 @@ public class PasswordStore {
|
|||
fatalError("Failed to fetch passwords: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func setAllSynced() {
|
||||
let passwordEntities = fetchUnsyncedPasswords()
|
||||
for passwordEntity in passwordEntities {
|
||||
|
|
@ -460,7 +460,7 @@ public class PasswordStore {
|
|||
fatalError("Failed to save: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func getLatestUpdateInfo(filename: String) -> String {
|
||||
guard let storeRepository = storeRepository else {
|
||||
return "Unknown"
|
||||
|
|
@ -486,10 +486,10 @@ public class PasswordStore {
|
|||
}
|
||||
return autoFormattedDifference
|
||||
}
|
||||
|
||||
|
||||
public func updateRemoteRepo() {
|
||||
}
|
||||
|
||||
|
||||
private func gitAdd(path: String) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -497,7 +497,7 @@ public class PasswordStore {
|
|||
try storeRepository.index().addFile(path)
|
||||
try storeRepository.index().write()
|
||||
}
|
||||
|
||||
|
||||
private func gitRm(path: String) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -509,7 +509,7 @@ public class PasswordStore {
|
|||
try storeRepository.index().removeFile(path)
|
||||
try storeRepository.index().write()
|
||||
}
|
||||
|
||||
|
||||
private func deleteDirectoryTree(at url: URL) throws {
|
||||
var tempURL = storeURL.appendingPathComponent(url.deletingLastPathComponent().path)
|
||||
var count = try fm.contentsOfDirectory(atPath: tempURL.path).count
|
||||
|
|
@ -519,12 +519,12 @@ public class PasswordStore {
|
|||
count = try fm.contentsOfDirectory(atPath: tempURL.path).count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func createDirectoryTree(at url: URL) throws {
|
||||
let tempURL = storeURL.appendingPathComponent(url.deletingLastPathComponent().path)
|
||||
try fm.createDirectory(at: tempURL, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
|
||||
private func gitMv(from: String, to: String) throws {
|
||||
let fromURL = storeURL.appendingPathComponent(from)
|
||||
let toURL = storeURL.appendingPathComponent(to)
|
||||
|
|
@ -532,7 +532,7 @@ public class PasswordStore {
|
|||
try gitAdd(path: to)
|
||||
try gitRm(path: from)
|
||||
}
|
||||
|
||||
|
||||
private func gitCommit(message: String) throws -> GTCommit? {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -546,7 +546,7 @@ public class PasswordStore {
|
|||
let commit = try storeRepository.createCommit(with: newTree, message: message, author: signature, committer: signature, parents: [parent], updatingReferenceNamed: headReference.name)
|
||||
return commit
|
||||
}
|
||||
|
||||
|
||||
private func getLocalBranch(withName branchName: String) throws -> GTBranch? {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -555,7 +555,7 @@ public class PasswordStore {
|
|||
let branches = try storeRepository.branches(withPrefix: reference)
|
||||
return branches.first
|
||||
}
|
||||
|
||||
|
||||
public func pushRepository(credential: GitCredential, requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?, transferProgressBlock: @escaping (UInt32, UInt32, Int, UnsafeMutablePointer<ObjCBool>) -> Void) throws {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -571,12 +571,12 @@ public class PasswordStore {
|
|||
throw(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func addPasswordEntities(password: Password) throws -> PasswordEntity? {
|
||||
guard !passwordExisted(password: password) else {
|
||||
throw AppError.PasswordDuplicatedError
|
||||
}
|
||||
|
||||
|
||||
var passwordURL = password.url
|
||||
var previousPathLength = Int.max
|
||||
var paths: [String] = []
|
||||
|
|
@ -606,7 +606,7 @@ public class PasswordStore {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
private func insertPasswordEntity(name: String, path: String, parent: PasswordEntity?, synced: Bool = false, isDir: Bool = false) -> PasswordEntity? {
|
||||
var ret: PasswordEntity? = nil
|
||||
if let passwordEntity = NSEntityDescription.insertNewObject(forEntityName: "PasswordEntity", into: self.context) as? PasswordEntity {
|
||||
|
|
@ -624,7 +624,7 @@ public class PasswordStore {
|
|||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
public func add(password: Password) throws -> PasswordEntity? {
|
||||
try createDirectoryTree(at: password.url)
|
||||
let newPasswordEntity = try addPasswordEntities(password: password)
|
||||
|
|
@ -635,7 +635,7 @@ public class PasswordStore {
|
|||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
return newPasswordEntity
|
||||
}
|
||||
|
||||
|
||||
public func delete(passwordEntity: PasswordEntity) throws {
|
||||
let deletedFileURL = passwordEntity.getURL()!
|
||||
try gitRm(path: deletedFileURL.path)
|
||||
|
|
@ -644,7 +644,7 @@ public class PasswordStore {
|
|||
let _ = try gitCommit(message: "Remove \(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!) from store using Pass for iOS.")
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
}
|
||||
|
||||
|
||||
public func edit(passwordEntity: PasswordEntity, password: Password) throws -> PasswordEntity? {
|
||||
var newPasswordEntity: PasswordEntity? = passwordEntity
|
||||
|
||||
|
|
@ -656,16 +656,16 @@ public class PasswordStore {
|
|||
newPasswordEntity = passwordEntity
|
||||
newPasswordEntity?.synced = false
|
||||
}
|
||||
|
||||
|
||||
if password.changed&PasswordChange.path.rawValue != 0 {
|
||||
let deletedFileURL = passwordEntity.getURL()!
|
||||
// add
|
||||
try createDirectoryTree(at: password.url)
|
||||
newPasswordEntity = try addPasswordEntities(password: password)
|
||||
|
||||
|
||||
// mv
|
||||
try gitMv(from: deletedFileURL.path, to: password.url.path)
|
||||
|
||||
|
||||
// delete
|
||||
try deleteDirectoryTree(at: deletedFileURL)
|
||||
try deletePasswordEntities(passwordEntity: passwordEntity)
|
||||
|
|
@ -675,7 +675,7 @@ public class PasswordStore {
|
|||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
return newPasswordEntity
|
||||
}
|
||||
|
||||
|
||||
private func deletePasswordEntities(passwordEntity: PasswordEntity) throws {
|
||||
var current: PasswordEntity? = passwordEntity
|
||||
while current != nil && (current!.children!.count == 0 || !current!.isDir) {
|
||||
|
|
@ -689,7 +689,7 @@ public class PasswordStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func saveUpdated(passwordEntity: PasswordEntity) {
|
||||
do {
|
||||
try context.save()
|
||||
|
|
@ -697,11 +697,11 @@ public class PasswordStore {
|
|||
fatalError("Failed to save a PasswordEntity: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func deleteCoreData(entityName: String) {
|
||||
let deleteFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: entityName)
|
||||
let deleteRequest = NSBatchDeleteRequest(fetchRequest: deleteFetchRequest)
|
||||
|
||||
|
||||
do {
|
||||
try context.execute(deleteRequest)
|
||||
try context.save()
|
||||
|
|
@ -710,7 +710,7 @@ public class PasswordStore {
|
|||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func updateImage(passwordEntity: PasswordEntity, image: Data?) {
|
||||
guard let image = image else {
|
||||
return
|
||||
|
|
@ -733,7 +733,7 @@ public class PasswordStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func erase() {
|
||||
publicKey = nil
|
||||
privateKey = nil
|
||||
|
|
@ -743,19 +743,19 @@ public class PasswordStore {
|
|||
try? fm.removeItem(atPath: Globals.pgpPublicKeyPath)
|
||||
try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath)
|
||||
try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
|
||||
|
||||
|
||||
Utils.removeAllKeychain()
|
||||
|
||||
deleteCoreData(entityName: "PasswordEntity")
|
||||
|
||||
|
||||
SharedDefaults.removeAll()
|
||||
storeRepository = nil
|
||||
|
||||
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
NotificationCenter.default.post(name: .passwordStoreErased, object: nil)
|
||||
}
|
||||
|
||||
// return the number of discarded commits
|
||||
|
||||
// return the number of discarded commits
|
||||
public func reset() throws -> Int {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -772,7 +772,7 @@ public class PasswordStore {
|
|||
try storeRepository.reset(to: newHead, resetType: .hard)
|
||||
self.setAllSynced()
|
||||
self.updatePasswordEntityCoreData()
|
||||
|
||||
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
NotificationCenter.default.post(name: .passwordStoreChangeDiscarded, object: nil)
|
||||
return localCommits.count
|
||||
|
|
@ -780,8 +780,8 @@ public class PasswordStore {
|
|||
return 0 // no new commit
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private func getLocalCommits() throws -> [GTCommit]? {
|
||||
guard let storeRepository = storeRepository else {
|
||||
throw AppError.RepositoryNotSetError
|
||||
|
|
@ -791,18 +791,18 @@ public class PasswordStore {
|
|||
throw AppError.RepositoryRemoteMasterNotFoundError
|
||||
}
|
||||
let remoteMasterBranch = try storeRepository.remoteBranches()[index]
|
||||
|
||||
|
||||
// check oid before calling localCommitsRelative
|
||||
guard remoteMasterBranch.oid != nil else {
|
||||
throw AppError.RepositoryRemoteMasterNotFoundError
|
||||
}
|
||||
|
||||
|
||||
// get a list of local commits
|
||||
return try storeRepository.localCommitsRelative(toRemoteBranch: remoteMasterBranch)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public func decrypt(passwordEntity: PasswordEntity, requestPGPKeyPassphrase: () -> String) throws -> Password? {
|
||||
let encryptedDataPath = storeURL.appendingPathComponent(passwordEntity.getPath())
|
||||
let encryptedData = try Data(contentsOf: encryptedDataPath)
|
||||
|
|
@ -817,7 +817,7 @@ public class PasswordStore {
|
|||
}
|
||||
return Password(name: passwordEntity.getName(), url: url, plainText: plainText)
|
||||
}
|
||||
|
||||
|
||||
public func encrypt(password: Password) throws -> Data {
|
||||
guard keyring.keys.count > 0 else {
|
||||
throw AppError.PGPPublicKeyNotExistError
|
||||
|
|
@ -830,7 +830,7 @@ public class PasswordStore {
|
|||
return encryptedData
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func removePGPKeys() {
|
||||
try? fm.removeItem(atPath: Globals.pgpPublicKeyPath)
|
||||
try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath)
|
||||
|
|
@ -844,14 +844,14 @@ public class PasswordStore {
|
|||
publicKey = nil
|
||||
privateKey = nil
|
||||
}
|
||||
|
||||
|
||||
public func removeGitSSHKeys() {
|
||||
try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
|
||||
Defaults.remove(.gitSSHPrivateKeyArmor)
|
||||
Defaults.remove(.gitSSHPrivateKeyURL)
|
||||
self.gitSSHPrivateKeyPassphrase = nil
|
||||
}
|
||||
|
||||
|
||||
public func gitSSHKeyExists(inFileSharing: Bool = false) -> Bool {
|
||||
if inFileSharing == false {
|
||||
return fm.fileExists(atPath: Globals.gitSSHPrivateKeyPath)
|
||||
|
|
@ -859,7 +859,7 @@ public class PasswordStore {
|
|||
return fm.fileExists(atPath: Globals.iTunesFileSharingSSHPrivate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func pgpKeyExists(inFileSharing: Bool = false) -> Bool {
|
||||
if inFileSharing == false {
|
||||
return fm.fileExists(atPath: Globals.pgpPublicKeyPath) && fm.fileExists(atPath: Globals.pgpPrivateKeyPath)
|
||||
|
|
@ -867,7 +867,7 @@ public class PasswordStore {
|
|||
return fm.fileExists(atPath: Globals.iTunesFileSharingPGPPublic) && fm.fileExists(atPath: Globals.iTunesFileSharingPGPPrivate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func gitSSHKeyImportFromFileSharing() throws {
|
||||
try fm.moveItem(atPath: Globals.iTunesFileSharingSSHPrivate, toPath: Globals.gitSSHPrivateKeyPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ extension AdditionField {
|
|||
}
|
||||
|
||||
extension AdditionField: Equatable {
|
||||
|
||||
|
||||
public static func == (first: AdditionField, second: AdditionField) -> Bool {
|
||||
return first.asTuple == second.asTuple
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public enum OtpType: String {
|
|||
var description: String {
|
||||
return rawValue
|
||||
}
|
||||
|
||||
|
||||
init(token: Token?) {
|
||||
switch token?.generator.factor {
|
||||
case .some(.counter):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue