Skip to content

Commit 157d720

Browse files
moved #to_bn call after comparison
this allows (when value is an integer) the runtime and JIT to optimize the call, instead of relying on C-extension openssl
1 parent 1d2a2df commit 157d720

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/openssl/asn1.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,12 @@ def put_length(length)
418418
def put_integer(value)
419419
raise TypeError, "Can't convert nil into OpenSSL::BN" if value.nil?
420420

421-
value = value.to_bn
422421
if value >= 0
423-
data = value.to_s(2)
422+
data = value.to_bn.to_s(2)
424423
data.prepend("\x00".b) if data.empty? || data.getbyte(0) >= 0x80
425424
else
426-
value = (1.to_bn << (value.num_bits + 7) / 8 * 8) + value
425+
value = value.to_bn
426+
value += (1 << (value.num_bits + 7) / 8 * 8)
427427
data = value.to_s(2)
428428
data.prepend("\xff".b) if data.empty? || data.getbyte(0) < 0x80
429429
end

0 commit comments

Comments
 (0)