CommandAPDU
@objcMembers
public class CommandAPDU : BaseClass
SmartCardIO - CommandAPDU Class
A command APDU following the structure defined in ISO/IEC 7816-4. It consists of a four byte header and a conditional body of variable length. This class does not attempt to verify that the APDU encodes a semantically valid command.
Note that when the expected length of the response APDU is specified in the constructors, the actual length (Ne) must be specified, not its encoded form (Le). Similarly, getNe() returns the actual value Ne. In other words, a value of 0 means “no data in the response APDU” rather than “maximum length.”
This class supports both the short and extended forms of length encoding for Ne and Nc. However, note that not all terminals and Smart Cards are capable of accepting APDUs that use the extended form.
-
Initialiser; constructs a CommandAPDU from a byte array containing the complete APDU contents (header and body).
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(apdu: [UInt8]) throws
Parameters
apdu
byte array containing the complete APDU contents (header and body).
-
Initialiser; constructs a CommandAPDU from a byte array containing the complete APDU contents (header and body).
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(apdu: [UInt8], apduOffset: UInt32, apduLength: UInt32) throws
Parameters
apdu
Byte array containing the complete APDU contents (header and body).
- apduOffset: Start offset of the APDU contents within the byte array
- apduLength: Length of the APDU contents
-
Initialiser; constructs a CommandAPDU from a Data buffer containing the complete APDU contents (header and body).
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@nonobjc public init(apdu: Data) throws
Parameters
apdu
Data buffer containing the complete APDU contents (header and body).
-
Initialiser; constructs a CommandAPDU from a Data buffer containing the complete APDU contents (header and body).
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(apduDataBuffer: Data) throws
Parameters
apduDataBuffer
Data buffer containing the complete APDU contents (header and body).
-
Initialiser; contructs a CommandAPDU from a String containing the complete APDU contents (header and body) in hexadecimal format.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@nonobjc public init(apdu: String) throws
Parameters
apdu
String in the form “AF 09 …or AF09…”
-
Initialiser; contructs a CommandAPDU from a String containing the complete APDU contents (header and body) in hexadecimal format.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(apduString: String) throws
Parameters
apduString
String in the form “AF 09 …or AF09…”
-
Initialiser; constructs a CommandAPDU from the four header bytes.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8) throws
Parameters
cla
CLA header byte
ins
INS header byte
p1
P1 header byte
p2
P2 header byte
-
Initialiser; constructs a CommandAPDU from the four header bytes and command data.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8]) throws
Parameters
cla
CLA header byte
ins
INS header byte
p1
P1 header byte
p2
P2 header byte
data
Byte array holding the command data
-
Initialiser; constructs a CommandAPDU from the four header bytes, command data, and expected response data length.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8], ne: UInt32) throws
Parameters
cla
CLA header byte
ins
INS header byte
p1
P1 header byte
p2
P2 header byte
data
Byte array holding the command data
ne
Expected response length (Ne)
-
Initialiser; constructs a CommandAPDU from the four header bytes and command data.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8], dataOffset: UInt32, dataLength: UInt32) throws
Parameters
cla
CLA header byte
ins
INS header byte
p1
P1 header byte
p2
P2 header byte
data
Byte array holding the command data
dataOffset
Start offset of the command data within the byte array
dataLength
Length of the command data
-
Initialiser; constructs a CommandAPDU from the four header bytes and command data.
Throws
Status.StatusCode on failure (see enum Status.StatusCode for possible values)
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, data: [UInt8], dataOffset: UInt32, dataLength: UInt32, ne: UInt32) throws
Parameters
cla
CLA header byte
ins
INS header byte
p1
P1 header byte
p2
P2 header byte
data
Byte array holding the command data
dataOffset
Start offset of the command data within the byte array
dataLength
Length of the command data
ne
Expected response length (Ne)
-
Constructs a CommandAPDU from the four header bytes and the expected response data length.
Declaration
Swift
@objc public init(cla: UInt8, ins: UInt8, p1: UInt8, p2: UInt8, ne: UInt32) throws
-
Returns a copy of the bytes in this APDU.
Declaration
Swift
public func getBytes() -> Data
Return Value
Data buffer holding the bytes of this APDU
-
Returns the value of the class byte CLA.
Declaration
Swift
public func getCLA() -> UInt8
Return Value
Class byte CLA
-
Returns the value of the instruction byte INS.
Declaration
Swift
public func getINS() -> UInt8
Return Value
Instruction byte INS
-
Returns the value of the parameter byte P1.
Declaration
Swift
public func getP1() -> UInt8
Return Value
parameter byte P1
-
Returns the value of the parameter byte P2.
Declaration
Swift
public func getP2() -> UInt8
Return Value
parameter byte P2
-
Returns the number of data bytes in the command body (Nc) or 0 if this APDU has no body.
Declaration
Swift
public func getNc() -> UInt32
Return Value
number of data bytes in the command body (Nc)
-
Returns the maximum number of expected data bytes in a response APDU (Ne).
Declaration
Swift
public func getNe() -> UInt32
Return Value
maximum number of expected data bytes in a response APDU (Ne)
-
Returns a copy of the data bytes in the command body.
Declaration
Swift
public func getData() -> Data
Return Value
Copy of the data bytes in the command body
-
Returns a string representation of this command APDU.
Declaration
Swift
public func toString() -> String
Return Value
String representation of this command APDU