Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/yubikey/hex.rb
Instance Method Summary collapse
-
#hex? ⇒ Boolean
Check if the string is hex encoded.
-
#modhex? ⇒ Boolean
Check if the string is modhex encoded.
-
#to_bin ⇒ Object
Convert hex string to binary.
-
#to_hex ⇒ Object
Convert binary string to hex.
Instance Method Details
#hex? ⇒ Boolean
Check if the string is hex encoded
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
19 20 21 |
# File 'lib/yubikey/hex.rb', line 19 def modhex? self =~ /^[cbdefghijklnrtuv]+$/ ? true : false end |
#to_bin ⇒ Object
Convert hex string to binary
4 5 6 |
# File 'lib/yubikey/hex.rb', line 4 def to_bin to_a.pack('H*') end |
#to_hex ⇒ Object
Convert binary string to hex
9 10 11 |
# File 'lib/yubikey/hex.rb', line 9 def to_hex unpack('H*')[0] end |