diff --git a/Sources/Keycard/CashCommandSet.swift b/Sources/Keycard/CashCommandSet.swift index f5ce329..35ae89d 100644 --- a/Sources/Keycard/CashCommandSet.swift +++ b/Sources/Keycard/CashCommandSet.swift @@ -3,8 +3,12 @@ import Foundation public class CashCommandSet { let cardChannel: CardChannel + public init(cardChannel: CardChannel) { + self.cardChannel = cardChannel + } + public func select() throws -> APDUResponse { - let selectApplet: APDUCommand = APDUCommand(cla: CLA.iso7816.rawValue, ins: ISO7816INS.select.rawValue, p1: 0x04, p2: 0x00, data: Identifier.keycardCashInstanceAID) + let selectApplet: APDUCommand = APDUCommand(cla: CLA.iso7816.rawValue, ins: ISO7816INS.select.rawValue, p1: 0x04, p2: 0x00, data: Identifier.keycardCashInstanceAID.val) return try cardChannel.send(selectApplet) } diff --git a/Sources/Keycard/KeycardCommandSet.swift b/Sources/Keycard/KeycardCommandSet.swift index f0d38cc..39f37c8 100644 --- a/Sources/Keycard/KeycardCommandSet.swift +++ b/Sources/Keycard/KeycardCommandSet.swift @@ -84,11 +84,15 @@ public class KeycardCommandSet { public func setNDEF(ndef: [UInt8]) throws -> APDUResponse { let len = (Int(ndef[0]) << 8) | Int(ndef[1]) + var finalNDEF: [UInt8] + if len != (ndef.count - 2) { - ndef = [UInt8(ndef.count >> 8), UInt8(ndef.count & 0xff)] + ndef + finalNDEF = [UInt8(ndef.count >> 8), UInt8(ndef.count & 0xff)] + ndef + } else { + finalNDEF = ndef } - return try storeData(data: ndef, type: StoreDataP1.ndef.rawValue) + return try storeData(data: finalNDEF, type: StoreDataP1.ndef.rawValue) } public func storeData(data: [UInt8], type: UInt8) throws -> APDUResponse { @@ -97,7 +101,7 @@ public class KeycardCommandSet { } public func getData(type: UInt8) throws -> APDUResponse { - let cmd = secureChannel.protectedCommand(cla: CLA.proprietary.rawValue, ins: KeycardINS.getData.rawValue, p1: type, p2: 0, data: data) + let cmd = secureChannel.protectedCommand(cla: CLA.proprietary.rawValue, ins: KeycardINS.getData.rawValue, p1: type, p2: 0, data: []) return try secureChannel.transmit(channel: cardChannel, cmd: cmd) }