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.

SELECT Commands

  • selectMasterFile() Asynchronous

    Select 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.

  • Select 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.

READ Commands

  • 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.

    See also

    DataGroup and DGTag

    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() Asynchronous

    Read 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 file EF.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

    CardAccess and PACEHandler

    Declaration

    Swift

    func readCardAccess() async throws -> [UInt8]

    Return Value

    An array of bytes representing the CardAccess data.

  • readFile() Asynchronous

    Read 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.

AUTHENTICATION Commands

  • getChallenge() Asynchronous

    Get 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

    BACHandler

    Declaration

    Swift

    func getChallenge() async throws -> APDUResponse

    Return Value

    An APDUResponse representing the challenge.

  • 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

    BACHandler

    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.

  • 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.

    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.

  • 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.

    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.

  • Send a general authentication command.

    Throws

    An error if sending the command fails or if the tag sends back an error within its response.

    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.