Issue #7050 has been updated by Eregon (Benoit Daloze).


I would of course also add Aaron's test for SecureRandom hexdigests if this is fine to be merged.
----------------------------------------
Bug #7050: encoding of String#unpack for 'H', 'h', 'B' and 'b'
https://bugs.ruby-lang.org/issues/7050#change-29678

Author: Eregon (Benoit Daloze)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-07-15 trunk 36395) [x86_64-darwin10.8.0]


Originally mentioned in #6799, I think the encoding of the resulting Strings for the 'H', 'h', 'B' and 'b' directives of String#unpack should be encoded in US-ASCII, because they  will always contain 0-9a-f (0-1 for 'B','b') chars.

This is already done for the 'm', 'M' and 'u' directives in Array#pack.

It would also fix SecureRandom hexdigests as mentioned in #6799.

P.S.: Does anyone know the rationale behind which method to use for 'u','m','M' and 'H','h','B','b' ?
To have a base64 representation you need [s].pack('m') (and so #pack is used for 'u','m','M' to obtain the specified format), but for 'H','h','B','b' you need s.unpack(directive). I think the latter makes more sense when compared to other types such as 'l', in which #unpack is used to obtain the desired format.


-- 
http://bugs.ruby-lang.org/