module SecurizeString::BinaryStringDataMethods::InstanceMethods
Adds basic binary data instance methods via an include of SecurizeString::BinaryStringDataMethods
.
Public Instance Methods
data_to_escaped_hex()
click to toggle source
Returns an escaped hex string representation of the data.
This hex string is compatible with Ruby and Javascript.
# File lib/securize_string/binary_string_data_methods.rb, line 62 def data_to_escaped_hex # First we convert the string into a packed hex string. hex_string = self.unpack('H*')[0] # Now we grab two elements at a time, prefix it, and add it to the buffer. ptr = 0 len = self.bytesize outbuf = "" while(ptr<(len*2)) outbuf << '\x' + hex_string[ptr,2] ptr+=2 end # Now we return the buffer return outbuf end
data_to_hex()
click to toggle source
Returns the hexidecimal string representation of the data.
# File lib/securize_string/binary_string_data_methods.rb, line 48 def data_to_hex return (self.to_s.empty? ? '' : self.to_s.unpack('H*')[0]) end
data_to_i()
click to toggle source
Returns the data converted from hexidecimal into an integer. This is usually as a BigInt.
# File lib/securize_string/binary_string_data_methods.rb, line 55 def data_to_i return (self.to_s.empty? ? 0 : self.data_to_hex.hex) end