Class: Smartcard::Iso::JcopRemoteTransport
- Inherits:
-
Object
- Object
- Smartcard::Iso::JcopRemoteTransport
- Includes:
- IsoCardMixin, JcopRemoteProtocol
- Defined in:
- lib/smartcard/iso/jcop_remote_transport.rb
Overview
Implements the transport layer for a JCOP simulator instance.
Instance Method Summary collapse
-
#card_atr ⇒ Object
:nodoc: standard transport method.
-
#connect ⇒ Object
Makes a transport-level connection to the TEM.
-
#disconnect ⇒ Object
Breaks down the transport-level connection to the TEM.
-
#exchange_apdu(apdu) ⇒ Object
:nodoc: standard transport method.
-
#initialize(options) ⇒ JcopRemoteTransport
constructor
Creates a new unconnected transport for a JCOP simulator serving TCP/IP.
- #to_s ⇒ Object
Methods included from JcopRemoteProtocol
Methods included from IsoCardMixin
deserialize_response, #iso_apdu, #iso_apdu!, serialize_apdu
Constructor Details
#initialize(options) ⇒ JcopRemoteTransport
Creates a new unconnected transport for a JCOP simulator serving TCP/IP.
The options parameter must have the following keys:
host:: the DNS name or IP of the host running the JCOP simulator
port:: the TCP/IP port of the JCOP simulator server
23 24 25 26 27 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 23 def initialize() @host, @port = [:host], [:port] @socket = nil @atr = nil end |
Instance Method Details
#card_atr ⇒ Object
:nodoc: standard transport method
39 40 41 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 39 def card_atr @atr end |
#connect ⇒ Object
Makes a transport-level connection to the TEM.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 44 def connect begin @socket = Zerg::Support::SocketFactory.socket :out_addr => @host, :out_port => @port, :no_delay => true raise 'Connection refused' unless @socket # Wait for the card to be inserted. @socket, :type => 0, :node => 0, :data => [0, 1, 0, 0] = @socket @atr = [:data].pack('C*') rescue Exception @socket = nil raise end end |
#disconnect ⇒ Object
Breaks down the transport-level connection to the TEM.
61 62 63 64 65 66 67 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 61 def disconnect if @socket @socket.close @socket = nil @atr = nil end end |
#exchange_apdu(apdu) ⇒ Object
:nodoc: standard transport method
30 31 32 33 34 35 36 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 30 def exchange_apdu(apdu) @socket, :type => 1, :node => 0, :data => apdu loop do = @socket return [:data] if [:type] == 1 end end |
#to_s ⇒ Object
69 70 71 72 |
# File 'lib/smartcard/iso/jcop_remote_transport.rb', line 69 def to_s "#<JCOP Remote Terminal: disconnected>" if @socket.nil? "#<JCOP Remote Terminal: #{@host}:#{@port}>" end |