Sha256: 1a5d78a003cf5801ec692b29c3c591d3b70a050beaccc1a32acde79641168617

Contents?: true

Size: 390 Bytes

Versions: 5

Compression:

Stored size: 390 Bytes

Contents

class String
  
  # Convert hex string to binary
  def to_bin
    [self].pack('H*')
  end
  
  # Convert binary string to hex
  def to_hex
    unpack('H*')[0]
  end
  
  # Check if the string is hex encoded
  def hex?
    self =~ /^[0-9a-fA-F]+$/ ? true : false
  end
  
  # Check if the string is modhex encoded
  def modhex?
    self =~ /^[cbdefghijklnrtuv]+$/ ? true : false
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yubikey-1.4.1 lib/yubikey/hex.rb
yubikey-1.4.0 lib/yubikey/hex.rb
yubikey-1.3.1 lib/yubikey/hex.rb
yubikey-1.3.0 lib/yubikey/hex.rb
yubikey-1.2.1 lib/yubikey/hex.rb