Permalink
Browse files

Support leading 0s

  • Loading branch information...
1 parent 80fa278 commit 8453ab515d27ff835fa6f7e89c9dfd191024e8a1 @singpolyma committed Jul 23, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/openpgp/util.rb
View
@@ -64,6 +64,9 @@ def self.crc24(data)
# @return [Integer]
# @see http://tools.ietf.org/html/rfc4880#section-3.2
def self.bitlength(data)
- data.empty? ? 0 : (data.size - 1) * 8 + (Math.log(data[0].ord) / Math.log(2)).floor + 1
+ data = data.split(//)
+ while (f = data.shift) == '\0'; end
+ return 0 unless f
+ Math.log(f.ord, 2).floor + 1 + (data.length*8)
end
end

0 comments on commit 8453ab5

Please sign in to comment.