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]) throwsParameters
apdubyte 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) throwsParameters
apduByte 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) throwsParameters
apduData 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) throwsParameters
apduDataBufferData 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) throwsParameters
apduString 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) throwsParameters
apduStringString 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) throwsParameters
claCLA header byte
insINS header byte
p1P1 header byte
p2P2 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]) throwsParameters
claCLA header byte
insINS header byte
p1P1 header byte
p2P2 header byte
dataByte 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) throwsParameters
claCLA header byte
insINS header byte
p1P1 header byte
p2P2 header byte
dataByte array holding the command data
neExpected 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) throwsParameters
claCLA header byte
insINS header byte
p1P1 header byte
p2P2 header byte
dataByte array holding the command data
dataOffsetStart offset of the command data within the byte array
dataLengthLength 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) throwsParameters
claCLA header byte
insINS header byte
p1P1 header byte
p2P2 header byte
dataByte array holding the command data
dataOffsetStart offset of the command data within the byte array
dataLengthLength of the command data
neExpected 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() -> DataReturn Value
Data buffer holding the bytes of this APDU
-
Returns the value of the class byte CLA.
Declaration
Swift
public func getCLA() -> UInt8Return Value
Class byte CLA
-
Returns the value of the instruction byte INS.
Declaration
Swift
public func getINS() -> UInt8Return Value
Instruction byte INS
-
Returns the value of the parameter byte P1.
Declaration
Swift
public func getP1() -> UInt8Return Value
parameter byte P1
-
Returns the value of the parameter byte P2.
Declaration
Swift
public func getP2() -> UInt8Return 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() -> UInt32Return 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() -> UInt32Return 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() -> DataReturn Value
Copy of the data bytes in the command body
-
Returns a string representation of this command APDU.
Declaration
Swift
public func toString() -> StringReturn Value
String representation of this command APDU
CommandAPDU Class Reference