Cache TOTP discovery and report progress (#74)
This commit is contained in:
@@ -609,6 +609,8 @@ public protocol MobileAuthenticationProtocol: AnyObject, Sendable {
|
||||
|
||||
func beginEntryEditor(path: String) throws -> MobileEntryEditorSession
|
||||
|
||||
func cachedTotpPage() throws -> MobileTotpPage?
|
||||
|
||||
func cancel() throws
|
||||
|
||||
func copyEntryField(path: String, field: UInt64) throws -> MobileEntryCopy
|
||||
@@ -647,7 +649,7 @@ public protocol MobileAuthenticationProtocol: AnyObject, Sendable {
|
||||
|
||||
func totpDetail(path: String, unixSeconds: UInt64) throws -> MobileTotpDetail
|
||||
|
||||
func totpPage() throws -> MobileTotpPage
|
||||
func totpPage(operation: MobileTotpOperation) throws -> MobileTotpPage
|
||||
|
||||
func touchUserActivity() throws
|
||||
|
||||
@@ -746,6 +748,15 @@ open func beginEntryEditor(path: String)throws -> MobileEntryEditorSession {
|
||||
})
|
||||
}
|
||||
|
||||
open func cachedTotpPage()throws -> MobileTotpPage? {
|
||||
return try FfiConverterOptionTypeMobileTotpPage.lift(try rustCallWithError(FfiConverterTypeMobileAuthenticationFfiError_lift) {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_method_mobileauthentication_cached_totp_page(
|
||||
self.uniffiCloneHandle(),uniffiCallStatus
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
open func cancel()throws {try rustCallWithError(FfiConverterTypeMobileAuthenticationFfiError_lift) {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_method_mobileauthentication_cancel(
|
||||
@@ -945,11 +956,12 @@ open func totpDetail(path: String, unixSeconds: UInt64)throws -> MobileTotpDeta
|
||||
})
|
||||
}
|
||||
|
||||
open func totpPage()throws -> MobileTotpPage {
|
||||
open func totpPage(operation: MobileTotpOperation)throws -> MobileTotpPage {
|
||||
return try FfiConverterTypeMobileTotpPage_lift(try rustCallWithError(FfiConverterTypeMobileAuthenticationFfiError_lift) {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_method_mobileauthentication_totp_page(
|
||||
self.uniffiCloneHandle(),uniffiCallStatus
|
||||
self.uniffiCloneHandle(),
|
||||
FfiConverterTypeMobileTotpOperation_lower(operation),uniffiCallStatus
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -1637,6 +1649,133 @@ public func FfiConverterTypeMobileOnboardingOperation_lower(_ value: MobileOnboa
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public protocol MobileTotpOperationProtocol: AnyObject, Sendable {
|
||||
|
||||
func cancel()
|
||||
|
||||
func progress() -> MobileTotpDiscoveryProgress
|
||||
|
||||
}
|
||||
open class MobileTotpOperation: MobileTotpOperationProtocol, @unchecked Sendable {
|
||||
fileprivate let handle: UInt64
|
||||
|
||||
/// Used to instantiate a [FFIObject] without an actual handle, for fakes in tests, mostly.
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public struct NoHandle {
|
||||
public init() {}
|
||||
}
|
||||
|
||||
// TODO: We'd like this to be `private` but for Swifty reasons,
|
||||
// we can't implement `FfiConverter` without making this `required` and we can't
|
||||
// make it `required` without making it `public`.
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
required public init(unsafeFromHandle handle: UInt64) {
|
||||
self.handle = handle
|
||||
}
|
||||
|
||||
// This constructor can be used to instantiate a fake object.
|
||||
// - Parameter noHandle: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
|
||||
//
|
||||
// - Warning:
|
||||
// Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing handle the FFI lower functions will crash.
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public init(noHandle: NoHandle) {
|
||||
self.handle = 0
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func uniffiCloneHandle() -> UInt64 {
|
||||
return try! rustCall { uniffi_ironstorage_apple_fn_clone_mobiletotpoperation(self.handle, $0) }
|
||||
}
|
||||
// No primary constructor declared for this class.
|
||||
|
||||
deinit {
|
||||
if handle == 0 {
|
||||
// Mock objects have handle=0 don't try to free them
|
||||
return
|
||||
}
|
||||
|
||||
try! rustCall { uniffi_ironstorage_apple_fn_free_mobiletotpoperation(handle, $0) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
open func cancel() {try! rustCall() {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_method_mobiletotpoperation_cancel(
|
||||
self.uniffiCloneHandle(),uniffiCallStatus
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
open func progress() -> MobileTotpDiscoveryProgress {
|
||||
return try! FfiConverterTypeMobileTotpDiscoveryProgress_lift(try! rustCall() {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_method_mobiletotpoperation_progress(
|
||||
self.uniffiCloneHandle(),uniffiCallStatus
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public struct FfiConverterTypeMobileTotpOperation: FfiConverter {
|
||||
typealias FfiType = UInt64
|
||||
typealias SwiftType = MobileTotpOperation
|
||||
|
||||
public static func lift(_ handle: UInt64) throws -> MobileTotpOperation {
|
||||
return MobileTotpOperation(unsafeFromHandle: handle)
|
||||
}
|
||||
|
||||
public static func lower(_ value: MobileTotpOperation) -> UInt64 {
|
||||
return value.uniffiCloneHandle()
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileTotpOperation {
|
||||
let handle: UInt64 = try readInt(&buf)
|
||||
return try lift(handle)
|
||||
}
|
||||
|
||||
public static func write(_ value: MobileTotpOperation, into buf: inout [UInt8]) {
|
||||
writeInt(&buf, lower(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpOperation_lift(_ handle: UInt64) throws -> MobileTotpOperation {
|
||||
return try FfiConverterTypeMobileTotpOperation.lift(handle)
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpOperation_lower(_ value: MobileTotpOperation) -> UInt64 {
|
||||
return FfiConverterTypeMobileTotpOperation.lower(value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public struct MobileAuthenticationState: Equatable, Hashable {
|
||||
public var unlocked: Bool
|
||||
public var biometricUnlockEnabled: Bool
|
||||
@@ -3713,16 +3852,88 @@ public func FfiConverterTypeMobileTotpDetail_lower(_ value: MobileTotpDetail) ->
|
||||
}
|
||||
|
||||
|
||||
public struct MobileTotpDiscoveryProgress: Equatable, Hashable {
|
||||
public var phase: MobileTotpDiscoveryPhase
|
||||
public var total: UInt32
|
||||
public var inspected: UInt32
|
||||
public var cacheHits: UInt32
|
||||
public var matches: UInt32
|
||||
public var unavailable: UInt32
|
||||
|
||||
// Default memberwise initializers are never public by default, so we
|
||||
// declare one manually.
|
||||
public init(phase: MobileTotpDiscoveryPhase, total: UInt32, inspected: UInt32, cacheHits: UInt32, matches: UInt32, unavailable: UInt32) {
|
||||
self.phase = phase
|
||||
self.total = total
|
||||
self.inspected = inspected
|
||||
self.cacheHits = cacheHits
|
||||
self.matches = matches
|
||||
self.unavailable = unavailable
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if compiler(>=6)
|
||||
extension MobileTotpDiscoveryProgress: Sendable {}
|
||||
#endif
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public struct FfiConverterTypeMobileTotpDiscoveryProgress: FfiConverterRustBuffer {
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileTotpDiscoveryProgress {
|
||||
return
|
||||
try MobileTotpDiscoveryProgress(
|
||||
phase: FfiConverterTypeMobileTotpDiscoveryPhase.read(from: &buf),
|
||||
total: FfiConverterUInt32.read(from: &buf),
|
||||
inspected: FfiConverterUInt32.read(from: &buf),
|
||||
cacheHits: FfiConverterUInt32.read(from: &buf),
|
||||
matches: FfiConverterUInt32.read(from: &buf),
|
||||
unavailable: FfiConverterUInt32.read(from: &buf)
|
||||
)
|
||||
}
|
||||
|
||||
public static func write(_ value: MobileTotpDiscoveryProgress, into buf: inout [UInt8]) {
|
||||
FfiConverterTypeMobileTotpDiscoveryPhase.write(value.phase, into: &buf)
|
||||
FfiConverterUInt32.write(value.total, into: &buf)
|
||||
FfiConverterUInt32.write(value.inspected, into: &buf)
|
||||
FfiConverterUInt32.write(value.cacheHits, into: &buf)
|
||||
FfiConverterUInt32.write(value.matches, into: &buf)
|
||||
FfiConverterUInt32.write(value.unavailable, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpDiscoveryProgress_lift(_ buf: RustBuffer) throws -> MobileTotpDiscoveryProgress {
|
||||
return try FfiConverterTypeMobileTotpDiscoveryProgress.lift(buf)
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpDiscoveryProgress_lower(_ value: MobileTotpDiscoveryProgress) -> RustBuffer {
|
||||
return FfiConverterTypeMobileTotpDiscoveryProgress.lower(value)
|
||||
}
|
||||
|
||||
|
||||
public struct MobileTotpPage: Equatable, Hashable {
|
||||
public var rows: [MobileTotpRow]
|
||||
public var unavailableEntries: UInt32
|
||||
public var cacheNotice: String?
|
||||
public var watch: MobileWatchSnapshotStatus
|
||||
|
||||
// Default memberwise initializers are never public by default, so we
|
||||
// declare one manually.
|
||||
public init(rows: [MobileTotpRow], unavailableEntries: UInt32, watch: MobileWatchSnapshotStatus) {
|
||||
public init(rows: [MobileTotpRow], unavailableEntries: UInt32, cacheNotice: String?, watch: MobileWatchSnapshotStatus) {
|
||||
self.rows = rows
|
||||
self.unavailableEntries = unavailableEntries
|
||||
self.cacheNotice = cacheNotice
|
||||
self.watch = watch
|
||||
}
|
||||
|
||||
@@ -3744,6 +3955,7 @@ public struct FfiConverterTypeMobileTotpPage: FfiConverterRustBuffer {
|
||||
try MobileTotpPage(
|
||||
rows: FfiConverterSequenceTypeMobileTotpRow.read(from: &buf),
|
||||
unavailableEntries: FfiConverterUInt32.read(from: &buf),
|
||||
cacheNotice: FfiConverterOptionString.read(from: &buf),
|
||||
watch: FfiConverterTypeMobileWatchSnapshotStatus.read(from: &buf)
|
||||
)
|
||||
}
|
||||
@@ -3751,6 +3963,7 @@ public struct FfiConverterTypeMobileTotpPage: FfiConverterRustBuffer {
|
||||
public static func write(_ value: MobileTotpPage, into buf: inout [UInt8]) {
|
||||
FfiConverterSequenceTypeMobileTotpRow.write(value.rows, into: &buf)
|
||||
FfiConverterUInt32.write(value.unavailableEntries, into: &buf)
|
||||
FfiConverterOptionString.write(value.cacheNotice, into: &buf)
|
||||
FfiConverterTypeMobileWatchSnapshotStatus.write(value.watch, into: &buf)
|
||||
}
|
||||
}
|
||||
@@ -5747,6 +5960,93 @@ public func FfiConverterTypeMobileTab_lower(_ value: MobileTab) -> RustBuffer {
|
||||
|
||||
|
||||
|
||||
public enum MobileTotpDiscoveryPhase: Equatable, Hashable {
|
||||
|
||||
case preparing
|
||||
case inspecting
|
||||
case saving
|
||||
case complete
|
||||
case cancelled
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if compiler(>=6)
|
||||
extension MobileTotpDiscoveryPhase: Sendable {}
|
||||
#endif
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public struct FfiConverterTypeMobileTotpDiscoveryPhase: FfiConverterRustBuffer {
|
||||
typealias SwiftType = MobileTotpDiscoveryPhase
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileTotpDiscoveryPhase {
|
||||
let variant: Int32 = try readInt(&buf)
|
||||
switch variant {
|
||||
|
||||
case 1: return .preparing
|
||||
|
||||
case 2: return .inspecting
|
||||
|
||||
case 3: return .saving
|
||||
|
||||
case 4: return .complete
|
||||
|
||||
case 5: return .cancelled
|
||||
|
||||
default: throw UniffiInternalError.unexpectedEnumCase
|
||||
}
|
||||
}
|
||||
|
||||
public static func write(_ value: MobileTotpDiscoveryPhase, into buf: inout [UInt8]) {
|
||||
switch value {
|
||||
|
||||
|
||||
case .preparing:
|
||||
writeInt(&buf, Int32(1))
|
||||
|
||||
|
||||
case .inspecting:
|
||||
writeInt(&buf, Int32(2))
|
||||
|
||||
|
||||
case .saving:
|
||||
writeInt(&buf, Int32(3))
|
||||
|
||||
|
||||
case .complete:
|
||||
writeInt(&buf, Int32(4))
|
||||
|
||||
|
||||
case .cancelled:
|
||||
writeInt(&buf, Int32(5))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpDiscoveryPhase_lift(_ buf: RustBuffer) throws -> MobileTotpDiscoveryPhase {
|
||||
return try FfiConverterTypeMobileTotpDiscoveryPhase.lift(buf)
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeMobileTotpDiscoveryPhase_lower(_ value: MobileTotpDiscoveryPhase) -> RustBuffer {
|
||||
return FfiConverterTypeMobileTotpDiscoveryPhase.lower(value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public enum MobileWatchSnapshotState: Equatable, Hashable {
|
||||
|
||||
case unavailable
|
||||
@@ -5931,6 +6231,30 @@ fileprivate struct FfiConverterOptionTypeMobileKeyTransferKey: FfiConverterRustB
|
||||
}
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
fileprivate struct FfiConverterOptionTypeMobileTotpPage: FfiConverterRustBuffer {
|
||||
typealias SwiftType = MobileTotpPage?
|
||||
|
||||
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
||||
guard let value = value else {
|
||||
writeInt(&buf, Int8(0))
|
||||
return
|
||||
}
|
||||
writeInt(&buf, Int8(1))
|
||||
FfiConverterTypeMobileTotpPage.write(value, into: &buf)
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
|
||||
switch try readInt(&buf) as Int8 {
|
||||
case 0: return nil
|
||||
case 1: return try FfiConverterTypeMobileTotpPage.read(from: &buf)
|
||||
default: throw UniffiInternalError.unexpectedOptionalTag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
@@ -6343,6 +6667,13 @@ public func mobileShellFixture(state: MobileShellState) -> MobileShell {
|
||||
)
|
||||
})
|
||||
}
|
||||
public func mobileTotpOperation() -> MobileTotpOperation {
|
||||
return try! FfiConverterTypeMobileTotpOperation_lift(try! rustCall() {
|
||||
uniffiCallStatus in
|
||||
uniffi_ironstorage_apple_fn_func_mobile_totp_operation(uniffiCallStatus
|
||||
)
|
||||
})
|
||||
}
|
||||
public func productName() -> String {
|
||||
return try! FfiConverterString.lift(try! rustCall() {
|
||||
uniffiCallStatus in
|
||||
@@ -6405,6 +6736,9 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_ironstorage_apple_checksum_func_mobile_shell_fixture() != 1649) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_func_mobile_totp_operation() != 22350) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_func_product_name() != 43533) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
@@ -6423,6 +6757,9 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_begin_entry_editor() != 63281) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_cached_totp_page() != 36629) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_cancel() != 6512) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
@@ -6480,7 +6817,7 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_totp_detail() != 42762) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_totp_page() != 18529) {
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_totp_page() != 15475) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileauthentication_touch_user_activity() != 18402) {
|
||||
@@ -6540,6 +6877,12 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobileonboardingoperation_setup() != 3525) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobiletotpoperation_cancel() != 30179) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_ironstorage_apple_checksum_method_mobiletotpoperation_progress() != 54435) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
|
||||
return InitializationResult.ok
|
||||
}()
|
||||
|
||||
@@ -268,6 +268,11 @@ RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_begin_create_
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_begin_entry_editor(uint64_t ptr, RustBuffer path, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_CACHED_TOTP_PAGE
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_CACHED_TOTP_PAGE
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_cached_totp_page(uint64_t ptr, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_CANCEL
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_CANCEL
|
||||
void uniffi_ironstorage_apple_fn_method_mobileauthentication_cancel(uint64_t ptr, RustCallStatus *_Nonnull out_status
|
||||
@@ -365,7 +370,7 @@ RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_totp_detail(u
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_TOTP_PAGE
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_TOTP_PAGE
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_totp_page(uint64_t ptr, RustCallStatus *_Nonnull out_status
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobileauthentication_totp_page(uint64_t ptr, uint64_t operation, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILEAUTHENTICATION_TOUCH_USER_ACTIVITY
|
||||
@@ -503,6 +508,26 @@ RustBuffer uniffi_ironstorage_apple_fn_method_mobileonboardingoperation_progress
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobileonboardingoperation_setup(uint64_t ptr, RustBuffer branch, int8_t use_existing, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_CLONE_MOBILETOTPOPERATION
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_CLONE_MOBILETOTPOPERATION
|
||||
uint64_t uniffi_ironstorage_apple_fn_clone_mobiletotpoperation(uint64_t handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FREE_MOBILETOTPOPERATION
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FREE_MOBILETOTPOPERATION
|
||||
void uniffi_ironstorage_apple_fn_free_mobiletotpoperation(uint64_t handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILETOTPOPERATION_CANCEL
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILETOTPOPERATION_CANCEL
|
||||
void uniffi_ironstorage_apple_fn_method_mobiletotpoperation_cancel(uint64_t ptr, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILETOTPOPERATION_PROGRESS
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_METHOD_MOBILETOTPOPERATION_PROGRESS
|
||||
RustBuffer uniffi_ironstorage_apple_fn_method_mobiletotpoperation_progress(uint64_t ptr, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_AUTHENTICATION
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_AUTHENTICATION
|
||||
uint64_t uniffi_ironstorage_apple_fn_func_mobile_authentication(RustCallStatus *_Nonnull out_status
|
||||
@@ -545,6 +570,12 @@ RustBuffer uniffi_ironstorage_apple_fn_func_mobile_shell(RustCallStatus *_Nonnul
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_SHELL_FIXTURE
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_SHELL_FIXTURE
|
||||
RustBuffer uniffi_ironstorage_apple_fn_func_mobile_shell_fixture(RustBuffer state, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_TOTP_OPERATION
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_MOBILE_TOTP_OPERATION
|
||||
uint64_t uniffi_ironstorage_apple_fn_func_mobile_totp_operation(RustCallStatus *_Nonnull out_status
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_FN_FUNC_PRODUCT_NAME
|
||||
@@ -869,6 +900,12 @@ uint16_t uniffi_ironstorage_apple_checksum_func_mobile_shell(void
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_FUNC_MOBILE_SHELL_FIXTURE
|
||||
uint16_t uniffi_ironstorage_apple_checksum_func_mobile_shell_fixture(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_FUNC_MOBILE_TOTP_OPERATION
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_FUNC_MOBILE_TOTP_OPERATION
|
||||
uint16_t uniffi_ironstorage_apple_checksum_func_mobile_totp_operation(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_FUNC_PRODUCT_NAME
|
||||
@@ -905,6 +942,12 @@ uint16_t uniffi_ironstorage_apple_checksum_method_mobileauthentication_begin_cre
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILEAUTHENTICATION_BEGIN_ENTRY_EDITOR
|
||||
uint16_t uniffi_ironstorage_apple_checksum_method_mobileauthentication_begin_entry_editor(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILEAUTHENTICATION_CACHED_TOTP_PAGE
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILEAUTHENTICATION_CACHED_TOTP_PAGE
|
||||
uint16_t uniffi_ironstorage_apple_checksum_method_mobileauthentication_cached_totp_page(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILEAUTHENTICATION_CANCEL
|
||||
@@ -1139,6 +1182,18 @@ uint16_t uniffi_ironstorage_apple_checksum_method_mobileonboardingoperation_prog
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILEONBOARDINGOPERATION_SETUP
|
||||
uint16_t uniffi_ironstorage_apple_checksum_method_mobileonboardingoperation_setup(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILETOTPOPERATION_CANCEL
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILETOTPOPERATION_CANCEL
|
||||
uint16_t uniffi_ironstorage_apple_checksum_method_mobiletotpoperation_cancel(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILETOTPOPERATION_PROGRESS
|
||||
#define UNIFFI_FFIDEF_UNIFFI_IRONSTORAGE_APPLE_CHECKSUM_METHOD_MOBILETOTPOPERATION_PROGRESS
|
||||
uint16_t uniffi_ironstorage_apple_checksum_method_mobiletotpoperation_progress(void
|
||||
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_FFI_IRONSTORAGE_APPLE_UNIFFI_CONTRACT_VERSION
|
||||
|
||||
@@ -654,7 +654,11 @@ private final class ShellViewController: UITableViewController, MobileTabRoot {
|
||||
)
|
||||
if failure.kind == .authentication || failure.kind == .secureStorage {
|
||||
alert.addAction(UIAlertAction(title: "Preferences", style: .default) { [weak self] _ in
|
||||
self?.tabBarController?.selectedIndex = 3
|
||||
guard let tabs = self?.tabBarController else { return }
|
||||
tabs.selectedIndex = tabs.viewControllers?.firstIndex { controller in
|
||||
guard let navigation = controller as? UINavigationController else { return false }
|
||||
return (navigation.viewControllers.first as? MobileTabRoot)?.shellTab == .preferences
|
||||
} ?? tabs.selectedIndex
|
||||
})
|
||||
}
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .cancel))
|
||||
@@ -1577,6 +1581,76 @@ private final class KeyQrView: UIView {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private final class TotpDiscoveryView: UIView {
|
||||
private let spinner = UIActivityIndicatorView(style: .medium)
|
||||
private let titleLabel = UILabel()
|
||||
private let detailLabel = UILabel()
|
||||
private let progressView = UIProgressView(progressViewStyle: .default)
|
||||
|
||||
init(cancel: @escaping () -> Void) {
|
||||
super.init(frame: .zero)
|
||||
titleLabel.font = .preferredFont(forTextStyle: .headline)
|
||||
titleLabel.adjustsFontForContentSizeCategory = true
|
||||
titleLabel.textAlignment = .center
|
||||
detailLabel.font = .preferredFont(forTextStyle: .subheadline)
|
||||
detailLabel.adjustsFontForContentSizeCategory = true
|
||||
detailLabel.textColor = .secondaryLabel
|
||||
detailLabel.textAlignment = .center
|
||||
detailLabel.numberOfLines = 0
|
||||
progressView.accessibilityLabel = "TOTP discovery progress"
|
||||
let cancelButton = UIButton(type: .system, primaryAction: UIAction(title: "Cancel") { _ in
|
||||
cancel()
|
||||
})
|
||||
let progressRow = UIStackView(arrangedSubviews: [spinner, progressView])
|
||||
progressRow.alignment = .center
|
||||
progressRow.spacing = 12
|
||||
let stack = UIStackView(arrangedSubviews: [titleLabel, detailLabel, progressRow, cancelButton])
|
||||
stack.axis = .vertical
|
||||
stack.alignment = .fill
|
||||
stack.spacing = 12
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.centerXAnchor.constraint(equalTo: centerXAnchor),
|
||||
stack.topAnchor.constraint(equalTo: topAnchor, constant: 24),
|
||||
stack.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -24),
|
||||
stack.leadingAnchor.constraint(greaterThanOrEqualTo: readableContentGuide.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(lessThanOrEqualTo: readableContentGuide.trailingAnchor),
|
||||
progressView.widthAnchor.constraint(greaterThanOrEqualToConstant: 180),
|
||||
])
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) is not supported")
|
||||
}
|
||||
|
||||
func apply(_ progress: MobileTotpDiscoveryProgress) {
|
||||
titleLabel.text = switch progress.phase {
|
||||
case .preparing: "Preparing TOTP Discovery"
|
||||
case .inspecting: "Discovering TOTP Entries"
|
||||
case .saving: "Saving Protected Cache"
|
||||
case .complete: "TOTP Discovery Complete"
|
||||
case .cancelled: "Cancelling TOTP Discovery"
|
||||
}
|
||||
if progress.total == 0 {
|
||||
spinner.startAnimating()
|
||||
progressView.isHidden = true
|
||||
detailLabel.text = "Reading the password-store inventory."
|
||||
} else {
|
||||
spinner.stopAnimating()
|
||||
progressView.isHidden = false
|
||||
progressView.progress = Float(progress.inspected) / Float(progress.total)
|
||||
progressView.accessibilityValue = "\(progress.inspected) of \(progress.total)"
|
||||
detailLabel.text =
|
||||
"\(progress.inspected) of \(progress.total) inspected • "
|
||||
+ "\(progress.cacheHits) cached • \(progress.matches) TOTP"
|
||||
+ (progress.unavailable == 0 ? "" : " • \(progress.unavailable) unavailable")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private final class TotpListViewController: UITableViewController, MobileTabRoot {
|
||||
fileprivate let shellTab = MobileTab.totp
|
||||
@@ -1585,6 +1659,11 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
private var page: MobileTotpPage?
|
||||
private var loadTask: Task<Void, Never>?
|
||||
private var unlockTask: Task<Void, Never>?
|
||||
private var shellTask: Task<Void, Never>?
|
||||
private var progressTask: Task<Void, Never>?
|
||||
private var operation: MobileTotpOperation?
|
||||
private var loadGeneration = 0
|
||||
private var refreshAfterUnlock = false
|
||||
|
||||
init(shellPage: MobilePage, authentication: MobileAuthentication?) {
|
||||
self.shellPage = shellPage
|
||||
@@ -1602,8 +1681,11 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
|
||||
deinit {
|
||||
operation?.cancel()
|
||||
loadTask?.cancel()
|
||||
unlockTask?.cancel()
|
||||
shellTask?.cancel()
|
||||
progressTask?.cancel()
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
@@ -1632,7 +1714,7 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
refreshState()
|
||||
reloadShell()
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int { 1 }
|
||||
@@ -1649,7 +1731,8 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
let unavailable = page.unavailableEntries == 0
|
||||
? ""
|
||||
: " \(page.unavailableEntries) entries could not be inspected with the active key."
|
||||
return page.watch.detail + unavailable
|
||||
let cache = page.cacheNotice.map { " \($0)" } ?? ""
|
||||
return page.watch.detail + unavailable + cache
|
||||
}
|
||||
|
||||
override func tableView(
|
||||
@@ -1677,7 +1760,16 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
guard let row = page?.rows[indexPath.row], let authentication else { return }
|
||||
guard let row = page?.rows[indexPath.row] else { return }
|
||||
guard (try? authentication?.state().unlocked) == true else {
|
||||
unlock(passphrase: nil, row: row)
|
||||
return
|
||||
}
|
||||
open(row)
|
||||
}
|
||||
|
||||
private func open(_ row: MobileTotpRow) {
|
||||
guard let authentication else { return }
|
||||
loadTask?.cancel()
|
||||
loadTask = Task { [weak self] in
|
||||
let result = await Task.detached(priority: .userInitiated) {
|
||||
@@ -1709,20 +1801,36 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
|
||||
@objc private func refreshRequested() {
|
||||
refreshState(force: true)
|
||||
if (try? authentication?.state().unlocked) == true {
|
||||
loadPage()
|
||||
} else {
|
||||
refreshAfterUnlock = true
|
||||
refreshControl?.endRefreshing()
|
||||
unlockRequested()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func authenticationDidChange() {
|
||||
if (try? authentication?.state().unlocked) != true {
|
||||
operation?.cancel()
|
||||
}
|
||||
refreshState()
|
||||
}
|
||||
|
||||
@objc private func localStoreDidChange() {
|
||||
guard (try? authentication?.state().unlocked) == true else { return }
|
||||
loadPage()
|
||||
operation?.cancel()
|
||||
loadTask?.cancel()
|
||||
progressTask?.cancel()
|
||||
loadGeneration += 1
|
||||
operation = nil
|
||||
progressTask = nil
|
||||
tableView.tableHeaderView = nil
|
||||
page = nil
|
||||
loadCachedPage()
|
||||
}
|
||||
|
||||
@objc private func unlockRequested() {
|
||||
unlock(passphrase: nil)
|
||||
unlock(passphrase: nil, row: nil)
|
||||
}
|
||||
|
||||
@objc private func lockRequested() {
|
||||
@@ -1750,29 +1858,30 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
)
|
||||
return
|
||||
}
|
||||
if (try? authentication?.state().unlocked) == true {
|
||||
if page == nil || force { loadPage() }
|
||||
} else {
|
||||
loadTask?.cancel()
|
||||
page = nil
|
||||
tableView.reloadData()
|
||||
navigationItem.rightBarButtonItem = nil
|
||||
var configuration = UIContentUnavailableConfiguration.empty()
|
||||
configuration.image = UIImage(systemName: "lock.fill")
|
||||
configuration.text = "TOTP Is Locked"
|
||||
configuration.secondaryText =
|
||||
"Authenticate to scan password entries for time-based one-time passwords."
|
||||
configuration.button = .filled()
|
||||
configuration.button.title = "Unlock"
|
||||
configuration.buttonProperties.primaryAction = UIAction { [weak self] _ in
|
||||
self?.unlockRequested()
|
||||
}
|
||||
contentUnavailableConfiguration = configuration
|
||||
refreshControl?.endRefreshing()
|
||||
if force, (try? authentication?.state().unlocked) == true {
|
||||
loadPage()
|
||||
} else if page == nil, loadTask == nil {
|
||||
loadCachedPage()
|
||||
} else if page != nil {
|
||||
configureLockButton()
|
||||
}
|
||||
}
|
||||
|
||||
private func unlock(passphrase: String?) {
|
||||
private func reloadShell() {
|
||||
shellTask?.cancel()
|
||||
shellTask = Task { [weak self] in
|
||||
let shell = await Task.detached(priority: .userInitiated) { mobileShell() }.value
|
||||
guard
|
||||
!Task.isCancelled,
|
||||
let self,
|
||||
let page = shell.pages.first(where: { $0.tab == .totp })
|
||||
else { return }
|
||||
shellPage = page
|
||||
refreshState()
|
||||
}
|
||||
}
|
||||
|
||||
private func unlock(passphrase: String?, row: MobileTotpRow?) {
|
||||
guard let authentication else {
|
||||
presentAuthenticationFailure(.unavailable)
|
||||
return
|
||||
@@ -1782,8 +1891,13 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
unlockTask = Task { [weak self] in
|
||||
let result = await Task.detached(priority: .userInitiated) {
|
||||
do {
|
||||
return Result<MobileAuthenticationState, AuthenticationFailure>.success(
|
||||
let state = if let row {
|
||||
try authentication.unlockEntry(path: row.path, passphrase: passphrase)
|
||||
} else {
|
||||
try authentication.unlockTotp(passphrase: passphrase)
|
||||
}
|
||||
return Result<MobileAuthenticationState, AuthenticationFailure>.success(
|
||||
state
|
||||
)
|
||||
} catch let error as MobileAuthenticationFfiError {
|
||||
return .failure(AuthenticationFailure(error))
|
||||
@@ -1792,26 +1906,34 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
}.value
|
||||
guard !Task.isCancelled, let self else { return }
|
||||
contentUnavailableConfiguration = nil
|
||||
switch result {
|
||||
case .success:
|
||||
NotificationCenter.default.post(
|
||||
name: .ironStorageAuthenticationDidChange,
|
||||
object: authentication
|
||||
)
|
||||
loadPage()
|
||||
if refreshAfterUnlock || page == nil {
|
||||
refreshAfterUnlock = false
|
||||
loadPage()
|
||||
} else if let row {
|
||||
open(row)
|
||||
} else {
|
||||
configureLockButton()
|
||||
}
|
||||
UIAccessibility.post(notification: .announcement, argument: "TOTP unlocked")
|
||||
case let .failure(failure)
|
||||
where passphrase == nil
|
||||
&& (failure.kind == .passphraseRequired
|
||||
|| failure.kind == .biometryUnavailable):
|
||||
promptForPassphrase(message: failure.detail)
|
||||
promptForPassphrase(message: failure.detail, row: row)
|
||||
case let .failure(failure):
|
||||
if failure.kind != .cancelled { handle(failure) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func promptForPassphrase(message: String) {
|
||||
private func promptForPassphrase(message: String, row: MobileTotpRow?) {
|
||||
let alert = UIAlertController(
|
||||
title: "GPG Key Passphrase",
|
||||
message: message,
|
||||
@@ -1829,7 +1951,7 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
alert.addAction(UIAlertAction(title: "Unlock", style: .default) { [weak self, weak alert] _ in
|
||||
guard let value = alert?.textFields?.first?.text, !value.isEmpty else { return }
|
||||
alert?.textFields?.first?.text = nil
|
||||
self?.unlock(passphrase: value)
|
||||
self?.unlock(passphrase: value, row: row)
|
||||
})
|
||||
present(alert, animated: true)
|
||||
}
|
||||
@@ -1839,13 +1961,75 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
presentAuthenticationFailure(.unavailable)
|
||||
return
|
||||
}
|
||||
operation?.cancel()
|
||||
loadTask?.cancel()
|
||||
showLoading("Loading TOTP")
|
||||
progressTask?.cancel()
|
||||
loadGeneration += 1
|
||||
let current = loadGeneration
|
||||
let operation = mobileTotpOperation()
|
||||
self.operation = operation
|
||||
navigationItem.rightBarButtonItems = nil
|
||||
let discoveryView = TotpDiscoveryView { [weak self] in
|
||||
self?.cancelDiscovery()
|
||||
}
|
||||
apply(operation.progress(), to: discoveryView)
|
||||
tableView.tableHeaderView = discoveryView
|
||||
contentUnavailableConfiguration = nil
|
||||
progressTask = Task { [weak self] in
|
||||
while !Task.isCancelled {
|
||||
do {
|
||||
try await Task.sleep(for: .milliseconds(150))
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
guard !Task.isCancelled, let self, current == loadGeneration else { return }
|
||||
apply(operation.progress(), to: discoveryView)
|
||||
}
|
||||
}
|
||||
loadTask = Task { [weak self] in
|
||||
let result = await Task.detached(priority: .userInitiated) {
|
||||
do {
|
||||
return Result<MobileTotpPage, AuthenticationFailure>.success(
|
||||
try authentication.totpPage()
|
||||
try authentication.totpPage(operation: operation)
|
||||
)
|
||||
} catch let error as MobileAuthenticationFfiError {
|
||||
return .failure(AuthenticationFailure(error))
|
||||
} catch {
|
||||
return .failure(.unexpected)
|
||||
}
|
||||
}.value
|
||||
guard !Task.isCancelled, let self, current == loadGeneration else { return }
|
||||
progressTask?.cancel()
|
||||
progressTask = nil
|
||||
self.operation = nil
|
||||
loadTask = nil
|
||||
tableView.tableHeaderView = nil
|
||||
refreshControl?.endRefreshing()
|
||||
configureLockButton()
|
||||
switch result {
|
||||
case let .success(page):
|
||||
apply(page)
|
||||
case let .failure(failure):
|
||||
if failure.kind == .cancelled {
|
||||
loadCachedPage()
|
||||
} else {
|
||||
handle(failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func loadCachedPage() {
|
||||
guard let authentication else {
|
||||
presentAuthenticationFailure(.unavailable)
|
||||
return
|
||||
}
|
||||
loadTask?.cancel()
|
||||
loadTask = Task { [weak self] in
|
||||
let result = await Task.detached(priority: .userInitiated) {
|
||||
do {
|
||||
return Result<MobileTotpPage?, AuthenticationFailure>.success(
|
||||
try authentication.cachedTotpPage()
|
||||
)
|
||||
} catch let error as MobileAuthenticationFfiError {
|
||||
return .failure(AuthenticationFailure(error))
|
||||
@@ -1854,26 +2038,15 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
}.value
|
||||
guard !Task.isCancelled, let self else { return }
|
||||
refreshControl?.endRefreshing()
|
||||
loadTask = nil
|
||||
switch result {
|
||||
case let .success(page):
|
||||
self.page = page
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
||||
image: UIImage(systemName: "lock.fill"),
|
||||
style: .plain,
|
||||
target: self,
|
||||
action: #selector(lockRequested)
|
||||
)
|
||||
navigationItem.rightBarButtonItem?.accessibilityLabel = "Lock IronStorage"
|
||||
tableView.reloadData()
|
||||
if page.rows.isEmpty {
|
||||
showUnavailable(
|
||||
title: "No TOTP Codes",
|
||||
detail: "No valid time-based OTP entries were found in the password store.",
|
||||
image: "timer"
|
||||
)
|
||||
case let .success(.some(page)):
|
||||
apply(page)
|
||||
case .success(.none):
|
||||
if (try? authentication.state().unlocked) == true {
|
||||
loadPage()
|
||||
} else {
|
||||
contentUnavailableConfiguration = nil
|
||||
showLocked()
|
||||
}
|
||||
case let .failure(failure):
|
||||
handle(failure)
|
||||
@@ -1881,6 +2054,69 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
}
|
||||
|
||||
private func apply(_ page: MobileTotpPage) {
|
||||
self.page = page
|
||||
configureLockButton()
|
||||
tableView.reloadData()
|
||||
if page.rows.isEmpty {
|
||||
showUnavailable(
|
||||
title: "No TOTP Codes",
|
||||
detail: "No valid time-based OTP entries were found in the password store.",
|
||||
image: "timer"
|
||||
)
|
||||
} else {
|
||||
contentUnavailableConfiguration = nil
|
||||
}
|
||||
}
|
||||
|
||||
private func configureLockButton() {
|
||||
let unlocked = (try? authentication?.state().unlocked) == true
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
||||
image: UIImage(systemName: unlocked ? "lock.fill" : "lock.open.fill"),
|
||||
style: .plain,
|
||||
target: self,
|
||||
action: unlocked ? #selector(lockRequested) : #selector(unlockRequested)
|
||||
)
|
||||
navigationItem.rightBarButtonItem?.accessibilityLabel =
|
||||
unlocked ? "Lock IronStorage" : "Unlock IronStorage"
|
||||
}
|
||||
|
||||
private func showLocked() {
|
||||
page = nil
|
||||
tableView.reloadData()
|
||||
navigationItem.rightBarButtonItem = nil
|
||||
var configuration = UIContentUnavailableConfiguration.empty()
|
||||
configuration.image = UIImage(systemName: "lock.fill")
|
||||
configuration.text = "TOTP Is Locked"
|
||||
configuration.secondaryText =
|
||||
"Unlock once to discover time-based one-time-password entries."
|
||||
configuration.button = .filled()
|
||||
configuration.button.title = "Unlock"
|
||||
configuration.buttonProperties.primaryAction = UIAction { [weak self] _ in
|
||||
self?.unlockRequested()
|
||||
}
|
||||
contentUnavailableConfiguration = configuration
|
||||
refreshControl?.endRefreshing()
|
||||
}
|
||||
|
||||
private func cancelDiscovery() {
|
||||
operation?.cancel()
|
||||
}
|
||||
|
||||
private func apply(_ progress: MobileTotpDiscoveryProgress, to view: TotpDiscoveryView) {
|
||||
view.apply(progress)
|
||||
let width = tableView.bounds.width
|
||||
let height = view.systemLayoutSizeFitting(
|
||||
CGSize(width: width, height: UIView.layoutFittingCompressedSize.height),
|
||||
withHorizontalFittingPriority: .required,
|
||||
verticalFittingPriority: .fittingSizeLevel
|
||||
).height
|
||||
view.frame = CGRect(x: 0, y: 0, width: width, height: height)
|
||||
if tableView.tableHeaderView === view {
|
||||
tableView.tableHeaderView = view
|
||||
}
|
||||
}
|
||||
|
||||
private func handle(_ failure: AuthenticationFailure) {
|
||||
if failure.kind == .expired {
|
||||
NotificationCenter.default.post(
|
||||
@@ -1895,6 +2131,7 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
|
||||
private func showLoading(_ title: String) {
|
||||
tableView.backgroundView = nil
|
||||
var configuration = UIContentUnavailableConfiguration.loading()
|
||||
configuration.text = title
|
||||
configuration.secondaryText = "Reading OTP metadata in secure storage."
|
||||
@@ -1902,6 +2139,7 @@ private final class TotpListViewController: UITableViewController, MobileTabRoot
|
||||
}
|
||||
|
||||
private func showUnavailable(title: String, detail: String, image: String) {
|
||||
tableView.backgroundView = nil
|
||||
var configuration = UIContentUnavailableConfiguration.empty()
|
||||
configuration.image = UIImage(systemName: image)
|
||||
configuration.text = title
|
||||
|
||||
Reference in New Issue
Block a user