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 ⇒ String
Get public key MD5 checksum.
-
#sha1 ⇒ String
Get public key SHA1 checksum.
-
#to_system_key(command) ⇒ String
Convert public key to system key with arbitrary command.
-
#valid? ⇒ Boolean
Check if public key contents is valid.
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 ⇒ String
Get public key MD5 checksum
33 34 35 |
# File 'lib/git_handler/public_key.rb', line 33 def md5 Digest::MD5.hexdigest(@content) end |
#sha1 ⇒ String
Get public key SHA1 checksum
39 40 41 |
# File 'lib/git_handler/public_key.rb', line 39 def sha1 Digest::SHA1.hexdigest(@content) end |
#to_system_key(command) ⇒ String
Convert public key to system key with arbitrary command
46 47 48 |
# File 'lib/git_handler/public_key.rb', line 46 def to_system_key(command) "command=\"#{command}\",#{COMMAND_OPTIONS.join(",")} #{@content}" end |
#valid? ⇒ Boolean
Check if public key contents is valid
27 28 29 |
# File 'lib/git_handler/public_key.rb', line 27 def valid? SSHKey.valid_ssh_public_key?(@content) end |