Skip to content

Commit 95784ac

Browse files
committed
Remove asyncMap
1 parent 047e331 commit 95784ac

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

FullStackTests/Tests/OATHFullStackTests.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ class OATHFullStackTests: XCTestCase {
5656
func testCalculateAllCodes() throws {
5757
runOATHTest { session in
5858
let result = try await session.calculateCodes(timestamp: Date(timeIntervalSince1970: 0))
59-
let codes = try await result.asyncMap { result in
60-
if let code = result.1 {
61-
return code
62-
}
63-
let credential = result.0
64-
if credential.requiresTouch {
65-
print("👆 Touch the YubiKey!")
59+
var codes: [OATHSession.Code] = []
60+
for pair in result {
61+
if let code = pair.1 {
62+
codes.append(code)
63+
} else {
64+
let credential = pair.0
65+
if credential.requiresTouch {
66+
print("👆 Touch the YubiKey!")
67+
}
68+
let code = try await session.calculateCode(
69+
credential: credential,
70+
timestamp: Date(timeIntervalSince1970: 0)
71+
)
72+
codes.append(code)
6673
}
67-
let code = try await session.calculateCode(
68-
credential: credential,
69-
timestamp: Date(timeIntervalSince1970: 0)
70-
)
71-
return code
7274
}
7375
XCTAssert(codes.count == 5)
7476
XCTAssert(codes[0].code == "659165")

YubiKit/YubiKit/OATH/OATHSession.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ public final actor OATHSession: Session {
317317
throw OATHSessionError.responseDataNotTLVFormatted
318318
}
319319

320-
return try await result.asyncMap { (name, response) in
320+
var credentialCodePairs: [(Credential, Code?)] = []
321+
for (name, response) in result {
321322
guard name.tag == 0x71 else { throw OATHSessionError.unexpectedTag }
322323

323324
guard let credentialId = CredentialIdParser(data: name.value) else { throw OATHSessionError.unexpectedData }
@@ -343,17 +344,20 @@ public final actor OATHSession: Session {
343344
if response.value.count == 5 {
344345
if credentialId.period != oathDefaultPeriod {
345346
let code = try await self.calculateCode(credential: credential, timestamp: timestamp)
346-
return (credential, code)
347+
credentialCodePairs.append((credential, code))
347348
} else {
348349
let digits = response.value.first!
349350
let code = UInt32(bigEndian: response.value.subdata(in: 1..<response.value.count).uint32)
350351
let stringCode = String(format: "%0\(digits)d", UInt(code))
351-
return (credential, Code(code: stringCode, timestamp: timestamp, credentialType: credentialType))
352+
credentialCodePairs.append(
353+
(credential, Code(code: stringCode, timestamp: timestamp, credentialType: credentialType))
354+
)
352355
}
353356
} else {
354-
return (credential, nil)
357+
credentialCodePairs.append((credential, nil))
355358
}
356359
}
360+
return credentialCodePairs
357361
}
358362

359363
/// Sets an Access Key derived from a password. Once a key is set, any usage of the credentials stored will

YubiKit/YubiKit/Utilities/Sequence+Extensions.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)