Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/yubikey/hex.rb

Instance Method Summary collapse

Instance Method Details

#hex?Boolean

Check if the string is hex encoded

Returns:

  • (Boolean)


14
15
16
# File 'lib/yubikey/hex.rb', line 14

def hex?
  self =~ /^[0-9a-fA-F]+$/ ? true : false
end

#modhex?Boolean

Check if the string is modhex encoded

Returns:

  • (Boolean)


19
20
21
# File 'lib/yubikey/hex.rb', line 19

def modhex?
  self =~ /^[cbdefghijklnrtuv]+$/ ? true : false
end

#to_binObject

Convert hex string to binary



4
5
6
# File 'lib/yubikey/hex.rb', line 4

def to_bin
  to_a.pack('H*')
end

#to_hexObject

Convert binary string to hex



9
10
11
# File 'lib/yubikey/hex.rb', line 9

def to_hex
  unpack('H*')[0]
end