Class: Orthrus::SSH::KeyManager

Inherits:
Object
  • Object
show all
Defined in:
lib/orthrus/ssh/key_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(try_agent = true) ⇒ KeyManager

Returns a new instance of KeyManager.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/orthrus/ssh/key_manager.rb', line 6

def initialize(try_agent=true)
  @keys = []

  agent = nil
  if try_agent and Agent.available?
    begin
      agent = Agent.connect
    rescue IOError
      # ignore
    end
  end

  @agent = agent
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



21
22
23
# File 'lib/orthrus/ssh/key_manager.rb', line 21

def keys
  @keys
end

Instance Method Details

#add_key(key) ⇒ Object



23
24
25
# File 'lib/orthrus/ssh/key_manager.rb', line 23

def add_key(key)
  @keys << key
end

#agent_identitiesObject



31
32
33
# File 'lib/orthrus/ssh/key_manager.rb', line 31

def agent_identities
  @agent && @agent.identities
end

#each_keyObject



35
36
37
38
39
40
41
42
43
# File 'lib/orthrus/ssh/key_manager.rb', line 35

def each_key
  @keys.each { |x| yield x }
  if @agent
    @agent.identities.each do |x|
      x.source = @agent
      yield x
    end
  end
end

#load_key(path) ⇒ Object



27
28
29
# File 'lib/orthrus/ssh/key_manager.rb', line 27

def load_key(path)
  add_key Orthrus::SSH.load_private(path)
end

#sign(key, data, b64armor = false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/orthrus/ssh/key_manager.rb', line 45

def sign(key, data, b64armor=false)
  if key.source.kind_of? Agent
    _, sign = key.source.sign key, data
  else
    sign = key.sign data
  end

  if b64armor
    Utils.encode64 sign
  else
    sign
  end
end