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
amountThe 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
NFCISO7816APDUcommand 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 -> APDUResponseParameters
cmdThe
NFCISO7816APDUcommand to send.Return Value
An
APDUResponserepresenting 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 -> APDUResponseReturn Value
An
APDUResponserepresenting 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 -> APDUResponseReturn Value
An
APDUResponserepresenting 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 -> APDUResponseParameters
fileThe file identifier to select.
Return Value
An
APDUResponserepresenting 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
dataGroupThe Data Group to read.
Return Value
An array of bytes representing the data read.
-
readCardAccess()AsynchronousRead the
CardAccessdata.By default,
NFCISO7816Tagrequires 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
PACEprotocol because it requires reading parameters from fileEF.CardAccesswhich 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
CardAccessdata. -
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 -> APDUResponseReturn Value
An
APDUResponserepresenting 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 -> APDUResponseParameters
dataThe data for mutual authentication.
Return Value
An
APDUResponserepresenting 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 -> APDUResponseParameters
publicKeyThe public key data for key agreement.
keyIdThe optional key ID data.
Return Value
An
APDUResponserepresenting 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 -> APDUResponseParameters
dataThe data for the authentication template.
usageThe usage type of the authentication template.
Return Value
An
APDUResponserepresenting 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 -> APDUResponseParameters
dataThe data for authentication.
isLastA flag indicating if this is the last authentication step.
Return Value
An
APDUResponserepresenting the response from the tag.
View on GitHub
TagReader Class Reference