Class: GitHandler::PublicKey

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#contentObject (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

#md5Object



29
30
31
# File 'lib/git_handler/public_key.rb', line 29

def md5
  Digest::MD5.hexdigest(@content)
end

#sha1Object



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/git_handler/public_key.rb', line 25

def valid?
  SSHKey.valid_ssh_public_key?(@content)
end