fix small error
This commit is contained in:
parent
ca5c049bc7
commit
704700228c
|
@ -16,7 +16,7 @@ public struct APDUResponse {
|
|||
precondition(rawData.count >= 2, "rawData must contain at least the Status Word (2 bytes)")
|
||||
self.sw1 = rawData[rawData.count - 2]
|
||||
self.sw2 = rawData[rawData.count - 1]
|
||||
self.data = rawData.count > 2 ? Array(rawData[0..<(rawData.count - 3)]) : []
|
||||
self.data = rawData.count > 2 ? Array(rawData.prefix(upTo: rawData.count - 2)) : []
|
||||
}
|
||||
|
||||
public init(sw1: UInt8, sw2: UInt8, data: [UInt8]) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Foundation
|
||||
|
||||
public enum CardError: Error {
|
||||
case wrongPIN(retryCounter: Int)
|
||||
case unrecoverableSignature
|
||||
|
@ -8,3 +10,22 @@ public enum CardError: Error {
|
|||
case invalidMac
|
||||
case communicationError
|
||||
}
|
||||
|
||||
extension CardError: Equatable {
|
||||
|
||||
public static func ==(lhs: CardError, rhs: CardError) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case (.wrongPIN(let lattempt), .wrongPIN(let rattempt)): return lattempt == rattempt
|
||||
case (.unrecoverableSignature, .unrecoverableSignature),
|
||||
(.invalidState, .invalidState),
|
||||
(.notPaired, .notPaired),
|
||||
(.pinBlocked, .pinBlocked),
|
||||
(.invalidAuthData, .invalidAuthData),
|
||||
(.invalidMac, .invalidMac),
|
||||
(.communicationError, .communicationError):
|
||||
return true
|
||||
default: return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,8 +107,7 @@ extension KeycardController: NFCTagReaderSessionDelegate {
|
|||
}
|
||||
session.connect(to: first) { [weak self] error in
|
||||
guard let `self` = self else { return }
|
||||
if let error = error {
|
||||
// TODO: should I call onFailure() explicitly here?
|
||||
if error != nil {
|
||||
self.stop(errorMessage: self.alertMessages.tagConnectionError)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -123,6 +123,7 @@ class SecureChannel {
|
|||
let finalData: [UInt8];
|
||||
|
||||
if open {
|
||||
Logger.shared.log("SecureChannel: ==> protected: (cla=\(String(cla, radix:16)) ins=\(String(ins, radix:16)) p1=\(String(p1, radix:16)) p2=\(String(p2, radix:16)) data:\(Data(data).toHexString()))")
|
||||
let encrypted = encryptAPDU(data);
|
||||
let meta: [UInt8] = [cla, ins, p1, p2, UInt8(encrypted.count + SecureChannel.blockLength), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
updateIV(meta: meta, data: encrypted);
|
||||
|
@ -153,8 +154,9 @@ class SecureChannel {
|
|||
if self.iv != mac {
|
||||
throw CardError.invalidMac
|
||||
}
|
||||
|
||||
return APDUResponse(rawData: plainData)
|
||||
let result = APDUResponse(rawData: plainData)
|
||||
Logger.shared.log("SecureChannel: <== decrypted: (data=\(Data(result.data).toHexString()) sw1=\(String(result.sw1, radix:16)) sw2=\(String(result.sw2, radix:16)))")
|
||||
return result
|
||||
} else {
|
||||
return rsp;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue