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

- `init(apdu:)`

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

- `init(apdu:apduOffset:apduLength:)`

  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

- `init(apdu:)`

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

- `init(apduDataBuffer:)`

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

- `init(apdu:)`

  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…”

- `init(apduString:)`

  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…”

- `init(cla:ins:p1:p2:)`

  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

- `init(cla:ins:p1:p2: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]) 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

- `init(cla:ins:p1:p2:data:ne:)`

  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)

- `init(cla:ins:p1:p2:data:dataOffset:dataLength:)`

  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

- `init(cla:ins:p1:p2:data:dataOffset:dataLength: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, 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)

- `init(cla:ins:p1:p2: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

- `getBytes()`

  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

- `getCLA()`

  Returns the value of the class byte CLA.

  #### Declaration

  Swift

      public func getCLA() -> UInt8

  #### Return Value

  Class byte CLA

- `getINS()`

  Returns the value of the instruction byte INS.

  #### Declaration

  Swift

      public func getINS() -> UInt8

  #### Return Value

  Instruction byte INS

- `getP1()`

  Returns the value of the parameter byte P1.

  #### Declaration

  Swift

      public func getP1() -> UInt8

  #### Return Value

  parameter byte P1

- `getP2()`

  Returns the value of the parameter byte P2.

  #### Declaration

  Swift

      public func getP2() -> UInt8

  #### Return Value

  parameter byte P2

- `getNc()`

  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)

- `getNe()`

  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)

- `getData()`

  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

- `toString()`

  Returns a string representation of this command APDU.

  #### Declaration

  Swift

      public func toString() -> String

  #### Return Value

  String representation of this command APDU

Copyright (c) 2018-2024, AB Circle Ltd. All rights reserved.

Generated by jazzy ♪♫ v0.14.3, a Realm project.