https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-07-27T10:21:34ZRuby Issue Tracking SystemRuby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=284652012-07-27T10:21:34Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>So what should it return? [If you create a bug, saying what the expected behavior is (and also why you expect it) is quite important.]</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=284662012-07-27T11:08:30Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=284822012-07-27T19:34:29ZEregon (Benoit Daloze)
<ul></ul><p>duerst (Martin Dürst) wrote:</p>
<blockquote>
<p>So what should it return? [If you create a bug, saying what the expected behavior is (and also why you expect it) is quite important.]</p>
</blockquote>
<p>I thought it was clear enough, but indeed I should have mentioned it.<br>
An hexadecimal String like this should have the US-ASCII encoding, because, by definition, it only has ASCII characters ([a-f0-9]).</p>
<p>This for example, makes YAML dump it as a binary String, and may cause other problems as the String is believed to be "binary", while it's not (#digest on the other hand has the ASCII-8BIT encoding, which is right).</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=284852012-07-27T21:01:10ZEregon (Benoit Daloze)
<ul><li><strong>File</strong> <a href="/attachments/2942">0001-ext-digest-digest.c-hexencode_str_new-return-an-ASCI.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2942/0001-ext-digest-digest.c-hexencode_str_new-return-an-ASCI.patch">0001-ext-digest-digest.c-hexencode_str_new-return-an-ASCI.patch</a> added</li></ul><p>Patch attached.</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=285222012-07-29T10:53:18ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/2949">noname</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2949/noname">noname</a> added</li></ul><p>On Fri, Jul 27, 2012 at 07:34:30PM +0900, Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Digest::*.hexdigest returns an ASCII-8BIT String (Closed)" href="https://bugs.ruby-lang.org/issues/6799">#6799</a> has been updated by Eregon (Benoit Daloze).</p>
<p>duerst (Martin Dürst) wrote:</p>
<blockquote>
<p>So what should it return? [If you create a bug, saying what the expected behavior is (and also why you expect it) is quite important.]</p>
</blockquote>
<p>I thought it was clear enough, but indeed I should have mentioned it.<br>
An hexadecimal String like this should have the US-ASCII encoding, because, by definition, it only has ASCII characters ([a-f0-9]).</p>
</blockquote>
<p>FWIW, I would like this feature too. In Rails, we have to work around<br>
this issue in some database drivers because the ASCII-8BIT string will<br>
be considered to be binary.</p>
<p>--<br>
Aaron Patterson<br>
<a href="http://tenderlovemaking.com/" class="external">http://tenderlovemaking.com/</a></p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=285472012-07-30T15:06:56Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>Eregon (Benoit Daloze)</i></li></ul><p>Given that the string has only ASCII characters, an encoding of US-ASCII indeed seems best. Benoit, unless somebody objects soon, I think you should go ahead with your patch.</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=285792012-08-01T22:30:57ZEregon (Benoit Daloze)
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r36588.<br>
Benoit, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>ext/digest/digest.c (hexencode_str_new): return an ASCII string</p>
<ul>
<li>test/digest: tests for all kind of digests encodings<br>
<a href="/issues/6799">[ruby-core:46792]</a>[Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Digest::*.hexdigest returns an ASCII-8BIT String (Closed)" href="https://bugs.ruby-lang.org/issues/6799">#6799</a>]</li>
</ul> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=285802012-08-01T22:44:33ZEregon (Benoit Daloze)
<ul></ul><p>duerst (Martin Dürst) wrote:</p>
<blockquote>
<p>Given that the string has only ASCII characters, an encoding of US-ASCII indeed seems best. Benoit, unless somebody objects soon, I think you should go ahead with your patch.</p>
</blockquote>
<p>Thank you, I just did.</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=291982012-09-06T08:58:44Ztenderlovemaking (Aaron Patterson)tenderlove@ruby-lang.org
<ul><li><strong>File</strong> <a href="/attachments/3043">secure_random.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3043/secure_random.patch">secure_random.patch</a> added</li></ul><p>Could we do this for SecureRandom.hex as well? I've attached a patch. /cc akr</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=293042012-09-14T19:35:46ZEregon (Benoit Daloze)
<ul></ul><p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/50261">@Aaron (Aaron Kelly)</a>: Maybe String#unpack should be fixed instead to return an ASCII string for the 'H', 'h', 'B' and 'b' directives?<br>
It makes sense to me since these will always contain 0-9a-f (0-1 for 'B','b') chars.<br>
This is already done for the 'm', 'M' and 'u' directives in Array#pack.<br>
What do you think?</p>
<p>P.S.: Does anyone know the rationale behind which method to use for 'u','m','M' and 'H','h','B','b' ?<br>
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.</p> Ruby master - Bug #6799: Digest::*.hexdigest returns an ASCII-8BIT Stringhttps://bugs.ruby-lang.org/issues/6799?journal_id=293212012-09-15T15:53:16ZAnonymous
<ul><li><strong>File</strong> <a href="/attachments/3051">noname</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3051/noname">noname</a> added</li></ul><p>On Fri, Sep 14, 2012 at 07:35:46PM +0900, Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Digest::*.hexdigest returns an ASCII-8BIT String (Closed)" href="https://bugs.ruby-lang.org/issues/6799">#6799</a> has been updated by Eregon (Benoit Daloze).</p>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/50261">@Aaron (Aaron Kelly)</a>: Maybe String#unpack should be fixed instead to return an ASCII string for the 'H', 'h', 'B' and 'b' directives?<br>
It makes sense to me since these will always contain 0-9a-f (0-1 for 'B','b') chars.<br>
This is already done for the 'm', 'M' and 'u' directives in Array#pack.<br>
What do you think?</p>
</blockquote>
<p>I agree (and would prefer that). It just seems like a larger change<br>
than making this method work for me. ;-)</p>
<p>--<br>
Aaron Patterson<br>
<a href="http://tenderlovemaking.com/" class="external">http://tenderlovemaking.com/</a></p>