Skip to content

Commit

Permalink
Fixes bug when using NFC to calculate codes in OATH sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Dec 1, 2023
1 parent 9b27492 commit ee7b994
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
22 changes: 8 additions & 14 deletions Samples/OATHSample/OATHSample/OATHListModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OATHListModel: ObservableObject {
error = nil
let connection = try await ConnectionHelper.anyWiredConnection()
guard !Task.isCancelled else { return }
self.calculateCodes(connection: connection)
try await self.calculateCodes(connection: connection)
self.error = await connection.connectionDidClose()
self.accounts.removeAll()
self.source = "no connection"
Expand All @@ -54,7 +54,7 @@ class OATHListModel: ObservableObject {
do {
self.error = nil
let connection = try await NFCConnection.connection()
calculateCodes(connection: connection)
try await calculateCodes(connection: connection)
await connection.nfcConnection?.close(message: "Code calculated")
} catch {
self.error = error
Expand All @@ -63,18 +63,12 @@ class OATHListModel: ObservableObject {
}
#endif

@MainActor private func calculateCodes(connection: Connection) {
Task {
self.error = nil
do {
let session = try await OATHSession.session(withConnection: connection)
let result = try await session.calculateCodes()
self.accounts = result.map { return Account(label: $0.0.label, code: $0.1?.code ?? "****") }
self.source = connection.connectionType
} catch {
self.error = error
}
}
private func calculateCodes(connection: Connection) async throws {
self.error = nil
let session = try await OATHSession.session(withConnection: connection)
let result = try await session.calculateCodes()
self.accounts = result.map { return Account(label: $0.0.label, code: $0.1?.code ?? "****") }
self.source = connection.connectionType
}
}

Expand Down
3 changes: 2 additions & 1 deletion YubiKit/YubiKit/NFCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public final actor NFCConnection: Connection, InternalConnection {
}

internal func send(apdu: APDU) async throws -> Response {
guard let tag else { throw ConnectionError.noConnection }
print(self.tagReaderSession)
guard let tag else { throw "No taag fro some reason" }
guard let apdu = apdu.nfcIso7816Apdu else { throw NFCConnectionError.malformedAPDU }
let result: (Data, UInt8, UInt8) = try await tag.sendCommand(apdu: apdu)
return Response(data: result.0, sw1: result.1, sw2: result.2)
Expand Down

0 comments on commit ee7b994

Please sign in to comment.