Skip to content

Commit

Permalink
Hex: Changed pack and unpack to use 'H*'. This resulted in more consi…
Browse files Browse the repository at this point in the history
…stent fast speeds in tests.
  • Loading branch information
paploo committed Jul 19, 2011
1 parent 0b85bba commit beb175b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -236,6 +236,7 @@ mailto:jeff@paploo.net
= Version History
[1.3.3 - 2011-Jul-19] Added new functionality
* (FEATURE) Added PKCS5 v2 keygen from a passphrase support.
* (FIX) Hex conversion is more consistently faster now."
[1.3.2 - 2011-Jun-15] Changed minimum requirements from 1.8.6 to 1.8.7.
* (CHANGE) Minimum requirements are 1.8.7 due to too many bugs in 1.8.6.
* (FIX) Update to the documentation to reflect 1.8.7 support.
Expand Down Expand Up @@ -282,7 +283,6 @@ mailto:jeff@paploo.net
* See what happens when including SecurizeString into an object that is not a String.
What are the expected root methods? +to_s+, <tt>self.new(string)</tt> are two
that I know of.
* See if unpack('H*') is faster than calculating the string length for hex unpack.
* Create a method that returns a "\x48\x69" style string, and one that can
parse it back into a string.

Expand Down
4 changes: 2 additions & 2 deletions lib/securize_string/binary_string_data_methods.rb
Expand Up @@ -25,7 +25,7 @@ def parse_data(value, opts={})
case data_type_hint
when :hex
hex_string = value.to_s.delete('^0-9a-fA-F')
data_string = [hex_string].pack('H' + hex_string.bytesize.to_s)
data_string = [hex_string].pack('H*')
when :data
data_string = value.to_s
when :int
Expand All @@ -46,7 +46,7 @@ module InstanceMethods

# Returns the hexidecimal string representation of the data.
def data_to_hex
return (self.to_s.empty? ? '' : self.to_s.unpack('H' + (self.to_s.bytesize*2).to_s)[0])
return (self.to_s.empty? ? '' : self.to_s.unpack('H*')[0])
end

# Returns the data converted from hexidecimal into an integer.
Expand Down

0 comments on commit beb175b

Please sign in to comment.