TagReader
internal final class TagReader
A class for reading data from and communicating with an NFC ISO7816 tag through APDU (Application Protocol Data Unit) commands.
-
Declaration
Swift
internal var progress: ((Int) -> ())?
-
Declaration
Swift
internal var secureSession: NFCSecureSession
-
Declaration
Swift
internal init(tag: NFCISO7816Tag)
-
Override the maximum data amount to read.
Declaration
Swift
internal func overrideDataAmountToRead(amount: Int)
Parameters
amount
The new maximum data amount to read.
-
Reduce the data amount to read if it’s greater than 0xA0.
Declaration
Swift
internal func reduceDataAmountToRead()
-
send(cmd:
Asynchronous) Send an
NFCISO7816APDU
command to the tag and handle secure session if established.Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
internal func send(cmd: NFCISO7816APDU) async throws -> APDUResponse
Parameters
cmd
The
NFCISO7816APDU
command to send.Return Value
An
APDUResponse
representing the response from the tag.
-
selectMasterFile()
AsynchronousSelect the master file.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
func selectMasterFile() async throws -> APDUResponse
Return Value
An
APDUResponse
representing the response from the tag. -
selectPassportApplication()
AsynchronousSelect the passport application file.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
func selectPassportApplication() async throws -> APDUResponse
Return Value
An
APDUResponse
representing the response from the tag. -
selectFile(file:
Asynchronous) Select a specific file by providing its file identifier.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
func selectFile(file: [UInt8]) async throws -> APDUResponse
Parameters
file
The file identifier to select.
Return Value
An
APDUResponse
representing the response from the tag.
-
readDataGroup(_:
Asynchronous) Read data from a specified Data Group.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
func readDataGroup(_ dataGroup: DGTag?) async throws -> [UInt8]
Parameters
dataGroup
The Data Group to read.
Return Value
An array of bytes representing the data read.
-
readCardAccess()
AsynchronousRead the
CardAccess
data.By default,
NFCISO7816Tag
requires a list of ISO/IEC 7816 applets (AIDs). Upon discovery of an NFC tag, the first found applet from this list is automatically selected, and you have no way of changing this.This is a problem for the
PACE
protocol because it requires reading parameters from fileEF.CardAccess
which lies outside of eMRTD applet (AID: A0000002471001) in the master file.Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func readCardAccess() async throws -> [UInt8]
Return Value
An array of bytes representing the
CardAccess
data. -
readFile()
AsynchronousRead a file from the tag.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
Declaration
Swift
func readFile() async throws -> [UInt8]
Return Value
An array of bytes representing the data read.
-
getChallenge()
AsynchronousGet a challenge for authentication.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func getChallenge() async throws -> APDUResponse
Return Value
An
APDUResponse
representing the challenge. -
sendMutualAuthenticate(data:
Asynchronous) Send a mutual authentication command.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func sendMutualAuthenticate(data: Data) async throws -> APDUResponse
Parameters
data
The data for mutual authentication.
Return Value
An
APDUResponse
representing the response from the tag. -
sendMSEKAT(publicKey:
AsynchronouskeyId: ) Send a Manage Security Environment (MSE) command for key agreement.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func sendMSEKAT(publicKey: Data, keyId: Data?) async throws -> APDUResponse
Parameters
publicKey
The public key data for key agreement.
keyId
The optional key ID data.
Return Value
An
APDUResponse
representing the response from the tag. -
sendMSESetAT(data:
Asynchronousfor: ) Send a Manage Security Environment (MSE) command for setting an authentication template.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func sendMSESetAT(data: Data, for usage: APDUCommand.ManageSecurityEnvironment.AuthenticationTemplateUsege) async throws -> APDUResponse
Parameters
data
The data for the authentication template.
usage
The usage type of the authentication template.
Return Value
An
APDUResponse
representing the response from the tag. -
sendGeneralAuthenticate(data:
AsynchronousisLast: ) Send a general authentication command.
Throws
An error if sending the command fails or if the tag sends back an error within its response.
See also
Declaration
Swift
func sendGeneralAuthenticate(data: Data, isLast: Bool = false) async throws -> APDUResponse
Parameters
data
The data for authentication.
isLast
A flag indicating if this is the last authentication step.
Return Value
An
APDUResponse
representing the response from the tag.