Closed etjenymeraj closed 6 months ago
func selectHcaCommand() -> CommandType {
let applicationIdentifier = EgkFileSystem.DF.HCA.aid
return HealthCardCommand.Select.selectFile(with: applicationIdentifier)
}
func readHCAPDCommandShort() throws -> CommandType {
guard let shortFileIdentifier = EgkFileSystem.EF.hcaPD.sfid else { throw HealthCardCommandError.hcaPDUnavailable }
return try HealthCardCommand.Read.readFileCommand(with: shortFileIdentifier, ne: APDU.expectedLengthWildcardShort)
}
func readHCAPDCommand() throws -> CommandType {
try HealthCardCommand.Read.readFileCommand(ne: APDU.expectedLengthWildcardExtended, offset: 2)
}
try await card.selectHca()
let hcaPDDataShort = try await card.readHCAPDShort()
print("##########")
print("NFC DATA PD Hex \(hcaPDDataShort!.hexString)")
print("##########")
print("NFC DATA PD Bytes \([UInt8](hcaPDDataShort!))")
let hcaPDData = try await card.readHCAPD()
print("##########")
print("NFC DATA PD Hex \(hcaPDData!.hexString)")
print("##########")
print("NFC DATA PD Bytes \([UInt8](hcaPDData!))")
extension Data { var hexString: String { Array(self) .map { $0.hexString } .joined(separator: "") } }
extension UInt8 { var hexString: String { var result = String(self, radix: 16, uppercase: true)
while result.count < 2 {
result = "0" + result
}
return result
}
}
func selectHca() async throws {
let command = selectHcaCommand()
return try await send(command: command)
}
func readHCAPDShort() async throws -> Data? {
let command = try readHCAPDCommandShort()
return try await send(command: command)
}
func readHCAPD() async throws -> Data? {
let command = try readHCAPDCommand()
return try await send(command: command)
}
Leaving this for anyone else here. The above commands work fine. The format you get is gzip. So you need to decompress the gzip. Then you get data which you need to convert to string. Not using utf 8 but rather
String(data: unzippedData!, encoding: .windowsCP1250))")
@etjenymeraj Hey can I ask how you decoded the hexString that is returned from the PD file?
In the current project Im reading a lot of values from root folder such as gdo atr etc. This reading works just fine.
However when I switch to HCA folder (DF.HCA) and I use the already built command methods from the library to read (EF.PD) the data bytes I receive or the hex code is incomplete.
My EF.PD command printed
First PD command - cla: 00 ins: B0 p1: 82 p2: 00 ne: 256 Second PD command - cla: 00 ins: B0 p1: 00 p2: 08 ne: 65536
I tried running commands in this order but also just running second command directly. The result is the same.
Can you advise any potential solutions here?