Class: Aussiegeek::SshKey
- Inherits:
-
Object
- Object
- Aussiegeek::SshKey
- Defined in:
- lib/ssh-keys.rb
Defined Under Namespace
Classes: InvalidKey
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#key_length ⇒ Object
readonly
Returns the value of attribute key_length.
-
#key_type ⇒ Object
readonly
Returns the value of attribute key_type.
Instance Method Summary collapse
-
#initialize(ssh_key) ⇒ SshKey
constructor
A new instance of SshKey.
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
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
6 7 8 |
# File 'lib/ssh-keys.rb', line 6 def comment @comment end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
6 7 8 |
# File 'lib/ssh-keys.rb', line 6 def fingerprint @fingerprint end |
#key_length ⇒ Object (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_type ⇒ Object (readonly)
Returns the value of attribute key_type.
6 7 8 |
# File 'lib/ssh-keys.rb', line 6 def key_type @key_type end |