Class: ISO7816::Card::PCSCCard

Inherits:
Card
  • Object
show all
Defined in:
lib/7816/card.rb

Overview

class Card

Instance Attribute Summary

Attributes inherited from Card

#atr

Instance Method Summary collapse

Constructor Details

#initializePCSCCard

Returns a new instance of PCSCCard.



44
45
# File 'lib/7816/card.rb', line 44

def initialize()
end

Instance Method Details

#connectObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/7816/card.rb', line 47

def connect
  begin 
    if @connected
       #puts "!!!!!!!!!!!!!! Already Connected!"
    else
       @card = ISO7816::PCSC::Card.new()  
    end
  rescue
    @card.disconnect if @card
    raise $!
  end
  
  stat = @card.status
  @connected = true
  @atr = @card.atr
  @t0  = stat[:protocol] == Smartcard::PCSC::PROTOCOL_T0
  if block_given?
     yield self
     disconnect
  end  
  @atr
end

#disconnectObject



75
76
77
78
79
# File 'lib/7816/card.rb', line 75

def disconnect 
  @card.disconnect() if @card
  @card = nil
  @connected = false
end

#receive(len = 0) ⇒ Object



85
86
87
88
89
# File 'lib/7816/card.rb', line 85

def receive len=0
  ret = @received
  @received = nil
  return ret
end

#reconnectObject



70
71
72
73
# File 'lib/7816/card.rb', line 70

def reconnect
  #puts "calling reconn! #{ (@card && @connected)}"
  @card.reconnect if (@card && @connected)
end

#send(bytes = "") ⇒ Object



81
82
83
# File 'lib/7816/card.rb', line 81

def send bytes = ""
  @received = @card.transmit(bytes)
end

#t0?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/7816/card.rb', line 91

def t0?
  return @t0
end