Class: HrrRbSsh::Authentication::Method::KeyboardInteractive::InfoRequest

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb

Instance Attribute Summary

Attributes included from Loggable

#log_key, #logger

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn

Constructor Details

#initialize(name, instruction, language_tag, prompts, logger: nil) ⇒ InfoRequest

Returns a new instance of InfoRequest.



14
15
16
17
18
19
20
# File 'lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb', line 14

def initialize name, instruction, language_tag, prompts, logger: nil
  self.logger = logger
  @name         = name
  @instruction  = instruction
  @language_tag = language_tag
  @prompts      = prompts
end

Instance Method Details

#to_messageObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb', line 22

def to_message
  message = {
    :'message number' => Message::SSH_MSG_USERAUTH_INFO_REQUEST::VALUE,
    :'name'           => @name,
    :'instruction'    => @instruction,
    :'language tag'   => @language_tag,
    :'num-prompts'    => @prompts.size,
  }
  message_prompts = @prompts.map.with_index{ |(prompt, echo), i|
    [
      [:"prompt[#{i+1}]", prompt],
      [:"echo[#{i+1}]",   echo],
    ].inject(Hash.new){ |h, (k, v)| h.update({k => v}) }
  }.inject(Hash.new){ |a, b| a.merge(b) }
  message.merge(message_prompts)
end

#to_payloadObject



39
40
41
# File 'lib/hrr_rb_ssh/authentication/method/keyboard_interactive/info_request.rb', line 39

def to_payload
  Message::SSH_MSG_USERAUTH_INFO_REQUEST.new(logger: logger).encode self.to_message
end