Project

General

Profile

Bug #6799 » 0001-ext-digest-digest.c-hexencode_str_new-return-an-ASCI.patch

Eregon (Benoit Daloze), 07/27/2012 09:01 PM

View differences:

ext/digest/digest.c
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];
test/digest/test_digest.rb
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
test/digest/test_digest_extend.rb
(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
(1-1/4)