lib/net/ber/ber_parser.rb in net-ldap-0.10.0 vs lib/net/ber/ber_parser.rb in net-ldap-0.10.1
- old
+ new
@@ -39,12 +39,21 @@
if object_type == :string
s = Net::BER::BerIdentifiedString.new(data || "")
s.ber_identifier = id
s
elsif object_type == :integer
- j = 0
- data.each_byte { |b| j = (j << 8) + b }
- j
+ neg = !(data.unpack("C").first & 0x80).zero?
+ int = 0
+
+ data.each_byte do |b|
+ int = (int << 8) + (neg ? 255 - b : b)
+ end
+
+ if neg
+ (int + 1) * -1
+ else
+ int
+ end
elsif object_type == :oid
# See X.690 pgh 8.19 for an explanation of this algorithm.
# This is potentially not good enough. We may need a
# BerIdentifiedOid as a subclass of BerIdentifiedArray, to
# get the ber identifier and also a to_s method that produces