mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ext/digest/digest.c (hexencode_str_new): return an ASCII string
* test/digest: tests for all kind of digests encodings [ruby-core:46792][Bug #6799] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36588 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f52eefece1
commit
61b624d149
4 changed files with 18 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
Wed Aug 1 22:29:12 2012 Benoit Daloze <eregontp@gmail.com>
|
||||
|
||||
ext/digest/digest.c (hexencode_str_new): return an ASCII string
|
||||
|
||||
* test/digest: tests for all kind of digests encodings
|
||||
[ruby-core:46792][Bug #6799]
|
||||
|
||||
Wed Aug 1 05:50:53 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||
|
||||
* test/ruby/test_rubyoptions.rb (TestRubyOptions#test_encoding):
|
||||
|
|
|
@ -99,7 +99,7 @@ hexencode_str_new(VALUE str_digest)
|
|||
rb_raise(rb_eRuntimeError, "digest string too long");
|
||||
}
|
||||
|
||||
str = rb_str_new(0, digest_len * 2);
|
||||
str = rb_usascii_str_new(0, digest_len * 2);
|
||||
|
||||
for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
|
||||
unsigned char byte = digest[i];
|
||||
|
|
|
@ -25,21 +25,27 @@ module TestDigest
|
|||
|
||||
def test_s_hexdigest
|
||||
self.class::DATA.each do |str, hexdigest|
|
||||
assert_equal(hexdigest, self.class::ALGO.hexdigest(str))
|
||||
actual = self.class::ALGO.hexdigest(str)
|
||||
assert_equal(hexdigest, actual)
|
||||
assert_equal(Encoding::US_ASCII, actual.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
def test_s_base64digest
|
||||
self.class::DATA.each do |str, hexdigest|
|
||||
digest = [hexdigest].pack("H*")
|
||||
assert_equal([digest].pack("m0"), self.class::ALGO.base64digest(str))
|
||||
actual = self.class::ALGO.base64digest(str)
|
||||
assert_equal([digest].pack("m0"), actual)
|
||||
assert_equal(Encoding::US_ASCII, actual.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
def test_s_digest
|
||||
self.class::DATA.each do |str, hexdigest|
|
||||
digest = [hexdigest].pack("H*")
|
||||
assert_equal(digest, self.class::ALGO.digest(str))
|
||||
actual = self.class::ALGO.digest(str)
|
||||
assert_equal(digest, actual)
|
||||
assert_equal(Encoding::BINARY, actual.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class TestDigestExtend < Test::Unit::TestCase
|
|||
(0..0xff).to_a.map { |c| sprintf("%02x", c ) }.join(''),
|
||||
Digest.hexencode((0..0xff).to_a.map { |c| c.chr }.join(''))
|
||||
)
|
||||
assert_equal(Encoding::US_ASCII, Digest.hexencode("\1\2").encoding)
|
||||
end
|
||||
|
||||
def test_class_reset
|
||||
|
|
Loading…
Reference in a new issue