Bug #6799 ยป 0001-ext-digest-digest.c-hexencode_str_new-return-an-ASCI.patch
ext/digest/digest.c | ||
---|---|---|
99 | 99 |
rb_raise(rb_eRuntimeError, "digest string too long"); |
100 | 100 |
} |
101 | 101 | |
102 |
str = rb_str_new(0, digest_len * 2); |
|
102 |
str = rb_usascii_str_new(0, digest_len * 2);
|
|
103 | 103 | |
104 | 104 |
for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) { |
105 | 105 |
unsigned char byte = digest[i]; |
test/digest/test_digest.rb | ||
---|---|---|
25 | 25 | |
26 | 26 |
def test_s_hexdigest |
27 | 27 |
self.class::DATA.each do |str, hexdigest| |
28 |
assert_equal(hexdigest, self.class::ALGO.hexdigest(str)) |
|
28 |
actual = self.class::ALGO.hexdigest(str) |
|
29 |
assert_equal(hexdigest, actual) |
|
30 |
assert_equal(Encoding::US_ASCII, actual.encoding) |
|
29 | 31 |
end |
30 | 32 |
end |
31 | 33 | |
32 | 34 |
def test_s_base64digest |
33 | 35 |
self.class::DATA.each do |str, hexdigest| |
34 | 36 |
digest = [hexdigest].pack("H*") |
35 |
assert_equal([digest].pack("m0"), self.class::ALGO.base64digest(str)) |
|
37 |
actual = self.class::ALGO.base64digest(str) |
|
38 |
assert_equal([digest].pack("m0"), actual) |
|
39 |
assert_equal(Encoding::US_ASCII, actual.encoding) |
|
36 | 40 |
end |
37 | 41 |
end |
38 | 42 | |
39 | 43 |
def test_s_digest |
40 | 44 |
self.class::DATA.each do |str, hexdigest| |
41 | 45 |
digest = [hexdigest].pack("H*") |
42 |
assert_equal(digest, self.class::ALGO.digest(str)) |
|
46 |
actual = self.class::ALGO.digest(str) |
|
47 |
assert_equal(digest, actual) |
|
48 |
assert_equal(Encoding::BINARY, actual.encoding) |
|
43 | 49 |
end |
44 | 50 |
end |
45 | 51 |
test/digest/test_digest_extend.rb | ||
---|---|---|
49 | 49 |
(0..0xff).to_a.map { |c| sprintf("%02x", c ) }.join(''), |
50 | 50 |
Digest.hexencode((0..0xff).to_a.map { |c| c.chr }.join('')) |
51 | 51 |
) |
52 |
assert_equal(Encoding::US_ASCII, Digest.hexencode("\1\2").encoding) |
|
52 | 53 |
end |
53 | 54 | |
54 | 55 |
def test_class_reset |
55 |
- |