Ruby SHA2在我的IRB中消化不正确的文档或问题?

时间:2014-11-23 00:19:49

标签: ruby sha

doc @ http://www.ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest/SHA2.html显示:

Digest::SHA256.new.digest_length * 8
 #=> 512
Digest::SHA384.new.digest_length * 8
 #=> 1024
Digest::SHA512.new.digest_length * 8
 #=> 1024

这是2.1.3中的输出:

Digest::SHA256.new.digest_length * 8
 #=> 256 
Digest::SHA384.new.digest_length * 8
 #=> 384 
Digest::SHA512.new.digest_length * 8
 #=> 512

为什么我的块长度输出与Ruby文档不同?

2 个答案:

答案 0 :(得分:0)

似乎文档中有拼写错误,看,

block_length → Integer
Returns the block length of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 512
Digest::SHA384.new.digest_length * 8
# => 1024
Digest::SHA512.new.digest_length * 8
# => 1024

digest_length → Integer
Returns the length of the hash value of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512

两者都在示例中使用digest_length

但它应该是,

block_length → Integer
Returns the block length of the digest in bytes.

Digest::SHA256.new.block_length * 8
# => 512
Digest::SHA384.new.block_length * 8
# => 1024
Digest::SHA512.new.block_length * 8
# => 1024

digest_length → Integer
Returns the length of the hash value of the digest in bytes.

Digest::SHA256.new.digest_length * 8
# => 256
Digest::SHA384.new.digest_length * 8
# => 384
Digest::SHA512.new.digest_length * 8
# => 512

答案 1 :(得分:0)

This has been fixed in the 2.0.0 documentationcommit

方法Digest::SHA2#block_length的Ruby 1.9.3文档中似乎存在错误,因为它们在示例中使用digest_length方法而不是block_length

使用digest_block实际获得显示的值51210241024

Digest::SHA256.new.block_length * 8
# => 512

Digest::SHA384.new.block_length * 8
# => 1024

Digest::SHA512.new.block_length * 8
# => 1024