Module: Orthrus::SSH::Utils

Defined in:
lib/orthrus/ssh/utils.rb

Class Method Summary collapse

Class Method Details

.decode64(data) ⇒ Object



29
30
31
# File 'lib/orthrus/ssh/utils.rb', line 29

def self.decode64(data)
  data.unpack("m").first
end

.encode64(data) ⇒ Object



25
26
27
# File 'lib/orthrus/ssh/utils.rb', line 25

def self.encode64(data)
  [data].pack("m").gsub("\n","")
end

.sha1_hash(data) ⇒ Object



21
22
23
# File 'lib/orthrus/ssh/utils.rb', line 21

def self.sha1_hash(data)
  OpenSSL::Digest::SHA1.hexdigest data
end

.write_bignum(bn) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/orthrus/ssh/utils.rb', line 3

def self.write_bignum(bn)
  # Cribbed from net-ssh
  if bn.zero?
    return [0].pack("N")
  else
    buf = bn.to_s(2)
    if buf.getbyte(0)[7] == 1
      return [buf.length+1, 0, buf].pack("NCA*")
    else
      return [buf.length, buf].pack("NA*")
    end
  end
end

.write_string(str) ⇒ Object



17
18
19
# File 'lib/orthrus/ssh/utils.rb', line 17

def self.write_string(str)
  [str.size].pack("N") + str
end