Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14 from dgrijalva/master

Fix for encoding of negative bignums
  • Loading branch information...
commit 813372b2b61995ebcc129f7ae055364249d71fcb 2 parents 727ee16 + c9a6811
Aman Gupta tmm1 authored
Showing with 4 additions and 1 deletion.
  1. +1 −1  lib/bert/encode.rb
  2. +3 −0  test/encoder_test.rb
2  lib/bert/encode.rb
View
@@ -78,7 +78,7 @@ def write_float(float)
end
def write_bignum(num)
- n = (num.to_s(2).size / 8.0).ceil
+ n = (num.abs.to_s(2).size / 8.0).ceil
if n < 256
write_1 SMALL_BIGNUM
write_1 n
3  test/encoder_test.rb
View
@@ -82,6 +82,9 @@ class EncoderTest < Test::Unit::TestCase
should "handle bignums" do
bert = [131,110,8,0,0,0,232,137,4,35,199,138].pack('c*')
assert_equal bert, BERT::Encoder.encode(10_000_000_000_000_000_000)
+
+ bert = [131,110,8,1,0,0,232,137,4,35,199,138].pack('c*')
+ assert_equal bert, BERT::Encoder.encode(-10_000_000_000_000_000_000)
end
should "leave other stuff alone" do
Please sign in to comment.
Something went wrong with that request. Please try again.