Module: Net::BER::Extensions::Bignum

Included in:
Bignum
Defined in:
lib/net/ber/core_ext/bignum.rb

Overview

BER extensions to the Bignum class.

Instance Method Summary collapse

Instance Method Details

#to_berObject

Converts a Bignum to an uncompressed BER integer.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/net/ber/core_ext/bignum.rb', line 7

def to_ber
  result = []

  # NOTE: Array#pack's 'w' is a BER _compressed_ integer. We need
  # uncompressed BER integers, so we're not using that. See also:
  # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/228864
  n = self
  while n > 0
    b = n & 0xff
    result << b
    n = n >> 8
  end

  "\002" + ([result.size] + result.reverse).pack('C*')
end