re-implemented Fixnum#to_ber, which was wrongly implemented.

The new version still doesn't fix representations of negative values.
This commit is contained in:
blackhedd 2006-12-08 15:47:23 +00:00
parent 1d1a1a6f7d
commit 11d8152d1b

View file

@ -361,8 +361,23 @@ class Fixnum
# to_ber
#
def to_ber
i = [self].pack('w')
[2, i.length].pack("CC") + i
# originally used pack("w") which is WRONG.
#i = [self].pack('w')
# PLEASE optimize this code path. It's awfully ugly and probably slow.
# It also doesn't understand negative numbers yet.
raise Net::BER::BerError.new( "range error in fixnum" ) unless self > 0
z = [self].pack("N")
zlen = if self < 0x80
1
elsif self < 0x8000
2
elsif self < 0x800000
3
else
4
end
[2, zlen].pack("CC") + z[0-zlen,zlen]
end
#