CardChannel
public protocol CardChannel : AnyObject
A logical channel connection to a Smart Card. It is used to exchange APDUs
with a Smart Card. A CardChannel object can be obtained by calling the
method Card.basicChannel()
or Card.openLogicalChannel()
.
See also
See also
See also
Version
1.0
Date
6 Nov 2017
-
Returns the Card this channel is associated with.
Declaration
Swift
var card: Card { get }
-
Returns the channel number of this CardChannel. A channel number of 0 indicates the basic logical channel.
Throws
CardError.illegalState
if this channel has been closed or if the corresponding Card has been disconnectedDeclaration
Swift
func channelNumber() throws -> UInt8
Return Value
the channel number of this CardChannel
-
Transmits the specified command APDU to the Smart Card and returns the response APDU.
The CLA byte of the command APDU is automatically adjusted to match the channel number of this CardChannel.
Note that this method cannot be used to transmit
MANAGE CHANNEL
APDUs. Logical channels should be managed using theCard.openLogicalChannel()
andCardChannel.close()
methods.Implementations should transparently handle artifacts of the transmission protocol. For example, when using the T=0 protocol, the following processing should occur as described in ISO/IEC 7816-4:
if the response APDU has an SW1 of
61
, the implementation should issue aGET RESPONSE
command usingSW2
as theLe
field. This process is repeated as long as an SW1 of61
is received. The response body of these exchanges is concatenated to form the final response body.if the response APDU is
6C XX
, the implementation should reissue the command usingXX
as theLe
field.
The
ResponseAPDU
returned by this method is the result after this processing has been performed.Throws
CardError.illegalState
if this channel has been closed or if the corresponding Card has been disconnected;CardError.illegalArgument
if the APDU encodes aMANAGE CHANNEL
command;CardError.operationFailed
if the card operation failedDeclaration
Swift
func transmit(apdu: CommandAPDU) throws -> ResponseAPDU
Parameters
apdu
the command APDU
Return Value
the response APDU received from the card
-
Transmits the command APDU stored in the command data buffer and receives the response APDU in the response data buffer.
The command buffer must contain valid command APDU data. Upon return, the command buffer’s position will be equal to its limit; its limit will not have changed. The output buffer will have received the response APDU bytes. Its position will have advanced by the number of bytes received, which is also the return value of this method.
The CLA byte of the command APDU is automatically adjusted to match the channel number of this CardChannel.
Note that this method cannot be used to transmit
MANAGE CHANNEL
APDUs. Logical channels should be managed using theCard.openLogicalChannel()
andCardChannel.close()
methods.See
transmit(apdu:)
for a discussion of the handling of response APDUs with the SW1 values61
or6C
.Throws
CardError.illegalState
if this channel has been closed or if the corresponding Card has been disconnected;CardError.illegalArgument
if command and response are the same object, ifresponse
may not have sufficient space to receive the response APDU or if the APDU encodes aMANAGE CHANNEL
command;CardError.operationFailed
if the card operation failedDeclaration
Swift
func transmit(buffer: [UInt8]) throws -> [UInt8]
Parameters
buffer
the buffer containing the command APDU
Return Value
the buffer that shall receive the response APDU from the card
-
Transmits the command APDU stored in the command data buffer and receives the response APDU in the response data buffer.
The command buffer must contain valid command APDU data. Upon return, the command buffer’s position will be equal to its limit; its limit will not have changed. The output buffer will have received the response APDU bytes. Its position will have advanced by the number of bytes received, which is also the return value of this method.
The CLA byte of the command APDU is automatically adjusted to match the channel number of this CardChannel.
Note that this method cannot be used to transmit
MANAGE CHANNEL
APDUs. Logical channels should be managed using theCard.openLogicalChannel()
andCardChannel.close()
methods.See
transmit(apdu:)
for a discussion of the handling of response APDUs with the SW1 values61
or6C
.Throws
CardError.illegalState
if this channel has been closed or if the corresponding Card has been disconnected;CardError.illegalArgument
if command and response are the same object, ifresponse
may not have sufficient space to receive the response APDU or if the APDU encodes aMANAGE CHANNEL
command;CardError.operationFailed
if the card operation failedDeclaration
Swift
func transmit(data: Data) throws -> Data
Parameters
data
the buffer containing the command APDU
Return Value
the buffer that shall receive the response APDU from the card
-
Closes this CardChannel. The logical channel is closed by issuing a
MANAGE CHANNEL
command that should use the format[xx 70 80 0n]
wheren
is the channel number of this channel andxx
is theCLA
byte that encodes this logical channel and has all other bits set to 0. After this method returns, calling other methods in this class will raise aCardError.illegalState
.Note that the basic logical channel cannot be closed using this method. It can be closed by calling
Card.disconnect(reset:)
.Throws
CardError.operationFailed
if the card operation failed;CardError.illegalState
if this CardChannel represents a connection to the basic logical channelDeclaration
Swift
func close() throws