Class: GitHandler::PublicKey
- Inherits:
-
Object
- Object
- GitHandler::PublicKey
- Defined in:
- lib/git_handler/public_key.rb
Constant Summary collapse
- COMMAND_OPTIONS =
[ 'no-port-forwarding', 'no-X11-forwarding', 'no-agent-forwarding', 'no-pty' ]
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#initialize(content = nil) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #md5 ⇒ Object
- #sha1 ⇒ Object
- #to_system_key(command) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(content = nil) ⇒ PublicKey
Returns a new instance of PublicKey.
15 16 17 18 19 20 21 22 23 |
# File 'lib/git_handler/public_key.rb', line 15 def initialize(content=nil) @content = cleanup_content(content) if @content.empty? raise ArgumentError, 'Key content is empty!' end unless valid? raise ArgumentError, "Is not a valid public key!" end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
13 14 15 |
# File 'lib/git_handler/public_key.rb', line 13 def content @content end |
Instance Method Details
#md5 ⇒ Object
29 30 31 |
# File 'lib/git_handler/public_key.rb', line 29 def md5 Digest::MD5.hexdigest(@content) end |
#sha1 ⇒ Object
33 34 35 |
# File 'lib/git_handler/public_key.rb', line 33 def sha1 Digest::SHA1.hexdigest(@content) end |
#to_system_key(command) ⇒ Object
37 38 39 |
# File 'lib/git_handler/public_key.rb', line 37 def to_system_key(command) "command=\"#{command}\",#{COMMAND_OPTIONS.join(",")} #{@content}" end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/git_handler/public_key.rb', line 25 def valid? SSHKey.valid_ssh_public_key?(@content) end |