Class: Rubolite::SSHKey
- Inherits:
-
Object
- Object
- Rubolite::SSHKey
- Defined in:
- lib/rubolite/ssh_key.rb
Overview
unix.stackexchange.com/questions/23590/ssh-public-key-comment-separator This class represents the structure of SSH public keys as defined in RFC4716
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#key ⇒ Object
Returns the value of attribute key.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, key, comment) ⇒ SSHKey
constructor
A new instance of SSHKey.
- #write_for(username, directory) ⇒ Object
Constructor Details
#initialize(type, key, comment) ⇒ SSHKey
Returns a new instance of SSHKey.
8 9 10 11 12 |
# File 'lib/rubolite/ssh_key.rb', line 8 def initialize(type, key, comment) self.type = type self.key = key self.comment = comment end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
6 7 8 |
# File 'lib/rubolite/ssh_key.rb', line 6 def comment @comment end |
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'lib/rubolite/ssh_key.rb', line 6 def key @key end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/rubolite/ssh_key.rb', line 6 def type @type end |
Class Method Details
.from_file(path) ⇒ Object
14 15 16 17 |
# File 'lib/rubolite/ssh_key.rb', line 14 def self.from_file(path) key_contents = File.read(path) new(*key_parts(key_contents)) end |
.from_string(string) ⇒ Object
19 20 21 |
# File 'lib/rubolite/ssh_key.rb', line 19 def self.from_string(string) new(*key_parts(string)) end |
.key_parts(key_contents) ⇒ Object
23 24 25 |
# File 'lib/rubolite/ssh_key.rb', line 23 def self.key_parts(key_contents) key_contents.split " " end |
Instance Method Details
#write_for(username, directory) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/rubolite/ssh_key.rb', line 27 def write_for(username, directory) File.open("#{directory}/#{username}.pub", "w") do |handle| handle.write public_key_contents handle.close end end |