CommandApdu class

One ISO 7816-4 command APDU, and the rules for putting it on the wire.

The package could already tell you whether a card takes extended-length APDUs -- IsoDep.isExtendedLengthApduSupported -- while giving you nothing that could build one, so every caller wrote the Lc and Le fields by hand. That is a quiet thing to get wrong. The four ISO 7816-4 cases differ only in where the length bytes sit, and a command assembled for the wrong case is still a syntactically valid APDU: the card answers 6700, or reads a data field that starts three bytes off, rather than reporting anything that names the mistake.

The short form is used whenever the sizes fit it. Data longer than 255 bytes or an expectedResponseLength above 256 leaves no choice but the extended form, and forceExtended asks for it outright -- whether a particular card accepts extended APDUs is the caller's knowledge, not something the lengths can imply.

final select = CommandApdu(
  instructionClass: 0x00,
  instructionCode: 0xA4,
  p1Parameter: 0x04,
  p2Parameter: 0x00,
  data: applicationId,
  expectedResponseLength: 256,
);
final response = await card.sendCommandRaw(select.toBytes());

Constructors

CommandApdu({required int instructionClass, required int instructionCode, required int p1Parameter, required int p2Parameter, Uint8List? data, int? expectedResponseLength, bool forceExtended = false})
Constructs a command, rejecting values that cannot be encoded.
factory

Properties

data Uint8List?
The command data field, or null when the command carries none.
final
expectedResponseLength int?
How many bytes of response the command asks for, or null when it asks for none.
final
forceExtended bool
Whether the extended form was asked for even though the lengths fit the short one.
final
hashCode int
The hash code for this object.
no setterinherited
instructionClass int
CLA.
final
instructionCode int
INS.
final
isExtended bool
Whether toBytes writes the extended length fields.
no setter
p1Parameter int
P1.
final
p2Parameter int
P2.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toBytes() Uint8List
Encodes the command per ISO 7816-4.
toString() String
A string representation of this object.
override
withExpectedResponseLength(int expectedResponseLength) CommandApdu
The same command asking for expectedResponseLength bytes instead.

Operators

operator ==(Object other) bool
The equality operator.
inherited