2011-03-18 02:51:52 +01:00
|
|
|
# -*- ruby encoding: utf-8 -*-
|
2010-04-19 07:52:57 +02:00
|
|
|
##
|
|
|
|
# BER extensions to the Bignum class.
|
2010-03-20 05:18:10 +01:00
|
|
|
module Net::BER::Extensions::Bignum
|
|
|
|
##
|
|
|
|
# Converts a Bignum to an uncompressed BER integer.
|
|
|
|
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
|
|
|
|
end
|