Support selects a credential identity from the QuickType bar

This commit is contained in:
Mingshen Sun 2021-01-03 15:08:15 -08:00
parent d4669bbfcb
commit 29d74c48e5
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4
6 changed files with 125 additions and 30 deletions

View file

@ -345,6 +345,17 @@ public class PasswordStore {
}
}
public func fetchPasswordEntity(with path: String) -> PasswordEntity? {
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@", path)
do {
let passwordEntities = try context.fetch(passwordEntityFetchRequest) as! [PasswordEntity]
return passwordEntities.first
} catch {
fatalError("FailedToFetchPasswords".localize(error))
}
}
public func setAllSynced() {
let passwordEntities = fetchUnsyncedPasswords()
if !passwordEntities.isEmpty {
@ -688,6 +699,13 @@ public class PasswordStore {
return Password(name: passwordEntity.getName(), url: url, plainText: plainText)
}
public func decrypt(path: String, keyID: String? = nil, requestPGPKeyPassphrase: @escaping (String) -> String) throws -> Password {
guard let passwordEntity = fetchPasswordEntity(with: path) else {
throw AppError.decryption
}
return try decrypt(passwordEntity: passwordEntity, keyID: keyID, requestPGPKeyPassphrase: requestPGPKeyPassphrase)
}
public func encrypt(password: Password, keyID: String? = nil) throws -> Data {
let encryptedDataPath = storeURL.appendingPathComponent(password.url.path)
let keyID = keyID ?? findGPGID(from: encryptedDataPath)