Class: Aussiegeek::SshKey

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh-keys.rb

Defined Under Namespace

Classes: InvalidKey

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ssh_key) ⇒ SshKey

Returns a new instance of SshKey.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ssh-keys.rb', line 8

def initialize(ssh_key)
  if ssh_key.match /\n/
    raise InvalidKey
  end

  if ssh_key.length < 64
    raise InvalidKey
  end
  
  tmpfile = Tempfile.new('ruby_ssh-key' + Time.now.to_i.to_s)
  tmpfile << ssh_key
  tmpfile.close
  output = `ssh-keygen -l -f #{tmpfile.path}`
  status = $?.to_i
  if status > 0
    raise InvalidKey
  end
  @key_length, @fingerprint, @path, @key_type = output.split(' ')
  @key_length = @key_length.to_i
  @key_type = @key_type.match(/[a-zA-Z0-9]+/)[0].downcase
  tmpfile.unlink
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



6
7
8
# File 'lib/ssh-keys.rb', line 6

def comment
  @comment
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



6
7
8
# File 'lib/ssh-keys.rb', line 6

def fingerprint
  @fingerprint
end

#key_lengthObject (readonly)

Returns the value of attribute key_length.



6
7
8
# File 'lib/ssh-keys.rb', line 6

def key_length
  @key_length
end

#key_typeObject (readonly)

Returns the value of attribute key_type.



6
7
8
# File 'lib/ssh-keys.rb', line 6

def key_type
  @key_type
end