mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[rubygems/rubygems] Fix Bundler::Digest#sha1 on big-endian systems
As noticed by @nobu https://github.com/rubygems/rubygems/pull/4989#discussion_r735674633
From wikipedia: https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode
> append ml, the original message length in bits, as a 64-bit big-endian integer.
`Q` is native endian, so little-endian on most modern hardware.
The original code from RubyDigest reverses the bytes:
d15f906caf/lib/ruby_digest.rb (L521)
But that makes the code non-portable, the correct way is to directly ask
for a big-endian representation.
https://github.com/rubygems/rubygems/commit/ba2be01ea4
This commit is contained in:
parent
244c98e635
commit
557fa38915
1 changed files with 1 additions and 1 deletions
|
@ -59,7 +59,7 @@ module Bundler
|
||||||
size = string.bytesize * 8
|
size = string.bytesize * 8
|
||||||
buffer = string.bytes << 128
|
buffer = string.bytes << 128
|
||||||
buffer << 0 while buffer.size % 64 != 56
|
buffer << 0 while buffer.size % 64 != 56
|
||||||
[size].pack("Q").bytes.reverse_each {|b| buffer << b }
|
buffer.concat([size].pack("Q>").bytes)
|
||||||
buffer.each_slice(64, &block)
|
buffer.each_slice(64, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue