Exception: Smartcard::Iso::ApduError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/smartcard/iso/apdu_error.rb

Overview

Indicates an error code in an ISO-7618 response APDU.

This exception should be raised if the response obtained from iso_apdu has an error status. When raising the exception, supply the entire response as the only argument to raise.

Usage example:

response = transport.iso_apdu :ins => 0x12
raise Smartcard::Iso::ApduError, response unless response[:status] == 0x9000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ApduError

Creates a new exception (for raising).

Args:

response:: the APDU response (hash with +:data+ and +:status+ keys)


30
31
32
33
34
# File 'lib/smartcard/iso/apdu_error.rb', line 30

def initialize(response)
  @data = response[:data]
  @status = response[:status]
  super ApduError.message_for_apdu_response(response)
end

Instance Attribute Details

#dataObject

The data in the error APDU.



22
23
24
# File 'lib/smartcard/iso/apdu_error.rb', line 22

def data
  @data
end

#statusObject

The error status.



24
25
26
# File 'lib/smartcard/iso/apdu_error.rb', line 24

def status
  @status
end

Class Method Details

.message_for_apdu_response(response) ⇒ Object

Computes the exception message for an APDU response.



37
38
39
40
# File 'lib/smartcard/iso/apdu_error.rb', line 37

def self.message_for_apdu_response(response)
  "ISO-7816 response APDU has error status 0x#{'%04x' % response[:status]}" +
      " - #{response[:data].map { |ch| '%02x' % ch }.join(' ')}"
end