Class: HSMR::Key
Constant Summary
Constants included from HSMR
DOUBLE, SINGLE, TRIPLE, VERSION
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
-
#initialize(init = nil, length = DOUBLE) ⇒ Key
constructor
A new instance of Key.
Methods included from HSMR
cvv, decimalise, decrypt_pin, encrypt, encrypt_pin, #generate, ibm3624, #kcv, numeric?, #odd_parity?, #parity, pvv, #set_odd_parity, to_binary, to_hex, #to_s, #xor, xor, #xor!
Constructor Details
#initialize(init = nil, length = DOUBLE) ⇒ Key
Returns a new instance of Key.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hsmr/key.rb', line 8 def initialize(init=nil, length=DOUBLE) return nil if (init.is_a? Array ) && (init.length == 0) init = init.first if (init.is_a? Array) && (init.length == 1) if init.is_a? Array init.collect! {|c| ( (c.is_a? HSMR::Component) ? c : HSMR::Component.new(c) ) } raise TypeError, "Component argument expected" unless init.first.is_a? Component @key=HSMR::xor(init.pop, init).key elsif init.is_a? Component @key = init.component elsif init.is_a? String key=init.gsub(/ /,'') @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2)) elsif key.nil? key = generate(length) @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2)) end @length = @key.length end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/hsmr/key.rb', line 5 def key @key end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/hsmr/key.rb', line 6 def length @length end |