Class: Gpsoauth::Utils
- Inherits:
-
Object
- Object
- Gpsoauth::Utils
- Defined in:
- lib/gpsoauth/utilities.rb
Class Method Summary collapse
Class Method Details
.bytesToLong(s) ⇒ Object
4 5 6 |
# File 'lib/gpsoauth/utilities.rb', line 4 def bytesToLong(s) return s.bytes.inject {|a, b| (a << 8) + b } end |
.divmod(bn, v) ⇒ Object
8 9 10 11 |
# File 'lib/gpsoauth/utilities.rb', line 8 def divmod(bn, v) bn = bn.to_s.to_i if bn.is_a?(OpenSSL::BN) return bn.divmod(v) end |
.serialize_number(n, min_size = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gpsoauth/utilities.rb', line 13 def serialize_number(n, min_size=nil) res = [] n, mod = divmod(n, 256) while mod > 0 || n > 0 res << mod n, mod = divmod(n, 256) end res = res.reverse if min_size if res.size < min_size res = Array.new(min_size - res.size, 0) + res end end return res end |