parseResponse method

  1. @override
VtjCommandResult<Uint8List> parseResponse(
  1. Uint8List response
)
override

Parse the response bytes from the device.

Implementation

@override
VtjCommandResult<Uint8List> parseResponse(Uint8List response) {
  // Expected format: [commandId, status, 16-byte challenge]
  if (response.length < 18) {
    return const VtjCommandResult.failure('Invalid response length', null);
  }

  if (response[0] != commandId) {
    return const VtjCommandResult.failure('Invalid command ID in response', null);
  }

  final status = response[1];

  if (status == 0x00) {
    // Success: next 16 bytes are the auth challenge key
    return VtjCommandResult.success(
      Uint8List.fromList(response.sublist(2, 18)),
    );
  }

  if (status == 0x02) {
    return const VtjCommandResult.failure('Invalid arguments', 2);
  }

  return VtjCommandResult.failure(
    'Auth challenge failed with status: 0x${status.toRadixString(16).padLeft(2, '0')}',
    status,
  );
}