Class: CTAPI::Card
- Inherits:
-
Object
- Object
- CTAPI::Card
- Defined in:
- lib/ctapi.rb
Instance Attribute Summary collapse
-
#atr ⇒ Object
The answer to reset (ATR) of the inserted chipcard.
Instance Method Summary collapse
-
#atr_ok? ⇒ Boolean
Check if the ATR is correct.
-
#initialize(atr) ⇒ Card
constructor
A new instance of Card.
-
#inspect ⇒ Object
Returns adescription of this card including the ATR as a string.
-
#memory_bits ⇒ Object
The bit width of this chipcard.
-
#memory_blocks ⇒ Object
Number of memory blocks on this chipcard.
-
#memory_size ⇒ Object
Computes the memory size of the inserted chipcard in bytes.
-
#protocol ⇒ Object
Supported protocol of this chipcard.
-
#structure ⇒ Object
The structure of this chipcard.
-
#to_s ⇒ Object
Returns a short description of this card as a string.
Constructor Details
#initialize(atr) ⇒ Card
Returns a new instance of Card.
455 456 457 |
# File 'lib/ctapi.rb', line 455 def initialize(atr) @atr = atr end |
Instance Attribute Details
#atr ⇒ Object
The answer to reset (ATR) of the inserted chipcard.
460 461 462 |
# File 'lib/ctapi.rb', line 460 def atr @atr end |
Instance Method Details
#atr_ok? ⇒ Boolean
Check if the ATR is correct. If false, the data of this Card object could be wrong and the calculations based on this data wrong.
464 465 466 |
# File 'lib/ctapi.rb', line 464 def atr_ok? @atr[4, 2] == "\x90\x00" && @atr[2] == 0x10 end |
#inspect ⇒ Object
Returns adescription of this card including the ATR as a string.
518 519 520 521 522 |
# File 'lib/ctapi.rb', line 518 def inspect string = to_s string[-1] = " #{atr}>" string end |
#memory_bits ⇒ Object
The bit width of this chipcard.
469 470 471 |
# File 'lib/ctapi.rb', line 469 def memory_bits 1 << (@atr[1] & 0x07) end |
#memory_blocks ⇒ Object
Number of memory blocks on this chipcard.
474 475 476 |
# File 'lib/ctapi.rb', line 474 def memory_blocks 1 << (((@atr[1] & 0x78) >> 3) + 6) end |
#memory_size ⇒ Object
Computes the memory size of the inserted chipcard in bytes.
479 480 481 |
# File 'lib/ctapi.rb', line 479 def memory_size (memory_blocks * memory_bits >> 3) end |
#protocol ⇒ Object
Supported protocol of this chipcard.
497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/ctapi.rb', line 497 def protocol if (@atr[0] & 0x80) == 0x00 'ISO' elsif (@atr[0] & 0xf0) == 0x80 'I2C' elsif (@atr[0] & 0xf0) == 0x90 '3W' elsif (@atr[0] & 0xf0) == 0xa0 '2W' else 'unknown' end end |
#structure ⇒ Object
The structure of this chipcard.
484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/ctapi.rb', line 484 def structure if (@atr[0] & 0x3) == 0 'ISO' elsif (@atr[0] & 0x7) == 2 'common use' elsif (@atr[0] & 0x7) == 6 'proprietary use' else 'special use' end end |
#to_s ⇒ Object
Returns a short description of this card as a string.
512 513 514 515 |
# File 'lib/ctapi.rb', line 512 def to_s "<#{self.class}:Structure #{structure} Protocol #{protocol} " + "(#{memory_blocks}x#{memory_bits}=#{memory_size}B)" + '>' end |